Skip to main content

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
Hooks are configured in your 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:
Executes a shell command. This is the most common hook type.
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.
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.
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

Examples

Format files after edits

Run Prettier on any file Claude writes or edits:

Run tests after code changes

Audit log every tool call

Safety check before shell commands

Notify on session end

Setting disableAllHooks: true in settings.json disables all hooks and status line execution for that settings scope.