Skip to content

Hooks Configuration ​

Hooks run commands or prompts in response to Claude Code events. Each key is a hook event name (PascalCase), mapping to an array of matchers.

Fields ​

Top-level hooks object (standalone hooks.json):

FieldTypeRequiredDescription
hooksobjectyesEvent-keyed hooks configuration
descriptionstringnoOptional description of the hook configuration

Hook Matcher ​

Each event maps to an array of matcher objects:

FieldTypeRequiredDescription
matcherstringnoPattern to match against (e.g., tool name for PreToolUse)
hooksobject[]yesArray of hook handlers

Hook Handler ​

FieldTypeRequiredDescription
typestringyescommand, http, mcp_tool, prompt, or agent (valid values)
commandstringnoShell command (when type is command)
urlstringnoPOST endpoint URL (when type is http)
headersobjectnoHTTP headers (when type is http)
allowedEnvVarsstring[]noEnv vars allowed in header interpolation (when type is http)
serverstringnoMCP server name (when type is mcp_tool); server must already be connected
toolstringnoTool name on the MCP server (when type is mcp_tool)
inputobjectnoArguments passed to the tool (when type is mcp_tool); supports ${path} substitution
promptstringnoPrompt text. Required when type is prompt or agent — an agent hook is driven by prompt, not by an agent field
timeoutnumbernoTimeout in seconds
statusMessagestringnoStatus message shown during execution
oncebooleannoRun only once per session
modelstringnoModel override for prompt/agent hooks
asyncbooleannoRun hook asynchronously (non-blocking)
ifstringnoConditional hook filter
argsstring[]noDirect executable arguments; bypasses shell interpretation
asyncRewakebooleannoWake Claude after an asynchronous hook
shellstringnoShell form: bash or powershell

Example ​

json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "echo 'Bash tool invoked'",
            "timeout": 5000
          }
        ]
      }
    ],
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "prompt",
            "prompt": "Review the project README before starting work."
          }
        ]
      }
    ]
  }
}