Skip to content

Hooks

Base classes

Name Children Inherits
ClaudeCodeBaseModel
clawd_code_sdk.models.base
Base model for all Claude Code Pydantic models.

â‹” Inheritance diagram

graph TD
  2338608984["settings.Hooks"]
  2604142835["base.ClaudeCodeBaseModel"]
  3879467795["main.BaseModel"]
  2751680898["builtins.object"]
  2604142835 --> 2338608984
  3879467795 --> 2604142835
  2751680898 --> 3879467795

🛈 DocStrings

Bases: ClaudeCodeBaseModel

Lifecycle event hooks that run at configurable points during Claude Code operation (tool use, session start/end, notifications, prompt submit, message display, and more), not just before/after tool executions. See https://code.claude.com/docs/en/hooks.

Source code in src/clawd_code_sdk/models/settings.py
class Hooks(ClaudeCodeBaseModel):
    """Lifecycle event hooks that run at configurable points during Claude Code operation (tool use, session start/end, notifications, prompt submit, message display, and more), not just before/after tool executions. See https://code.claude.com/docs/en/hooks."""

    model_config = ConfigDict(
        extra="forbid",
    )
    pre_tool_use: list[HookMatcher] | None = Field(None, alias="PreToolUse")
    """
    Hooks that run before tool calls
    """
    post_tool_use: list[HookMatcher] | None = Field(None, alias="PostToolUse")
    """
    Hooks that run after tool completion
    """
    post_tool_use_failure: list[HookMatcher] | None = Field(None, alias="PostToolUseFailure")
    """
    Hooks that run after a tool fails
    """
    permission_request: list[HookMatcher] | None = Field(None, alias="PermissionRequest")
    """
    Hooks that run when a permission dialog appears
    """
    notification: list[HookMatcher] | None = Field(None, alias="Notification")
    """
    Hooks that trigger on notifications
    """
    user_prompt_submit: list[HookMatcher] | None = Field(None, alias="UserPromptSubmit")
    """
    Hooks that run when a user submits a prompt
    """
    stop: list[HookMatcher] | None = Field(None, alias="Stop")
    """
    Hooks that run when agents finish responding. Does not run on user interrupt
    """
    stop_failure: list[HookMatcher] | None = Field(None, alias="StopFailure")
    """
    Hooks that run when a turn ends due to an API error (e.g., rate_limit, authentication_failed, billing_error, invalid_request, server_error, max_output_tokens, unknown). Matcher can scope to specific error types. Hook output and exit code are ignored. See https://code.claude.com/docs/en/hooks
    """
    subagent_start: list[HookMatcher] | None = Field(None, alias="SubagentStart")
    """
    Hooks that run when a subagent is spawned
    """
    subagent_stop: list[HookMatcher] | None = Field(None, alias="SubagentStop")
    """
    Hooks that run when subagents finish responding
    """
    pre_compact: list[HookMatcher] | None = Field(None, alias="PreCompact")
    """
    Hooks that run before the context is compacted
    """
    post_compact: list[HookMatcher] | None = Field(None, alias="PostCompact")
    """
    Hooks that run after the context is compacted. See https://code.claude.com/docs/en/hooks
    """
    elicitation: list[HookMatcher] | None = Field(None, alias="Elicitation")
    """
    Hooks that run when an MCP server requests user input during a tool call. See https://code.claude.com/docs/en/hooks
    """
    elicitation_result: list[HookMatcher] | None = Field(None, alias="ElicitationResult")
    """
    Hooks that run after a user responds to an MCP elicitation, before the response is sent back to the server. See https://code.claude.com/docs/en/hooks
    """
    teammate_idle: list[HookMatcher] | None = Field(None, alias="TeammateIdle")
    """
    Hooks that run when an agent team teammate is about to go idle. Exit code 2 sends feedback and keeps the teammate working. Does not support matchers. Agent teams are experimental. See https://code.claude.com/docs/en/hooks#teammateidle
    """
    task_completed: list[HookMatcher] | None = Field(None, alias="TaskCompleted")
    """
    Hooks that run when a task is being marked as completed. Exit code 2 prevents completion and sends feedback. Does not support matchers. See https://code.claude.com/docs/en/hooks#taskcompleted
    """
    setup: list[HookMatcher] | None = Field(None, alias="Setup")
    """
    UNDOCUMENTED. Hooks that run during repository initialization (--init, --init-only) or maintenance (--maintenance)
    """
    instructions_loaded: list[HookMatcher] | None = Field(None, alias="InstructionsLoaded")
    """
    Hooks that run when a CLAUDE.md or .claude/rules/*.md file is loaded into context. Fires at session start and when files are lazily loaded (e.g., nested traversal, path glob match). No decision control; used for audit logging and observability. Does not support matchers. See https://code.claude.com/docs/en/hooks#instructionsloaded
    """
    cwd_changed: list[HookMatcher] | None = Field(None, alias="CwdChanged")
    """
    Hooks that run when the working directory changes. Provides cwd (new directory) and previous_cwd. Matchers are ignored; fires on every directory change. See https://code.claude.com/docs/en/hooks#cwdchanged
    """
    file_changed: list[HookMatcher] | None = Field(None, alias="FileChanged")
    """
    Hooks that run when a watched file is created, modified, or deleted. Supports filename matchers. Provides file_path and file_event_type (created, modified, deleted). See https://code.claude.com/docs/en/hooks#filechanged
    """
    config_change: list[HookMatcher] | None = Field(None, alias="ConfigChange")
    """
    Hooks that run when settings, managed settings, or skill files change during a session. Supports matchers: user_settings, project_settings, local_settings, policy_settings, skills. Command handlers only. Exit code 2 blocks the change (except policy_settings which is audit-only). See https://code.claude.com/docs/en/hooks#configchange
    """
    worktree_create: list[HookMatcher] | None = Field(None, alias="WorktreeCreate")
    """
    Hooks that run when a worktree is created via --worktree or isolation: "worktree" in subagents. Command handlers only, no matchers. Hook must print absolute path to created worktree on stdout; non-zero exit fails creation. See https://code.claude.com/docs/en/hooks#worktreecreate
    """
    worktree_remove: list[HookMatcher] | None = Field(None, alias="WorktreeRemove")
    """
    Hooks that run when a worktree is being removed at session exit or when a subagent finishes. Command handlers only, no matchers. Used for cleanup tasks; cannot block removal. See https://code.claude.com/docs/en/hooks#worktreeremove
    """
    session_start: list[HookMatcher] | None = Field(None, alias="SessionStart")
    """
    Hooks that run when a new session starts
    """
    session_end: list[HookMatcher] | None = Field(None, alias="SessionEnd")
    """
    Hooks that run when a session ends
    """
    post_tool_batch: list[HookMatcher] | None = Field(None, alias="PostToolBatch")
    """
    Hooks that run after a full batch of parallel tool calls resolves, before the next model call. Exit code 2 blocks the agentic loop. Does not support matchers. See https://code.claude.com/docs/en/hooks
    """
    task_created: list[HookMatcher] | None = Field(None, alias="TaskCreated")
    """
    Hooks that run when a task is being created via TaskCreate. Exit code 2 rolls back task creation. Does not support matchers. See https://code.claude.com/docs/en/hooks#taskcreated
    """
    permission_denied: list[HookMatcher] | None = Field(None, alias="PermissionDenied")
    """
    Hooks that run when a tool call is denied by the auto mode classifier. Supports matchers on tool name. See https://code.claude.com/docs/en/hooks
    """
    user_prompt_expansion: list[HookMatcher] | None = Field(None, alias="UserPromptExpansion")
    """
    Hooks that run when a user-typed command expands into a prompt, before it reaches Claude. Exit code 2 blocks the expansion. Supports matchers on command name. See https://code.claude.com/docs/en/hooks
    """
    message_display: list[HookMatcher] | None = Field(None, alias="MessageDisplay")
    """
    Hooks that run while assistant message text is displayed
    """
    directory_added: list[HookMatcher] | None = Field(None, alias="DirectoryAdded")
    """
    UNDOCUMENTED. Hooks that run after /add-dir or the SDK register_repo_root control request registers a new working directory mid-session (added v2.1.219)
    """

