Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · claude-code

Intercept and control agent behavior with hooks changedagent-sdk/hooks

Upstream edited this page at 23 Nov 2026 04:15 UTC, give or take a minute or two: the time comes from Anthropic’s own sitemap rather than from a commit. This site recorded the change at 23 Nov 2026 04:37 UTC.

Upstream edited
Recorded here
Lines+5added
Lines−4removed
From line 170 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits29to this page, all time

The whole hunk

from line 170, old and new numbered
/
lines
from line 170
170170| `ElicitationResult` | No | Yes | A user responds to an MCP elicitation | Modify or block the response before it returns to the server |
171171| `ConfigChange` | No | Yes | Configuration file changes | Reload settings dynamically |
172172| `InstructionsLoaded` | No | Yes | A `CLAUDE.md` or rules file is loaded into context | Audit which instruction files load |
173| `WorktreeCreate` | No | Yes | Git worktree created | Track isolated workspaces |
173| `WorktreeCreate` | No | Yes | Claude Code needs a worktree, and the hook creates it instead of git | Create the worktree and return its path in [`hookSpecificOutput.worktreePath`](https://code.claude.com/docs/en/hooks#worktreecreate-output) |
174174| `WorktreeRemove` | No | Yes | A worktree created by a `WorktreeCreate` hook is being removed | Clean up workspace resources |
175175| `CwdChanged` | No | Yes | The working directory changes during a session | Reload environment variables per directory |
176176| `FileChanged` | No | Yes | A watched file is modified, created, or deleted | Reload configuration when project files change |
from line 308
308308 
309309To test it, make the callback raise an error and ask Claude to run a Bash command. The tool result includes `failed; blocking because onFailure is "block"`, and Claude doesn't see your error text.
310310 
311Return `{}` when the callback has no opinion. With `"block"` set, a path with no `return` blocks the action. A callback that catches its own error and returns `{}` isn't failing, so let the error propagate from a guard.
311Return `{}` when the callback has no opinion. With `"block"` set, a path with no `return` blocks the action. A callback that catches its own error and returns `{}` isn't failing, so let the error propagate from a guard. A `WorktreeCreate` callback must return `hookSpecificOutput.worktreePath`.
312312 
313313#### Events that behave differently
314314 
from line 318
318318* **`PermissionRequest`**: the block counts only if it arrives before your `canUseTool` callback answers.
319319* **`PostToolUse`**: the tool has already run, so Claude receives the failure as feedback.
320320 
321A callback that exceeds its timeout follows [Hook timeout](#hook-timeout). With `"block"` set, a timeout also blocks `PreCompact`, `Elicitation`, and `WorktreeCreate`.
321A callback that exceeds its timeout follows [Hook timeout](#hook-timeout). With `"block"` set, a timeout also blocks `PreCompact` and `Elicitation`.
322322 
323323#### Startup errors for `onFailure`
324324 
from line 823
823823* `Stop` and `SubagentStop`: the timed-out callback counts as returning no decision. The agent or subagent stops as if that callback had allowed it, and a decision from your other hooks on the event still applies. Before Claude Code v2.1.273, a timed-out `Stop` or `SubagentStop` callback counted as a failed hook run, and Claude Code discarded the decisions of your other hooks on the event.
824824* `SessionStart`: the timed-out callback counts as returning no output, and the session continues with the output of your other `SessionStart` hooks.
825825* `PreModelSwitch`: Claude Code blocks the model switch. A hook that doesn't answer hasn't approved the switch.
826* Other events, such as `Notification`, `PreCompact`, and `PostModelSwitch`: Claude Code logs the failure and continues. With [`onFailure: "block"`](#block-the-action-when-a-callback-fails), a timeout on `PreCompact`, `Elicitation`, or `WorktreeCreate` blocks the action.
826* `WorktreeCreate`: worktree creation fails with an error.
827* Other events, such as `Notification`, `PreCompact`, and `PostModelSwitch`: Claude Code logs the failure and continues. With [`onFailure: "block"`](#block-the-action-when-a-callback-fails), a timeout on `PreCompact` or `Elicitation` blocks the action.
827828 
828829The first time a `Stop` or `SessionStart` callback times out in the main session, Claude Code also adds an [`SDKInformationalMessage`](https://code.claude.com/docs/en/agent-sdk/typescript#sdkinformationalmessage) to the message stream saying the app driving the session didn't respond. Later timeouts don't repeat that message while your app stays unresponsive.
829830 
Feedback