Which moments a hook can attach to, and what it can do there. Event names link to each harness’s documentation. “Block”, “deny” and “modify” change what the agent does; “observe only” can watch but not intervene. Where hook files live is on the Locations page.
| Moment | Claude CodeHook commands |
|---|---|
| Hook types |
|
| Session and workspace | |
| Session setup | Setupset environment Fires only with --init-only, or --init/--maintenance in -p mode; JSON output, including additionalContext, is discarded. Only command and mcp_tool handlers run, and mcp_tool is skipped. |
| Session starts | SessionStartadd context, set environment Only command and mcp_tool handlers run, and mcp_tool is skipped at launch. |
| Directory is added | DirectoryAddedadd context For /add-dir the hook's systemMessage reaches Claude as context on the next turn; for repository-root registration it only reaches the debug log. |
| Working directory changes | CwdChangedset environment No matcher. Variables written to CLAUDE_ENV_FILE are cleared at the next CwdChanged. |
| Configuration changes | |
| Worktree is created | WorktreeCreatedelegate Provider operation: the hook creates the worktree and returns its path (command hooks on stdout, HTTP hooks in hookSpecificOutput.worktreePath). |
| Worktree is removed | WorktreeRemovedelegate Provider operation: the hook performs removal; this is not a notification hook. Fires only for worktrees a WorktreeCreate hook created. The 2.1.301 changelog reports a fix for exit removing hook-created worktrees without confirmation despite possible unpushed commits. Other WorktreeRemove cases may still remove without asking. |
| Session ends | SessionEndobserve only |
| Prompt and turn | |
| Before a prompt or command is expanded | UserPromptExpansionblock, add context |
| User submits a prompt | UserPromptSubmitblock, add context |
| Task is created | TaskCreatedblock |
| Task is completed | TaskCompletedblock, stop |
| Notification is sent | Notificationobserve only |
| Teammate goes idle | TeammateIdleblock, stop |
| Turn fails | StopFailureobserve only |
| Agent finishes its turn | Stopblock, add context |
| Tools | |
| Before a tool runs | PreToolUseallow, deny, ask user, defer, modify, add context defer works only in -p mode and for a single tool call per turn. A hook that times out does not block unless the handler sets onFailure: "block". |
| After a tool succeeds | PostToolUseadd context, modify, annotate decision: "block" does not undo the tool; it adds the reason next to the result. updatedToolOutput and updatedMCPToolOutput replace the output Claude sees. |
| After a tool fails | PostToolUseFailureadd context |
| After a batch of tools | PostToolBatchadd context, stop |
| Permissions and questions | |
| Permission is requested | PermissionRequestallow, deny, modify, update permissions, stop Exit code 2 is not honoured; deny with decision.behavior. updatedInput applies only when allowing. |
| Permission is denied | |
| Shell, terminals and files | |
| Watched file changes | FileChangedset environment |
| MCP | |
| MCP server asks the user | Elicitationtake over, deny, cancel MCP input requests only, distinct from PermissionRequest and model ask-user tools. Supports structured content and accept/decline/cancel; a hook answer bypasses ElicitationResult. Schema validation after a programmatic answer remains unverified. |
| User answers an MCP server | ElicitationResultmodify, deny, cancel Runs after user replies, including decline/cancel, but not after Elicitation hook answers. Can replace the whole content object. Official docs say cancel may retain submitted values; decline withholds them. This does not establish backend schema validation. |
| Subagents | |
| Subagent starts | SubagentStartadd context |
| Subagent finishes | SubagentStopblock, add context |
| Context and compaction | |
| Instructions are loaded | InstructionsLoadedobserve only |
| Before context is compacted | PreCompactblock |
| After context is compacted | PostCompactobserve only |
| Model and provider | |
| Before the model switches | PreModelSwitchallow, deny, ask user Runs only for switches a user or client requested (/model, the model picker, /config, fast mode, SDK set_model); automatic fallback and resume restores reach PostModelSwitch only. The matcher is compared against the canonical target model name; when no canonical name resolves, every PreModelSwitch hook runs regardless of matcher. A hook timeout blocks the switch, unlike PreToolUse. Outside interactive /model, ask is treated as a refusal. |
| After the model switches | PostModelSwitchadd context Also runs for automatic fallback, opusplan plan-mode transitions, and model restoration on resume, but not for a one-turn fallback-chain substitution. Cannot block. Output is delivered with the next request; only the last switch's output is delivered when several switches precede that request. |
| Messages and interface | |
| Message is displayed | MessageDisplaymodify displayContent changes only what is shown on screen; the transcript and what Claude sees keep the original. |
Notes and sources
Claude Code
- onFailure: "block" on a command or HTTP hook makes a failed or timed-out hook block the action (2.1.295 and later).
- Plugin mods are a separate JavaScript hook surface with their own events and are not recorded here.
- 2.1.302 published changes: at most 12 prompt and agent hooks for one event run at once; remaining handlers wait. This is not the subagent concurrency limit or a stated cap on command/MCP hooks. Superseded by 2.1.312 below.
- 2.1.304 caps skill hooks from each source (a repository, personal folder or plugin) at 1,024 hooks and 16,384 matcher characters per session; these are separate from the 12 prompt/agent-hook concurrency limit.
- 2.1.304 fixes a skill once hook removing another skill’s identical hook, preserves a PreToolUse deny reason when an SDK callback hook times out, and excludes up to 10 minutes of SessionStart command-hook runtime from the VS Code subprocess initialization timeout.
- 2.1.304 adds a transcript notice identifying the event and plugin when an earlier plugin skips a mod hook. Mod tool.check gains e.isReadOnly and decider: person; settings.read receives individual layers and can rewrite merged settings. Mods remain a separate JavaScript hook surface.
- 2.1.309 publisher fixes PowerShell command hooks failing to block on exit code 2, including Windows PreToolUse/PermissionRequest fail-open behavior without Git for Windows. No hook-execution probe.
- 2.1.307 added claude_code.safety_event OpenTelemetry instrumentation for permission/safety/hook/sandbox outcomes; 2.1.312 stops sending it. It was never a hook event or hook control authority.
- 2.1.311 publisher fixes SubagentStop firing repeatedly while a subagent runs (about twice per minute); it should run once when the subagent finishes. 2.1.310 fixes Windows PreToolUse/PermissionRequest fail-open behavior with only quoted command strings when Git Bash is missing. No hook-execution probe.
- 2.1.312 publisher notes: prompt and agent hooks run at most 24 at a time per session, subagents included, plus at most 12 that have waited longer than their event's timeout. A
timeoutunder 1 second counts as 1 second. Command, HTTP and MCP-tool hooks are not covered by this limit. No hook-execution probe. - Publisher updates: 2.1.314 truncates each PreCompact hook output to 10,000 characters; 2.1.317 adds onFailure: block to Agent SDK callbacks; 2.1.319 runs PostToolUse (up to 10 seconds) for calls finishing after a new message interrupts the turn. 2.1.321 fixes competing PreToolUse ask/defer answers, refuses MCP tool calls on >16 MiB mcp_tool hook replies, and keeps original AskUserQuestion/ExitPlanMode results despite PostToolUse replacements in Cowork cloud. Separate hosts and handler types; no execution probe.
- 2.1.328 publisher notes extend onFailure: block to mcp_tool hooks and add CLAUDE_CODE_DISABLE_DEFERRED_TOOL_RESUME to stop deferred tool execution on -p --resume/--continue. Code Mode script output no longer runs UserPromptSubmit hooks; use PostToolUse updatedToolOutput for redaction. Managed PostToolUse no longer fires for calls refused before execution; PostToolBatch receives most without a refused marker. No hook runtime probe.
- Claude Code hooks reference, Documentation, checked 2026-10-15
- Claude Code 2.1.301 published changes, Documentation, checked 2026-10-16
- Claude Code 2.1.302 published changes; no runtime probe, Documentation, checked 2026-10-19
- Claude Code 2.1.304 published changes; no runtime probe, Documentation, checked 2026-10-21
- Claude Code 2.1.309 publisher changelog, Documentation, checked 2026-10-24
- Claude Code 2.1.307 publisher changelog, Documentation, checked 2026-10-24
- Claude Code 2.1.310 publisher changelog, Documentation, checked 2026-10-28
- Claude Code 2.1.311 publisher changelog, Documentation, checked 2026-10-28
- Claude Code 2.1.312 publisher changelog, Documentation, checked 2026-10-30
- Claude Code 2.1.314 publisher changelog, Documentation, checked 2026-11-12
- Claude Code 2.1.317 publisher changelog, Documentation, checked 2026-11-12
- Claude Code 2.1.319 publisher changelog, Documentation, checked 2026-11-12
- Claude Code 2.1.321 publisher changelog, Documentation, checked 2026-11-12
- Claude Code 2.1.328 publisher changelog, Documentation, checked 2026-11-20