config_change class-attribute instance-attribute

config_change: list[HookMatcher] | None = Field(None, alias='ConfigChange')

Hooks that run when settings, managed settings, or skill files change during a session. Supports matchers: user_settings, project_settings, local_settings, policy_settings, skills. Command handlers only. Exit code 2 blocks the change (except policy_settings which is audit-only). See https://code.claude.com/docs/en/hooks#configchange

cwd_changed class-attribute instance-attribute

cwd_changed: list[HookMatcher] | None = Field(None, alias='CwdChanged')

Hooks that run when the working directory changes. Provides cwd (new directory) and previous_cwd. Matchers are ignored; fires on every directory change. See https://code.claude.com/docs/en/hooks#cwdchanged

directory_added class-attribute instance-attribute

directory_added: list[HookMatcher] | None = Field(None, alias='DirectoryAdded')

UNDOCUMENTED. Hooks that run after /add-dir or the SDK register_repo_root control request registers a new working directory mid-session (added v2.1.219)

elicitation class-attribute instance-attribute

elicitation: list[HookMatcher] | None = Field(None, alias='Elicitation')

Hooks that run when an MCP server requests user input during a tool call. See https://code.claude.com/docs/en/hooks

elicitation_result class-attribute instance-attribute

elicitation_result: list[HookMatcher] | None = Field(None, alias='ElicitationResult')

