Agent Hooks
Abstract
Agent Hooks is an open specification for structured lifecycle events emitted by AI-powered developer tools, agents, and assistants. It defines a vendor-neutral format for recording what an AI agent did, who initiated it, and why enabling cost transparency, security auditing, policy enforcement, and agent observability across any compliant tool.
1. Motivation
Modern AI coding tools such as Cursor, Windsurf Cascade, Claude Code, Google Gemini CLI, GitHub Copilot, and Codex operate as stateful agents, not stateless APIs. Each tool has independently introduced "hook" event systems that let developers intercept agent actions at key lifecycle points. The capabilities converge, but the naming, schemas, and feature sets diverge:
Cursor:
beforeShellExecution,afterFileEdit,afterAgentResponseClaude Code:
PreToolUse,PostToolUse,SessionStart,PreCompactWindsurf Cascade:
PreRunCommand,PostWriteCode,PreMCPToolUseGemini CLI:
BeforeTool,AfterAgent,PreCompressGitHub Copilot:
preToolUse,postToolUse,sessionStart
As a result:
Users cannot compare cost or execution behavior across tools
Platform vendors lack a shared accountability format
Third-party tooling (cost, security, compliance) requires custom integration per vendor
Token consumption are opaque or delayed
No shared vocabulary exists for "what just happened"
Agent Hooks defines a minimal but extensible event surface for AI-native workflows, providing the common language that is missing.
2. Goals
Interoperability: Any compliant tool can emit and consume hook events in one format.
Granularity: Support events from session lifecycle through individual tool invocations.
Attribution: Every event carries identity (who), action (what), and rationale (why).
Extensibility: Vendors can add custom metadata without breaking compatibility.
Human & Machine Readable: Events are JSON and readable without special tooling.
3. Non-Goals
Standardizing Prompts: Agent Hooks does not define prompt formats or agent logic.
Replacing Internal Telemetry: Vendors may keep their own systems; Agent Hooks is the external contract.
Prescribing Behavior: The spec standardizes signals, not how agents should act.
Transport Protocol: Delivery mechanism (stdout, HTTP, gRPC, queues) is out of scope.
UI Requirements: Agent Hooks does not require any specific interface.
4. Terminology
Term
Definition
Hook Event
A single immutable fact emitted by an AI agent during its lifecycle
Actor
The entity initiating or executing an action (human, AI agent, or system)
Session
A bounded interaction window (IDE open→close, CLI invocation, agent run)
Action
An external operation performed by the agent (shell, file I/O, tool call)
Mode
The agent mode the hook event was in when emitted
Model
The AI model used when a hook event was emitted
Compaction
Summarization or removal of conversation history to fit context limits
Actor Types
Type
Code
Description
Hook Event
user
A single immutable fact emitted by an AI agent during its lifecycle
AI Agent
agent
The AI assistant or coding agent
System
system
Platform infrastructure (e.g., auto-compaction, timeout)
Agent Modes
Mode
Description
agent
Autonomous multi-step execution
plan
Planning or strategy sub-agent
execute
Code-writing execution phase
chat
Conversational interaction
edit
Direct file editing context
5. Architecture Overview
Agent Hooks is a data specification, not a product. It defines how to record hook events. Storage and transport mechanisms are implementation-defined.
Each vendor maps its native events to the Agent Hooks schema. Consumers receive a unified stream regardless of which tool emitted the event.
6. Core Specification
6.1 Event Envelope Schema
Every hook event MUST include the following envelope:
6.1 Event Envelope Schema
6.2 Minimal Valid Event
6.3 Event Naming Convention
Event types use a dot-separated Category.Subcategory format. This avoids the fragmentation where beforeShellExecution (Cursor), PreRunCommand (Windsurf), preToolUse (Copilot), PreToolUse (Claude), and BeforeTool (Gemini) all describe the same concept.
Pattern
Meaning
Session.*
Session lifecycle
Prompt.*
User input events
Agent.*
Agent reasoning, planning, responses
Action.*
Tool/command execution
Model.*
LLM inference calls
Context.*
Context management (compaction)
Retry.*
Retry and loop detection
Policy.*
Safety and policy enforcement
©2026 Asante Babers