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
3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 | |
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