Claude Code Hooks Explained: Config Structure, Matchers, and PreToolUse Guards
Claude Code hooks are deterministic shell commands or endpoints that trigger at fixed points in a session, allowing developers to block, allow, or modify tool calls beyond standard permission prompts. Hooks are configured in a settings.json file using three levels of nesting: a hook event, a matcher group, and a hook handler. Matchers filter when a hook fires and support regex testing, while the optional 'if' field narrows execution further using permission-rule syntax. Command hooks report decisions via exit codes or JSON on stdout, and developers must choose one approach per hook. Notably, the PreToolUse event now requires decisions inside a hookSpecificOutput object with a permissionDecision field, replacing the deprecated top-level decision format used by other events.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in