tool_name) to filter which tool invocations trigger your hook.
PreToolUse
Fires before a tool executes. Use this to block, modify, or add context to tool calls. Stdin data:
Example — Block destructive commands:
hookSpecificOutput.updatedInput to stdout (see Output format). For example, a hook script that routes shell commands through a wrapper:
PostToolUse
Fires after a tool finishes executing. Use this for logging, validation, or triggering follow-up actions. Stdin data:
Example — Log all shell commands:
PermissionRequest
Fires when the agent needs a permission decision. Use this to implement custom approval logic. Stdin data:
Example — Auto-approve git commands:
UserPromptSubmit
Fires when the user submits a message. Use this to add context or trigger workflows. Stdin data:
Example — Inject context on every prompt:
additionalContext inside a hookSpecificOutput object on stdout, tagged with the event name. That text is injected into the agent’s context:
Stop
Fires when the agent decides to stop (finish its turn). Use this to add follow-up instructions or prevent premature stopping. Stdin data:
Example — Remind agent to run tests:
PostCompaction
Fires after context compaction completes successfully. Use this for logging, triggering follow-up actions, or re-injecting context that may have been lost during compaction. Stdin data:
Example — Log compaction events:
SessionStart
Fires when a new session begins. Use this for initialization, logging, or environment setup. Stdin data:
Example — Run setup script:
additionalContext inside a hookSpecificOutput object on stdout:
SessionEnd
Fires when a session ends. Use this for cleanup or final logging. Stdin data:Matching Multiple Events
A single hooks file can define hooks for multiple events:Using the Matcher
Thematcher field is a regex matched against the hook event’s tool_name. It is available for tool-related events: PreToolUse, PostToolUse, and PermissionRequest.
For non-tool events (UserPromptSubmit, Stop, PostCompaction, SessionStart, and SessionEnd), there is no tool_name; use "" or omit the matcher to run the hook for every event of that type.
The matcher is not a permission glob. Patterns like
mcp__github__* are useful in permissions, but hook matchers are regexes. Use mcp__github__.* in a hook matcher.Tool names you can match
Hook matchers run against the same externally-visible tool names that hook scripts receive in stdin astool_name. The exact tool names available can vary by CLI mode, model, and enabled integrations.
The most common public core tool names are:
readeditgrepglobexec
mcp__<server>__<tool>. For example, a github MCP server tool named create_issue appears as mcp__github__create_issue.
For other tools, match the exact tool_name shown in hook stdin. To confirm the complete set available in your current session, add a temporary PostToolUse hook with matcher: "" and log the stdin payload.
