Hook events
Each hook is registered under one of the following events:Configuration
Hooks are defined in your settings JSON file (e.g.~/.claude/settings.json for user-level hooks, or .claude/settings.json for project-level hooks) under the hooks key. The value is a map from event name to an array of matcher configurations.
matcher(optional) — a string pattern matched against the tool name (e.g."Bash","Write")hooks— an array of hook definitions to run when the matcher matches
The if condition
Every hook supports an if field that uses permission rule syntax to filter when the hook runs. The condition is evaluated against the hook input’s tool_name and tool_input fields.
"Bash(git *)"— any Bash call starting withgit"Read(*.ts)"— any Read call on a.tsfile"Write"— any Write call, regardless of path
Hook types
command — shell command
command — shell command
Runs a shell command. The hook input is passed as JSON via stdin.
Exit code behaviour:
0— success, continue normally2(withasyncRewake: true) — the model is woken and given the hook’s stdout as a new message- Any other non-zero — the hook is treated as an error
prompt — LLM evaluation
prompt — LLM evaluation
Sends a prompt to an LLM. Use
$ARGUMENTS in the prompt string to inject the hook input JSON.agent — sub-agent verifier
agent — sub-agent verifier
Spawns a sub-agent to verify or act on the hook event. The agent receives a prompt describing what to check, with
$ARGUMENTS replaced by the hook input JSON.http — HTTP webhook
http — HTTP webhook
POSTs the hook input JSON to a URL. Useful for integrating with external systems or webhooks.
Background execution
By default hooks run synchronously and block the agent until they complete. Useasync to run a hook in the background:
asyncRewake:
2, Claude Code treats the stdout as a new user message and resumes the model. Any other exit code is treated as normal background completion.
Full example
The following settings configuration uses all four hook types across multiple events:Hook scripts receive the full hook input as JSON on stdin. For
PreToolUse and PostToolUse events this includes tool_name, tool_input, session_id, transcript_path, and cwd.