Skip to main content

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.
PreToolUse
HookEvent
Fires before a tool is executed. Can approve, deny, or modify tool input.
PostToolUse
HookEvent
Fires after successful tool execution. Can add context or modify output.
PostToolUseFailure
HookEvent
Fires when tool execution fails. Can add error context.
UserPromptSubmit
HookEvent
Fires when user submits a prompt. Can add context to the prompt.
Stop
HookEvent
Fires when the main session stops.
SubagentStop
HookEvent
Fires when a sub-agent (Task tool) completes.
PreCompact
HookEvent
Fires before conversation compaction.
Notification
HookEvent
Fires for system notifications.
SubagentStart
HookEvent
Fires when a sub-agent starts.
PermissionRequest
HookEvent
Fires when permission is requested for a tool.

HookCallback

Function signature for hook callbacks.
Hook callbacks receive:
  1. input: HookInput - Strongly-typed input data for the event
  2. tool_use_id: str | None - Optional tool use identifier
  3. context: HookContext - Hook context (currently contains signal placeholder)
And must return a HookJSONOutput dictionary.

Example

HookMatcher

Configuration for matching and handling hook events.
matcher
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.
hooks
list[HookCallback]
List of callback functions to execute for this matcher.
timeout
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 extend BaseHookInput.

BaseHookInput

PreToolUseHookInput

PostToolUseHookInput

PostToolUseFailureHookInput

UserPromptSubmitHookInput

StopHookInput

SubagentStopHookInput

PreCompactHookInput

NotificationHookInput

SubagentStartHookInput

PermissionRequestHookInput

HookJSONOutput Types

Output types for hook callbacks. Can be synchronous or asynchronous.

SyncHookJSONOutput

continue_
bool
Whether Claude should proceed after hook execution. Note: Use continue_ in Python (converted to continue for CLI).
suppressOutput
bool
Hide stdout from transcript mode.
stopReason
str
Message shown when continue_ is False.
decision
Literal['block']
Set to "block" to indicate blocking behavior.
systemMessage
str
Warning message displayed to the user.
reason
str
Feedback message for Claude about the decision.
hookSpecificOutput
HookSpecificOutput
Event-specific controls (see below).

AsyncHookJSONOutput

Defers hook execution. Use for long-running operations.

HookSpecificOutput

Event-specific output for fine-grained control.

HookContext

Context information passed to hook callbacks.
Currently a placeholder for future abort signal support.

Complete Example

Python uses async_ and continue_ (with underscores) to avoid keyword conflicts. These are automatically converted to async and continue when sent to the CLI.