What are hooks?
Hooks are scripts you configure to run automatically at specific points in Claude Code’s execution — before a tool runs, after it completes, when a session starts, and so on. You can use hooks to:- Auto-format files after Claude edits them
- Run tests after code changes
- Log every tool call for auditing
- Block commands that match a pattern
- Send notifications when a session ends
settings.json (global or project-level) under the hooks key.
Hook events
Each hook is tied to an event. Claude Code emits the following events:Configuration format
Hooks are defined per event as an array of matchers. Each matcher optionally filters by tool name, then runs one or more hook actions.The
matcher field is optional. When omitted, the hook runs for every occurrence of that event regardless of which tool triggered it.Hook types
Claude Code supports four hook types:command — run a shell command
command — run a shell command
Executes a shell command. This is the most common hook type.
prompt — evaluate with an LLM
prompt — evaluate with an LLM
Sends a prompt to a model for evaluation. The model’s response can block or modify tool execution.Use
$ARGUMENTS in the prompt to inject the hook’s input JSON. If no model is specified, Claude Code uses a small, fast model.agent — run an agentic verifier
agent — run an agentic verifier
Spawns a small agent to verify the action. Useful for complex validation that needs multiple steps.If no model is specified, Claude Code uses Haiku. Defaults to a 60-second timeout.
http — POST to a URL
http — POST to a URL
POSTs the hook input as JSON to an HTTP endpoint.Environment variable interpolation in header values only works for variables listed in
allowedEnvVars.The /hooks command
Run/hooks in a session to open the interactive hooks configuration UI. From there you can:
- Browse all configured hook events
- Add, edit, or remove hook matchers
- Enable or disable individual hooks