Hooks reference changedhooks
Nearest release: v2.1.335, published under an hour after upstream edited the page. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Upstream edited this page at 2 Dec 2026 20:54 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 2 Dec 2026 21:07 UTC.
Upstream edited
Recorded here
Lines+14added
Lines−19removed
From line
312
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 312, 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 312
312312
313313Matching `StopFailure` on `cloud_credential_error` requires Claude Code v2.1.267 or later, the first version that reports credential-load failures under that value rather than `server_error` or `unknown`.
314314
315For most events, Claude Code evaluates the matcher against a field from the [JSON input](#hook-input-and-output) it sends to your hook on stdin. For tool events, that field is `tool_name`. For `PreModelSwitch` and `PostModelSwitch`, Claude Code evaluates the matcher against the canonical name it derives from `to_model`, as described under [PreModelSwitch](#premodelswitch). Each [hook event](#hook-events) section lists the full set of matcher values and the input schema for that event.
315For most events, Claude Code evaluates the matcher against a field from the [JSON input](#hook-input-and-output) it sends to your hook on stdin. On tool events, that field is `tool_name`. For `PreModelSwitch` and `PostModelSwitch`, Claude Code evaluates the matcher against the canonical name it derives from the `to_model` field, as described under [PreModelSwitch](#premodelswitch). Each [hook event](#hook-events) section lists the matcher values and the input schema for that event.
316316
317317This example runs a linting script only when Claude writes or edits a file:
318318
from line 1282
12821282
12831283### SessionStart
12841284
1285Runs when Claude Code starts a new session or resumes an existing session. Useful for loading development context like existing issues or recent changes to your codebase, or setting up environment variables. For static context that doesn't require a script, use [CLAUDE.md](https://code.claude.com/docs/en/memory.md) instead.
1285Runs when Claude Code starts a new session or resumes an existing session. Useful for loading development context like existing issues or recent changes to your codebase, or setting up environment variables.
12861286
1287SessionStart runs on every session, so keep these hooks fast. Only `type: "command"` and `type: "mcp_tool"` hooks are supported. See [MCP tool hook fields](#mcp-tool-hook-fields) for when `mcp_tool` hooks run.
1287Only `type: "command"` and `type: "mcp_tool"` hooks are supported. See [MCP tool hook fields](#mcp-tool-hook-fields) for when `mcp_tool` hooks run.
12881288
12891289The matcher value corresponds to how the session was initiated:
12901290
from line 1296
12961296| `compact` | Auto or manual compaction |
12971297| `fork` | A new session forked from an existing one: `--fork-session` with `--resume` or `--continue`, the `/fork` background copy, `/branch`, or a conversation you [move to the background](https://code.claude.com/docs/en/agent-view.md#from-inside-a-session) |
12981298
1299When you start an interactive session, resume a conversation at launch with `--continue` or `--resume`, or run `/clear`, you can type while SessionStart hooks run. A conversation you resumed at launch appears without waiting for the hooks. When you run `/resume` inside a terminal session, you see the resumed conversation after its synchronous hooks finish. SessionStart hooks are [synchronous by default](#run-hooks-in-the-background).
1299After you start a terminal session or run `/clear` in one, Claude Code sends your prompt once the [synchronous](#run-hooks-in-the-background) SessionStart hooks finish, so Claude has their context. To take the prompt back into the input while it waits, press `Esc`.
13001300
1301While synchronous hooks are still running after launch or `/clear` in an interactive terminal session, Claude Code waits to send your prompt or discards their output:
1302
1303* **You send a prompt**: Claude Code sends the prompt after the hooks finish, so their context reaches Claude. To take the waiting prompt back into the input, press `Esc`. The hooks keep running.
1304* **You run `/clear`**: Claude Code discards what the hooks return.
1305
13061301If a plugin finishes loading after the session starts, your prompt can reach Claude without the context from that plugin's hooks.
13071302
13081303#### SessionStart input
from line 2083
20882083| `permissionDecision` | `"allow"` skips the permission prompt, except for [actions no mode auto-approves](https://code.claude.com/docs/en/permission-modes.md#actions-no-mode-auto-approves) and [reads from network paths](https://code.claude.com/docs/en/permissions.md#network-paths). It doesn't skip approval for calls to [tools an Agent SDK app marks `always_ask`](https://code.claude.com/docs/en/agent-sdk/custom-tools#require-approval-for-specific-tools) either, unless the [permission mode approves the call](https://code.claude.com/docs/en/agent-sdk/typescript.md#permission-modes-that-can-approve-an-always_ask-call). `AskUserQuestion` and `ExitPlanMode` need [`updatedInput` paired with `"allow"`](#allow-with-updatedinput). For plan mode, see [Hook approvals in plan mode](https://code.claude.com/docs/en/permissions.md#hook-approvals-in-plan-mode). `"deny"` prevents the tool call. `"ask"` prompts the user to confirm. `"defer"` ends the turn so the tool can be resumed later, and requires [non-interactive mode](#defer-a-tool-call-for-later) with the `-p` flag. [Deny and ask rules](https://code.claude.com/docs/en/permissions.md#manage-permissions) are still evaluated regardless of what the hook returns |
20892084| `permissionDecisionReason` | For `"ask"`, shown to the user in the permission prompt. When Claude Code [denies the call](https://code.claude.com/docs/en/headless.md#turn-off-permission-prompts-in-unattended-runs) in a `-p` run where no one can answer that prompt, Claude reads the reason in the tool result instead. For `"deny"`, shown to Claude. For `"allow"` and `"defer"`, written to the [debug log](#debug-hooks) only |
20902085| `updatedInput` | Modifies the tool's input parameters before execution. Replaces the entire input object, so include unchanged fields alongside modified ones. Claude Code evaluates permission rules and a Bash command's [auto-background eligibility](https://code.claude.com/docs/en/tools-reference.md#foreground-commands-that-move-to-the-background) against the input your hook returns, not the input Claude sent. Combine with `"allow"` to auto-approve, or `"ask"` to show the modified input to the user. For `"defer"`, ignored. With no `permissionDecision`, [auto mode can deny the changed call](#pretooluse-updatedinput-in-auto-mode) |
2091| `additionalContext` | String added to Claude's context alongside the tool result. Ignored when `permissionDecision` is `"defer"`. See [Add context for Claude](#add-context-for-claude) |
2086| `additionalContext` | String added to Claude's context alongside the tool result. See [Add context for Claude](#add-context-for-claude) |
20922087
20932088When multiple PreToolUse hooks return different decisions, precedence is `deny` > `defer` > `ask` > `allow`.
20942089
from line 2610
26152610| :- | :- |
26162611| `reason` | The denial reason |
26172612
2618When you log denials, expect text such as the following in `reason`:
2613When you log denials, you see text such as the following in the `reason` field:
26192614
26202615* **Classifier verdict**: in most sessions, the matched [policy](https://code.claude.com/docs/en/auto-mode-config.md#fix-a-policy-denial) or rule in square brackets, such as `[Destructive or Unwanted Actions]`. See [Review denials](https://code.claude.com/docs/en/auto-mode-config.md#review-denials) for the other forms.
26212616* **[No verdict from the classifier](#permissiondenied-decision-control)**: starts with `Auto mode could not evaluate this action and is blocking it for safety`
from line 2666
26712666>
26722667> The `permission_prompt`, `idle_prompt`, `elicitation_dialog`, and `elicitation_url_dialog` types share their timing with desktop notifications, so in terminal sessions you only see them when you appear to be away from the terminal:
26732668>
2674> * Expect `permission_prompt` once you haven't typed for about six seconds. The timer starts when the permission prompt appears, and each keystroke defers it. To run a hook immediately when Claude asks for permission to use a tool, use [PermissionRequest](#permissionrequest) instead.
2675> * Expect `idle_prompt` about 60 seconds after Claude finishes responding, and only if you haven't typed since and no background agent, such as a background [subagent](https://code.claude.com/docs/en/sub-agents.md), is still running. Claude Code doesn't send `idle_prompt` while it waits for a claude.ai usage limit to reset. When the wait ends on its own, one of the `quota_auto_resume_*` types fires instead.
2676> * Expect `elicitation_dialog` for an elicitation form, or `elicitation_url_dialog` for a browser URL request, once you haven't typed for about six seconds.
2669> * `permission_prompt` fires once you haven't typed for about six seconds. The timer starts when the permission prompt appears, and each keystroke defers it. To run a hook immediately when Claude asks for permission to use a tool, use [PermissionRequest](#permissionrequest) instead.
2670> * `idle_prompt` fires about 60 seconds after Claude finishes responding, and only if you haven't typed since and no background agent, such as a background [subagent](https://code.claude.com/docs/en/sub-agents.md), is still running. Claude Code doesn't send `idle_prompt` while it waits for a claude.ai usage limit to reset. When the wait ends on its own, one of the `quota_auto_resume_*` types fires instead.
2671> * `elicitation_dialog` fires for an elicitation form, or `elicitation_url_dialog` for a browser URL request, once you haven't typed for about six seconds.
26772672>
26782673> A permission request or elicitation that arrives while another dialog is on screen keeps the same six-second timing, timed from when the request arrives. Its notification can reach you while the request still waits behind the open dialog.
26792674
26802675Claude Code times `permission_prompt` differently in sessions where it sends permission requests to the Agent SDK's [`canUseTool` callback](https://code.claude.com/docs/en/agent-sdk/user-input), which is how Claude Desktop and the VS Code extension host Claude Code:
26812676
2682* Expect `permission_prompt` about six seconds after Claude asks for permission. Claude Code doesn't defer it while you type.
2677* `permission_prompt` fires about six seconds after Claude asks for permission. Claude Code doesn't defer it while you type.
26832678* If you or a [PermissionRequest](#permissionrequest) hook answer sooner, Claude Code doesn't run `permission_prompt`.
26842679* Set [`CLAUDE_CODE_DISABLE_PERMISSION_PROMPT_NOTIFY_HOOKS`](https://code.claude.com/docs/en/env-vars) to `1` to turn `permission_prompt` off in these sessions.
26852680
from line 2825
28302825 "transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
28312826 "cwd": "/Users/...",
28322827 "hook_event_name": "TaskCreated",
2833 "task_id": "task-001",
2828 "task_id": "1",
28342829 "task_subject": "Implement user authentication",
28352830 "task_description": "Add login and signup endpoints",
28362831 "teammate_name": "implementer",
from line 2881
28862881 "cwd": "/Users/...",
28872882 "permission_mode": "default",
28882883 "hook_event_name": "TaskCompleted",
2889 "task_id": "task-001",
2884 "task_id": "1",
28902885 "task_subject": "Implement user authentication",
28912886 "task_description": "Add login and signup endpoints",
28922887 "teammate_name": "implementer",
from line 3258
32633258
32643259DirectoryAdded hooks have no decision control. They can't block the add, which has already completed when the hook runs. Claude Code discards the `continue` field from their JSON output and surfaces the rest differently per source:
32653260
3266* `slash_command`: Claude Code delivers the hook's `systemMessage` to Claude as context on the next conversation turn, rather than showing it to you. A count of failed hooks appears in the transcript. Full failure output goes to the debug log
3261* `slash_command`: if a hook returns a `systemMessage` value or fails, Claude reads that value and the failure count, then replies without waiting for your next prompt. You see only the reply. Full failure output goes to the debug log
32673262* `register_repo_root`: Claude Code writes `systemMessage` output and failure output to the debug log only
32683263
32693264### FileChanged
from line 3638
36433638| `prompt_cache_warm` | boolean | Whether the current model's prompt cache is likely still warm, meaning the switch forfeits it |
36443639| `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"` |
36453640| `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 |
3646| `pricing` | string | How Claude Code priced `estimated_cache_write_usd`: `"configured"` at your organization's own rates when it has configured them, `"catalog"` at list price, or `"
3641| `pricing` | string | How Claude Code priced `estimated_cache_write_usd`: `"configured"` at your organization's own rates when it has configured them, `"catalog"` at list price, or `"default"` when `to_model` has no known price and Claude Code assumed a default rate |
3642
3643This example shows the input for `/model opus` in a session running Sonnet 5:
3644
3645```json theme={null}
3646{
3647 "session_id": "abc123",
3648 "transcript_path": "/Users/.../.claude/projects/.../00893aaf-19fa-41d2-8238-13269b9b3ca0.jsonl",
3649 "cwd": "/Users/...",
3650 "hook_event_name": "PreModelSwitch",
3651 "from_model": "claude-sonnet-5",
3652 "to_model": "claude-opus-5",
3653 "requested_model": "opus",
3654 "source": "command",
3655 "context_tokens": 182340,
3656 "prompt_cache_warm": true,
3657 "cache_ttl": "5m",
3658 "estimated_cache_write_usd": 1.1396,
3659 "pricing": "catalog"
3660}
3661```
3662
3663#### PreModelSwitch decision control
3664
3665`PreModelSwitch` hooks can cancel the switch, ask the user to confirm it, or let it proceed. Exit code 2 or a top-level `decision: "block"` cancels the switch.
3666
3667For finer c
No line in this hunk matches that.