Harness Notes

Hooks

Updated 2026-11-22,

On this page

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.

MomentClaude CodeHook commands
Hook types
  • command
  • http
  • mcp_tool
  • prompt
  • agent (experimental)
Session and workspace
Session setup
Setup

set 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
SessionStart

add context, set environment

Only command and mcp_tool handlers run, and mcp_tool is skipped at launch.

Directory is added
DirectoryAdded

add 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
CwdChanged

set environment

No matcher. Variables written to CLAUDE_ENV_FILE are cleared at the next CwdChanged.

Configuration changes
ConfigChange

block

Changes to policy settings cannot be blocked.

Worktree is created
WorktreeCreate

delegate

Provider operation: the hook creates the worktree and returns its path (command hooks on stdout, HTTP hooks in hookSpecificOutput.worktreePath).

Worktree is removed
WorktreeRemove

delegate

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
SessionEnd

observe only

Prompt and turn
Before a prompt or command is expanded
UserPromptExpansion

block, add context

User submits a prompt
UserPromptSubmit

block, add context

Task is created
Task is completed
TaskCompleted

block, stop

Notification is sent
Notification

observe only

Teammate goes idle
TeammateIdle

block, stop

Turn fails
StopFailure

observe only

Agent finishes its turn
Stop

block, add context

Tools
Before a tool runs
PreToolUse

allow, 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
PostToolUse

add 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
After a batch of tools
PostToolBatch

add context, stop

Permissions and questions
Permission is requested
PermissionRequest

allow, deny, modify, update permissions, stop

Exit code 2 is not honoured; deny with decision.behavior. updatedInput applies only when allowing.

Permission is denied
PermissionDenied

retry

Fires only in auto mode; retry is ignored for denials without a verdict.

Shell, terminals and files
Watched file changes
FileChanged

set environment

MCP
MCP server asks the user
Elicitation

take 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
ElicitationResult

modify, 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
SubagentStart

add context

Subagent finishes
SubagentStop

block, add context

Context and compaction
Instructions are loaded
InstructionsLoaded

observe only

Before context is compacted
After context is compacted
PostCompact

observe only

Model and provider
Before the model switches
PreModelSwitch

allow, 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
PostModelSwitch

add 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
MessageDisplay

modify

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 timeout under 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.