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.HookEvent
Fires before a tool is executed. Can approve, deny, or modify tool input.
HookEvent
Fires after successful tool execution. Can add context or modify output.
HookEvent
Fires when tool execution fails. Can add error context.
HookEvent
Fires when user submits a prompt. Can add context to the prompt.
HookEvent
Fires when the main session stops.
HookEvent
Fires when a sub-agent (Task tool) completes.
HookEvent
Fires before conversation compaction.
HookEvent
Fires for system notifications.
HookEvent
Fires when a sub-agent starts.
HookEvent
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.str | None
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[HookCallback]
List of callback functions to execute for this matcher.
float | None
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
bool
Whether Claude should proceed after hook execution. Note: Use
continue_ in Python (converted to continue for CLI).bool
Hide stdout from transcript mode.
str
Message shown when
continue_ is False.Literal['block']
Set to
"block" to indicate blocking behavior.str
Warning message displayed to the user.
str
Feedback message for Claude about the decision.
HookSpecificOutput
Event-specific controls (see below).