Hooks reference changedhooks
Upstream edited this page at 29 Nov 2026 00:01 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 29 Nov 2026 00:07 UTC.
Upstream edited
Recorded here
Lines+3added
Lines−3removed
From line
511
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits177to this page, all time
The whole hunk
from line 511, old and new numbered
/
This page is larger than the 256 KiB this site keeps, so one side of the diff below stops where the stored text does.
from line 511
511511
512512Error handling differs from command hooks; see [HTTP response handling](#http-response-handling).
513513
514This example sends `PreToolUse` events to a local validation service, authenticating with a token from the `MY_TOKEN` environment variable:
514This example sends each `PreToolUse` event for the Bash tool to a service that checks the command, authenticating with a token from the `MY_TOKEN` environment variable:
515515
516516```json theme={null}
517517{
from line 522
522522 "hooks": [
523523 {
524524 "type": "http",
525 "url": "http://localhost:8080/hooks/pre-tool-use",
525 "url": "https://hooks.example.com/pre-tool-use",
526526 "timeout": 30,
527527 "headers": {
528528 "Authorization": "Bearer $MY_TOKEN"
from line 816
816816
817817* **`WorktreeCreate`**: any non-zero exit code makes worktree creation fail, whatever your JSON says.
818818* **`WorktreeRemove`**: any non-zero exit code makes worktree removal fail if the directory still exists afterward.
819* **`Stop`, `SubagentStop`, `TaskCompleted`, and a plugin's `UserPromptSubmit` hook**: when your hook exits 2 with nothing on stdout and its stderr says a file is missing, such as `No such file or directory`, Claude Code treats the run as a non-blocking error.
819* **`Stop`, `SubagentStop`, `TaskCompleted`, `TeammateIdle`, and a plugin's `UserPromptSubmit` hook**: when stdout is blank and stderr contains `No such file` or `can't open` in any letter case, Claude Code assumes a missing script, so exit 2 is a non-blocking error. Correct the script path if it's wrong. Otherwise, print [`decision: "block"` JSON with a `reason`](#decision-control) on stdout and exit 0.
820820* **`Elicitation` and `ElicitationResult`**: Claude Code applies your `hookSpecificOutput` when your hook exits 0, and ignores it on any other exit code.
821821* **Events that discard hook output, such as `StopFailure`**: Claude Code ignores your JSON on any exit code, apart from side-effect fields like `terminalSequence`, which still fire.
822822
from line 3639
36393639| `context_tokens` | number | Tokens the next request re-sends as its prompt: the input, cache read, cache creation, and output tokens of the last response in the main conversation, combined. `0` before the first response |
36403640| `prompt_cache_warm` | boolean | Whether the current model's prompt cache is likely still warm, meaning the switch forfeits it |
36413641| `cache_ttl` | string | [Prompt cache lifetime](https://code.claude.com/docs/en/prompt-caching.md#cache-lifetime) of the main conversation at the time of this switch: `"5m"` or `"1h"` |
3642| `estimated_cache_write_usd` | number | Estimated cost in US dollars of writing `context_tokens` to the prompt cache on `to_model` at the `cache_ttl` rate, excluding the next response. The server may not need to re-cache the whole context, so treat it as an estimate |
3643| `pricing` | string | How Claude Code priced `estimated_cache_write_usd`: `"configured"` at you
3642| `estimated_cache_write_usd` | number | Estimated cost in US dollars of writing `context_tokens` to the prompt cache on `to_model` at the `cache_ttl` rate, excluding the next response. The se
No line in this hunk matches that.