Overview
Hooks allow you to intercept and control Claude’s behavior at key lifecycle events like tool usage, prompt submission, and task execution.HookEvent
Supported hook event types.Fires before a tool is executed. Can approve, deny, or modify tool input.
Fires after successful tool execution. Can add context or modify output.
Fires when tool execution fails. Can add error context.
Fires when user submits a prompt. Can add context to the prompt.
Fires when the main session stops.
Fires when a sub-agent (Task tool) completes.
Fires before conversation compaction.
Fires for system notifications.
Fires when a sub-agent starts.
Fires when permission is requested for a tool.
HookCallback
Function signature for hook callbacks.input: HookInput- Strongly-typed input data for the eventtool_use_id: str | None- Optional tool use identifiercontext: HookContext- Hook context (currently contains signal placeholder)
HookJSONOutput dictionary.
Example
HookMatcher
Configuration for matching and handling hook events.Pattern to match against. For
PreToolUse, this can be a tool name like "Bash" or a regex pattern like "Write|Edit|MultiEdit".See hook matcher documentation for details.List of callback functions to execute for this matcher.
Timeout in seconds for all hooks in this matcher (default: 60).
Example
HookInput Types
Strongly-typed input for each hook event. All hook inputs extendBaseHookInput.
BaseHookInput
PreToolUseHookInput
PostToolUseHookInput
PostToolUseFailureHookInput
UserPromptSubmitHookInput
StopHookInput
SubagentStopHookInput
PreCompactHookInput
NotificationHookInput
SubagentStartHookInput
PermissionRequestHookInput
HookJSONOutput Types
Output types for hook callbacks. Can be synchronous or asynchronous.SyncHookJSONOutput
Whether Claude should proceed after hook execution. Note: Use
continue_ in Python (converted to continue for CLI).Hide stdout from transcript mode.
Message shown when
continue_ is False.Set to
"block" to indicate blocking behavior.Warning message displayed to the user.
Feedback message for Claude about the decision.
Event-specific controls (see below).