Hooks that run after a user responds to an MCP elicitation, before the response is sent back to the server. See https://code.claude.com/docs/en/hooks

file_changed class-attribute instance-attribute

file_changed: list[HookMatcher] | None = Field(None, alias='FileChanged')

Hooks that run when a watched file is created, modified, or deleted. Supports filename matchers. Provides file_path and file_event_type (created, modified, deleted). See https://code.claude.com/docs/en/hooks#filechanged

instructions_loaded class-attribute instance-attribute

instructions_loaded: list[HookMatcher] | None = Field(None, alias='InstructionsLoaded')

Hooks that run when a CLAUDE.md or .claude/rules/*.md file is loaded into context. Fires at session start and when files are lazily loaded (e.g., nested traversal, path glob match). No decision control; used for audit logging and observability. Does not support matchers. See https://code.claude.com/docs/en/hooks#instructionsloaded

message_display class-attribute instance-attribute

message_display: list[HookMatcher] | None = Field(None, alias='MessageDisplay')

Hooks that run while assistant message text is displayed

notification class-attribute instance-attribute

notification: list[HookMatcher] | None = Field(None, alias='Notification')

Hooks that trigger on notifications

permission_denied class-attribute instance-attribute

permission_denied: list[HookMatcher] | None = Field(None, alias='PermissionDenied')

Hooks that run when a tool call is denied by the auto mode classifier. Supports matchers on tool name. See https://code.claude.com/docs/en/hooks

permission_request class-attribute instance-attribute

permission_request: list[HookMatcher] | None = Field(None, alias='PermissionRequest')

Hooks that run when a permission dialog appears

post_compact class-attribute instance-attribute

post_compact: list[HookMatcher] | None = Field(None, alias='PostCompact')

Hooks that run after the context is compacted. See https://code.claude.com/docs/en/hooks

post_tool_batch class-attribute instance-attribute

post_tool_batch: list[HookMatcher] | None = Field(None, alias='PostToolBatch')

Hooks that run after a full batch of parallel tool calls resolves, before the next model call. Exit code 2 blocks the agentic loop. Does not support matchers. See https://code.claude.com/docs/en/hooks

post_tool_use class-attribute instance-attribute

post_tool_use: list[HookMatcher] | None = Field(None, alias='PostToolUse')

Hooks that run after tool completion

post_tool_use_failure class-attribute instance-attribute

post_tool_use_failure: list[HookMatcher] | None = Field(None, alias='PostToolUseFailure')

Hooks that run after a tool fails

pre_compact class-attribute instance-attribute

pre_compact: list[HookMatcher] | None = Field(None, alias='PreCompact')

Hooks that run before the context is compacted

pre_tool_use class-attribute instance-attribute

pre_tool_use: list[HookMatcher] | None = Field(None, alias='PreToolUse')

Hooks that run before tool calls

session_end class-attribute instance-attribute

session_end: list[HookMatcher] | None = Field(None, alias='SessionEnd')

Hooks that run when a session ends

session_start class-attribute instance-attribute

session_start: list[HookMatcher] | None = Field(None, alias='SessionStart')

Hooks that run when a new session starts

setup class-attribute instance-attribute

setup: list[HookMatcher] | None = Field(None, alias='Setup')

UNDOCUMENTED. Hooks that run during repository initialization (--init, --init-only) or maintenance (--maintenance)

stop class-attribute instance-attribute

stop: list[HookMatcher] | None = Field(None, alias='Stop')

Hooks that run when agents finish responding. Does not run on user interrupt

stop_failure class-attribute instance-attribute

stop_failure: list[HookMatcher] | None = Field(None, alias='StopFailure')

Hooks that run when a turn ends due to an API error (e.g., rate_limit, authentication_failed, billing_error, invalid_request, server_error, max_output_tokens, unknown). Matcher can scope to specific error types. Hook output and exit code are ignored. See https://code.claude.com/docs/en/hooks

subagent_start class-attribute instance-attribute

subagent_start: list[HookMatcher] | None = Field(None, alias='SubagentStart')

Hooks that run when a subagent is spawned

subagent_stop class-attribute instance-attribute

subagent_stop: list[HookMatcher] | None = Field(None, alias='SubagentStop')

Hooks that run when subagents finish responding

task_completed class-attribute instance-attribute

task_completed: list[HookMatcher] | None = Field(None, alias='TaskCompleted')

Hooks that run when a task is being marked as completed. Exit code 2 prevents completion and sends feedback. Does not support matchers. See https://code.claude.com/docs/en/hooks#taskcompleted

task_created class-attribute instance-attribute

task_created: list[HookMatcher] | None = Field(None, alias='TaskCreated')

Hooks that run when a task is being created via TaskCreate. Exit code 2 rolls back task creation. Does not support matchers. See https://code.claude.com/docs/en/hooks#taskcreated

teammate_idle class-attribute instance-attribute

teammate_idle: list[HookMatcher] | None = Field(None, alias='TeammateIdle')

Hooks that run when an agent team teammate is about to go idle. Exit code 2 sends feedback and keeps the teammate working. Does not support matchers. Agent teams are experimental. See https://code.claude.com/docs/en/hooks#teammateidle

user_prompt_expansion class-attribute instance-attribute

user_prompt_expansion: list[HookMatcher] | None = Field(None, alias='UserPromptExpansion')

Hooks that run when a user-typed command expands into a prompt, before it reaches Claude. Exit code 2 blocks the expansion. Supports matchers on command name. See https://code.claude.com/docs/en/hooks

user_prompt_submit class-attribute instance-attribute

user_prompt_submit: list[HookMatcher] | None = Field(None, alias='UserPromptSubmit')

Hooks that run when a user submits a prompt

worktree_create class-attribute instance-attribute

worktree_create: list[HookMatcher] | None = Field(None, alias='WorktreeCreate')

Hooks that run when a worktree is created via --worktree or isolation: "worktree" in subagents. Command handlers only, no matchers. Hook must print absolute path to created worktree on stdout; non-zero exit fails creation. See https://code.claude.com/docs/en/hooks#worktreecreate

worktree_remove class-attribute instance-attribute

worktree_remove: list[HookMatcher] | None = Field(None, alias='WorktreeRemove')

Hooks that run when a worktree is being removed at session exit or when a subagent finishes. Command handlers only, no matchers. Used for cleanup tasks; cannot block removal. See https://code.claude.com/docs/en/hooks#worktreeremove

:fa-brands-github: Show source on GitHub