What it is
“Hooks” are a control mechanism built into coding-agent platforms, most prominently Anthropic’s Claude Code and its underlying Agent SDK. A hook is a piece of code — a shell command, an HTTP call, or another small program — that a user registers to run automatically at a defined point in an agent’s operating cycle: when a session starts, when the agent is about to use a tool, after a tool finishes, when a subagent completes, and dozens of other such moments. The two hooks most relevant to safety are PreToolUse, which fires after the agent has decided to take an action but before it executes, and PostToolUse, which fires once the action has completed.
What makes hooks powerful is that the callback is not just a notification — it is a decision point. A PreToolUse hook can inspect the planned action (say, a shell command or a file edit) and return an instruction: allow it, deny it, require explicit human confirmation, or even rewrite the action’s parameters before it runs. A PostToolUse hook can audit what happened, inject additional context back into the agent’s reasoning, or flag a result for review. In effect, hooks let a human (or an organization’s security policy, encoded as a script) sit in the loop of an otherwise autonomous agent, at the exact moment that matters, rather than only at the start or end of a task.
Anthropic’s documentation describes hooks’ intended uses plainly: blocking dangerous operations such as destructive shell commands or unauthorized file access, logging tool calls for compliance and audit, sanitizing or redirecting inputs and outputs, and requiring human sign-off for sensitive actions like database writes. They are configured in settings files (.claude/settings.json or user- and organization-level equivalents) or passed directly as callbacks when an application is built on the Agent SDK.
Why it matters for AI governance and narratives
Hooks sit at the center of a live argument about how AI agents should be governed in practice, as opposed to in policy documents. Much of AI governance discourse operates at the level of principles — transparency, accountability, human oversight — while hooks are one of the few concrete, inspectable mechanisms that actually implement “human oversight” inside a running agent. That makes them useful evidence in the broader framing contest the observatory tracks: when an AI vendor or user claims an agent is “supervised” or “safe by design,” hooks are one of the few places that claim can be checked against an artifact rather than a promise.
But hooks also illustrate the gap between governance mechanism and governance guarantee. Industry commentary on agent hooks (reviewed for this backgrounder via Speakeasy’s analysis) notes that hook-based controls are typically designed to “fail open” — if the hook infrastructure itself breaks or is unavailable, the agent proceeds rather than halting. Anthropic’s own documentation confirms a related structural fact: hooks persist for the duration of a session, but do not automatically carry over into a new session. A session that is interrupted and resumed in a fresh environment — for instance, a cloud-hosted agent whose underlying container is replaced — does not necessarily reconstitute its hooks automatically. That is a mundane infrastructure detail with a governance consequence: a safety control that depends on session continuity can silently stop applying without any error being raised, and the agent will keep working as if nothing changed.
Key facts and dates
Anthropic’s Claude Code documentation enumerates roughly 40 distinct lifecycle events at which hooks can fire, including PreToolUse, PostToolUse, SessionStart, SessionEnd, SubagentStart/SubagentStop, and PreCompact. Hooks can be configured at several layers of precedence — user-level (~/.claude/settings.json), project-level (.claude/settings.json, shareable via version control), local project overrides, and organization-wide managed policy settings that individual users cannot override. The Agent SDK (used by developers building their own applications on top of Claude’s agent capabilities) exposes the same core events as typed callback functions in Python and TypeScript, with PreToolUse and PostToolUse supported in both languages and a larger set of session- and workflow-level events available in TypeScript.
Industry writing on the topic (Speakeasy; Endor Labs) frames hooks as an emerging de facto standard for agent governance tooling — used for policy enforcement, audit logging, and compliance visibility across fleets of coding agents — while also noting that coverage is often inconsistent across different agent platforms and that organizations must build custom infrastructure to aggregate hook-generated audit data.
Where to learn more
- Claude Code Hooks reference — Anthropic’s primary documentation of hook events, configuration, and JSON input/output formats
- Claude Agent SDK: Intercept and control agent behavior with hooks — primary documentation for developers building agents on the SDK
- Speakeasy: AI Agent Hooks — the interface for governing AI agents — industry analysis of hooks as a governance primitive
- Endor Labs: Introducing AI Coding Agent Governance — vendor analysis connecting hooks to software-development-lifecycle governance