In short.
The Claude Code Hooks Reference is a detailed guide for developers who want Claude Code to run their own commands, HTTP requests, MCP tools or model checks automatically at points in a session such as before a tool runs. Whether a hook can stop an unwanted action depends on the chosen event and failure settings. It explains five handler types, event matching, structured decisions and platform differences. Its most useful material covers cases where checks fail, time out or run too late to prevent an action. Command hooks run with full user permissions, and agent hooks are experimental. Runtime reliability, performance and total operating cost are unassessed.
Researched and written by an AI model and checked by a second AI model. How it works
Covers the complete selected reference at [https://code.claude.com/docs/en/hooks.md], including its inline examples and security, workspace-trust, experimental-feature, failure and platform notices. No licence text appears in the page. Linked pages, repositories, other folders and separately hosted image assets are excluded. No configuration or example was executed; runtime behavior, compatibility, performance, security effectiveness and actual costs remain unassessed.
The overview
Identity
This is Claude Code's Hooks reference at [https://code.claude.com/docs/en/hooks.md]. Hooks are custom actions triggered at particular points in a coding session, such as before a tool runs, after a file edit or when Claude finishes responding.
The page covers configuration, event inputs, output decisions, background execution and troubleshooting across terminal sessions, IDE extensions, the Desktop app and cloud sessions. JavaScript function hooks supplied by plugin mods are documented on separate linked pages.
Assessment
This is useful when implementing or debugging a specific automation requirement. It explains consequential details that a short example can hide: silence does not approve a tool call, exit code 1 often lets work continue, and a check after execution cannot undo the action.
The material assumes comfort with JSON settings, scripts and process output. Beginners can follow its annotated examples, while experienced developers get precise contracts for permission handling, parallel execution and failure recovery. The page describes intended behavior; it provides no independent reliability measurements.
Users
Individual developers can use it for formatting, lint feedback, notifications and loading changing project context. Teams can use its configuration-scope and managed-settings explanations to understand shared automation and administrator restrictions.
Integration developers get HTTP and MCP contracts, input rewriting and deferred tool calls for non-interactive applications. Readers need enough programming knowledge to implement and maintain their chosen handler; the page does not supply a ready-made validator for every policy.
Capabilities
Five handler types are documented: command runs a local executable or shell command; http sends an HTTP POST; mcp_tool calls a configured Model Context Protocol server; prompt requests a single model evaluation; agent starts a verifier with tool access. Supported handler types vary by event.
Depending on the event, hooks can deny a tool call, request confirmation, rewrite arguments, add context, replace the result Claude receives or keep an agent working. Other events support observation and side effects only. The reference also covers file watching, custom worktree creation, model-switch checks and background command hooks.
Using it
Requirements
Using these examples requires Claude Code and access to an applicable settings file or extension configuration. Command handlers also need their executable, script runtime and dependencies. Bash examples that parse JSON use jq; directly launched scripts on macOS and Linux need executable permissions. MCP handlers require a configured server and any necessary authentication completed beforehand.
Compatibility depends on the feature. For example, onFailure requires Claude Code v2.1.295 or later, and matching Monitor shell commands through a Bash matcher requires v2.1.314 or later. On Windows, direct execution needs a real executable; npm-style .cmd and .bat shims require a shell or invocation through their underlying runtime. A single minimum version covering the entire reference is not stated.
Mechanism
Configuration nests an event, a matcher group and one or more handlers. The event identifies when automation runs; the matcher filters occurrences; an optional if rule filters tool names and arguments further. Command handlers receive event JSON through standard input, HTTP handlers receive it as the POST body, and MCP handlers return text interpreted using command-output rules.
For synchronous command hooks, structured output must be one JSON object without surrounding logging. Exit 0 applies valid output; exit 2 blocks events that support blocking. Other failures generally allow the action to continue, with documented exceptions and an onFailure setting for command and HTTP handlers. PreToolUse decisions use hookSpecificOutput.permissionDecision, with precedence deny, defer, ask, then allow.
Simple matcher names and lists use exact matching; patterns containing other characters use unanchored JavaScript regular expressions. Matching handlers run in parallel, with up to 12 prompt or agent handlers running simultaneously. These details affect both coverage and execution time.
Setup
Choose the configuration scope first: .claude/settings.json for a shared project, .claude/settings.local.json for local project settings, or ~/.claude/settings.json for personal settings across projects. Hooks can also come from managed settings, plugins, skills and subagents. Settings-level hook entries merge, so adding a project entry does not remove existing managed hooks.
Add the event, matcher and handler, then supply the referenced implementation and dependencies. For paths using ${CLAUDE_PROJECT_DIR}, the page recommends exec form: put the executable in command and its arguments in args. This avoids shell parsing of substituted paths. The /hooks menu shows configured handlers and their origins; debug logs provide execution details.
Cloud sessions do not read a developer's local ~/.claude/settings.json. Managed restrictions can also block custom hooks, so configuration presence alone does not establish that a handler will run.
Example
One documented example registers a command handler under PreToolUse with matcher Bash, command node, args containing ${CLAUDE_PROJECT_DIR}/.claude/hooks/check-command.js, and onFailure set to block. The reference describes Claude Code blocking the Bash call when the script is missing and Node reports an error.
This illustrates how to prevent a failed check from silently letting the action continue. The example does not include the check-command.js implementation, so developers must supply its validation logic. The described outcome was not executed or independently verified.
Assessment & evidence
Limitations
Command hooks execute with full user permissions and can access, modify or delete files available to that account. In non-interactive and SDK sessions, settings-file hooks can run without an interactive workspace-trust acceptance, including hooks committed in repository settings.
Coverage has explicit gaps. PreToolUse does not intercept default prompt insertion of files referenced with @, or EndConversation calls. Its Bash if filtering is best effort; the page recommends the permission system for hard allow or deny rules. PostToolUse runs after effects have occurred. MessageDisplay changes visible assistant text while preserving the original transcript and model context.
Background hooks cannot block actions, and async: true command hooks have no enforced hook timeout. Their feedback generally waits for another conversation turn, and unfinished async hooks are killed when a non-interactive session tears down. MCP hooks are unavailable at initial SessionStart and Setup. Agent hooks are experimental, and model-based verdict accuracy is not established.
Reasoning
The documented timing suggests using a synchronous pre-execution handler when an operation must wait for a decision, and a background handler for feedback that can arrive later. A formatter or fixed validation script has explicit behavior developers can inspect; prompt hooks provide model judgment over the supplied input, while agent hooks can inspect files before deciding.
The page recommends command hooks for production workflows because agent hooks are experimental. This supports starting with a narrow command implementation where practical. Whether any chosen script or model evaluation correctly enforces a particular requirement remains unassessed.
Alternatives
The reference identifies simpler mechanisms for some goals: CLAUDE.md supplies static project conventions without running a script; permission rules enforce hard tool restrictions; FileChanged watches named files regardless of whether Claude, a shell command or another process changed them. FileChanged cannot prevent the change.
For an introductory walkthrough, the page links Automate actions with hooks at [https://code.claude.com/docs/en/hooks-guide.md]. That guide's contents and competing tools were not assessed.
Evidence
The supporting source is the Claude Code reference page at [https://code.claude.com/docs/en/hooks.md]. It contains configuration examples, event schemas, decision tables, platform notes and failure walkthroughs. These describe intended behavior rather than independently observed results.
This review reflects the page as retrieved on 12 November 2026. No hook, script, endpoint, MCP tool or model evaluation was run. Compatibility, security effectiveness, latency and reliability were not independently assessed.
Access & freshness
Costs
Total operating cost is unknown. The page does not establish Claude Code access pricing, hook-specific charges, model evaluation prices or charges from external HTTP and MCP services. Prompt hooks request model evaluations, and agent hooks can investigate for up to 50 turns, but their actual resource use and billed cost are not measured here.
Some session-resume and model-switch inputs include estimated_cache_write_usd. Those fields estimate conversation cache-writing costs and exclude response costs; the sample amounts are illustrative inputs, not a price quote or a complete cost estimate for using hooks.
Rights
No licence or redistribution grant appears in the page. Rights to redistribute the documentation, illustrations or example code, including commercial reuse, are unknown. The page's availability does not establish those permissions.
Freshness
This review reflects the page as retrieved on 12 November 2026 at 17:18:06 UTC. The page text does not state an overall publication or last-update date.
Numerous features have individual version requirements and historical behavior notes. For example, it describes changed PostToolUse interruption handling beginning with v2.1.319. Such notes make the installed Claude Code version consequential; compatibility with a particular installation and changes after capture remain unknown.
Actions
Start with one concrete goal, choose an event that occurs at the required time, and check its supported handler types and decision fields. Confirm feature-specific version requirements, inspect effective configuration with /hooks and use debug logs to understand matching and execution.
Before depending on a blocking handler, validate its allowed case, denied case, missing executable, invalid output and timeout behavior in a disposable project. Review repository hooks before unattended runs, and account for inherited environment variables and event data sent to external services. Adoption should depend on those local results; none are established here.
