Intercept and control agent behavior with hooks changedagent-sdk/hooks
Upstream edited this page at 28 Nov 2026 18:41 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 28 Nov 2026 19:07 UTC.
Upstream edited
Recorded here
Lines+2added
Lines−2removed
From line
813
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits34to this page, all time
The whole hunk
from line 813, old and new numbered
/
from line 813
813813
814814Claude Code runs each callback with a timeout, which you set in seconds with the `timeout` field on its `HookMatcher`. When you don't set one, Claude Code uses the event's default: 600 seconds for most events, 30 seconds for `UserPromptSubmit`, `PreModelSwitch`, and `PostModelSwitch`, and 10 seconds for `MessageDisplay`. Claude Code runs `SessionEnd` callbacks during shutdown under the shorter [SessionEnd timeout budget](https://code.claude.com/docs/en/hooks.md#sessionend-input), 1.5 seconds by default.
815815
816When a callback exceeds its timeout, Claude Code cancels it and discards its output, and the session continues rather than hanging. What happens next depends on the event:
816When a callback exceeds its timeout, Claude Code cancels it and discards its output. On the events below, Claude Code then blocks the action or continues without the callback:
817817
818818* `PreToolUse`: Claude Code blocks the tool call. If every other hook returned nothing or only an `allow` decision, the tool result tells Claude the hook didn't respond before its timeout, and the turn continues. If another of your hooks already denied the call, its deny still reaches Claude: the tool result includes that hook's reason, and the timeout text can follow it.
819819
from line 824
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.
826826* `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.
827* `Notification`, `PreCompact`, and `PostModelSwitch`: Claude Code logs the failure and continues. To block compaction when a `PreCompact` callback times out, set [`onFailure: "block"`](#block-the-action-when-a-callback-fails).
828828
829829The 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.
830830
No line in this hunk matches that.