Follow Discord
Sweep 03 Dec 2026 · 19:13Z Build v2.1.336 553 read Stable v2.1.332 Latest v2.1.336 Next v2.1.336 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · claude-code

Hooks reference changedhooks

Nearest release: v2.1.335, published 8 hours before 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 3 Dec 2026 06:13 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 3 Dec 2026 06:37 UTC.

Upstream edited
Recorded here
Lines+31added
Lines−23removed
From line 711 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 711, old and new numbered
/
lines

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 711
711711 * **Fix**: move the skill into a [plugin](https://code.claude.com/docs/en/plugins/create.md#convert-an-existing-claude-setup), because plugin skills keep their frontmatter hooks. List the plugin in a [marketplace](https://code.claude.com/docs/en/plugins/create-marketplace.md#create-a-marketplace), then install it from there. If Claude Code refuses the marketplace with [`is blocked by enterprise policy`](https://code.claude.com/docs/en/plugins/troubleshooting#marketplace-source-is-blocked-by-enterprise-policy), ask your administrator to allow that marketplace.
712712* **Hook limit**: in Claude Code v2.1.304 or later, each source of skills has its own limit per session. Your project, your personal skills folder, and each plugin count as separate sources. The skills from one source can register at most 1,024 hooks. Those hooks' matchers can total at most 16,384 characters. A matcher with several hooks under it counts once for each hook.
713713 * **Check**: repeat the session where the hook didn't fire, with debug logging on:
714 1. Start a new session from your shell with `claude --debug`. If you don't start sessions from a shell, type [`/debug`](https://code.claude.com/docs/en/commands#all-commands) first in the new session instead.
714 1. Start a new session from your shell with `claude --debug`. In the Desktop app, type [`/debug`](https://code.claude.com/docs/en/commands#all-commands) first in a new local session instead.
715715 2. Invoke the same skills in the same order, including the ones Claude invoked, because both totals build up skill by skill. Ask Claude to invoke any skill you can't type as a command.
716716 3. Search the [debug log](#debug-hooks) for `registers none of its hooks`. A line containing that text names the skill that went past the limit.
717717 * **Fix**: declare fewer hooks or shorter matchers in that skill or in the other skills from its source, then start a new session. If those skills aren't yours to edit, ask their author for that change. Until then, start a new session and invoke the skill you need before any other skill from its source.
from line 802
802802 
803803* **Success**: your hook exits 0. Claude Code applies any [JSON output](#json-output) fields your hook printed, and the action goes ahead unless those fields block or deny it. [Hooks that start a background process](#hooks-that-start-a-background-process) covers the exception.
804804* **Blocking error**: your hook exits 2. On [events that can block](#exit-code-2-behavior-per-event), Claude Code stops the action.
805* **Non-blocking error**: your hook exits with any other code, or fails in some other way, such as not starting or printing invalid JSON. The action goes ahead, except for hooks [whose failure blocks the action](#block-the-action-when-a-hook-fails), for example a hook with `onFailure` set to `"block"`. On events such as `PreToolUse`, you see a `<hook name> hook error` notice in the transcript.
805* **Non-blocking error**: your hook exits with any other code, or fails in some other way, such as failing to start or printing invalid JSON. The action proceeds unless the hook is one [whose failure blocks the action](#block-the-action-when-a-hook-fails), such as a hook with its `onFailure` field set to `"block"`. When a `PreToolUse` hook fails and the call proceeds, look for a `<hook name> hook failed` notice in the terminal transcript.
806806 
807What your hook prints to stdout can change the outcome. For example, when a `PreToolUse` hook exits 1 but prints JSON that passes validation, that JSON can still decide what happens. To find your hook's outcome on an event such as `PreToolUse`, match what it printed to stdout in the first column with its exit code along the top:
807What your hook prints to stdout can change the outcome. For example, when a `PreToolUse` hook exits 1 but prints JSON that passes validation, that JSON can still decide what happens.
808808 
809The following table shows the outcome on an event such as `PreToolUse` for each combination of stdout and exit code:
810 
809811| Stdout | Exit 0 | Exit 2 | Any other exit code |
810812| :- | :- | :- | :- |
811813| JSON object that passes [schema validation](#json-output) | Success. The fields apply | Blocking error. Claude Code still reads the fields, but a `PreToolUse` call stays blocked even if you return `"allow"` or `continue: false`. For other events, see [Exit code 2](#exit-code-2) | Success. Claude Code ignores the exit code, and the fields alone decide. For hooks [whose failure blocks the action](#block-the-action-when-a-hook-fails), the run counts as a failure instead |
from line 828
826828 
827829Exit 0 means success, and is the intended exit code when you print JSON for structured control. When your hook exits 0 but prints JSON that can't be parsed or fails [schema validation](#json-output), the action goes ahead unless the hook is one [whose failure blocks the action](#block-the-action-when-a-hook-fails). Instead of a success with your fields applied, the run is a [non-blocking error](#exit-code-output).
828830 
829If a `<hook name> hook error` notice carries a parse or validation message, use it to fix your output. For a hook that isn't [async](#how-async-hooks-execute), your stdout counts as [JSON output](#json-output) only when you print one JSON object, on one line or several, with nothing around it but whitespace. Claude Code reads any other stdout as plain text or a parse failure:
831If you see a parse or validation message under a `<hook name> hook failed` notice, use it to fix your output. For a hook that isn't [async](#how-async-hooks-execute), your stdout counts as [JSON output](#json-output) only when you print one JSON object, on one line or several, with nothing around it but whitespace. Claude Code reads any other stdout as plain text or a parse failure:
830832 
831833* **Output that doesn't start with `{`, or that starts with `{` and doesn't end with `}`**: plain text. A JSON array and a quoted JSON string are plain text by this rule.
832834* **Two or more lines that each parse as JSON on their own, the first starting with `{` and the last ending with `}`**: plain text when no line is a JSON output object that sets a field. When one line is, the output is a parse failure, so print that object with nothing else on stdout.
from line 877
875877 
876878#### Other exit codes
877879 
878A `<hook name> hook error` notice with `Failed with non-blocking status code:` means your hook didn't exit 0 or 2 and its stdout was plain text or empty. The run is a [non-blocking error](#exit-code-output), so your hook didn't stop the action. If the notice cuts off your stderr, turn on debug logging as [Debug hooks](#debug-hooks) describes and rerun the hook.
880If you see a `PreToolUse:<tool> hook failed` notice with your hook's stderr under it, your hook didn't stop the call.
879881 
880For example, when a `PreToolUse` hook on `Bash` prints `something broke` to stderr and exits 1, the `PreToolUse:Bash hook error` notice carries this line:
882For example, a `PreToolUse` hook on `Bash` that prints `something broke` to stderr and exits with code 1 leaves this line under the `PreToolUse:Bash hook failed` notice:
881883 
882884```text theme={null}
883Failed with non-blocking status code: something broke
885something broke
884886```
885887 
886If the notice carries the shell's `No such file or directory` message, as in the following line, the hook never ran, for example because its script path doesn't exist:
888To read the rest of a cut-off stderr message, turn on [debug logging](#debug-hooks) and rerun the hook.
887889 
890The shell's `No such file or directory` message for your script's path means the hook didn't run:
891 
888892```text theme={null}
889Failed with non-blocking status code: /bin/sh: /path/to/hook.sh: No such file or directory
893/bin/sh: /path/to/hook.sh: No such file or directory
890894```
891895 
892If the path is wrong, correct it where the hook is configured. In shell form, when the script path doesn't exist or isn't executable, the shell exits with a code like 127 and the notice carries the interpreter's message. Unless the hook is one [whose failure blocks the action](#block-the-action-when-a-hook-fails), a hook that can't start is a non-blocking error too.
896Check the script path in the hook's configuration.
893897 
894When you set up a policy hook, watch for this notice on its first run, because a mistyped path in `settings.json` means the hook never runs. To block the action when the hook can't start, set [`onFailure: "block"`](#block-the-action-when-a-hook-fails).
898The first time a hook that enforces a policy runs, watch for the `hook failed` notice. To block the action when the hook can't start, set [`onFailure: "block"`](#block-the-action-when-a-hook-fails).
895899 
896900> [!WARNING]
897901>
898> Exit code 1 without valid JSON output is a non-blocking error unless the hook is one [whose failure blocks the action](#block-the-action-when-a-hook-fails), even though 1 is the conventional Unix failure code. If your hook is meant to enforce a policy, use `exit 2`.
902> Exit code 1 without valid JSON output is a non-blocking error unless the hook is one [whose failure blocks the action](#block-the-action-when-a-hook-fails). To enforce a policy, use `exit 2`.
899903 
900904#### Timeouts
901905 
from line 1070
10661070| `InstructionsLoaded` | No | Exit code is ignored |
10671071| `MessageDisplay` | No | The original text is displayed |
10681072 
1069For `SessionStart`, `SubagentStart`, and `PostModelSwitch`, Claude Code renders the exit code 2 stderr in the transcript as a `<hook name> hook error` notice, the same way it renders a [non-blocking error](#exit-code-output). Claude doesn't see it, and the session or subagent proceeds. For `SubagentStart`, the notice appears in the subagent's own transcript, not in the parent conversation.
1073If a `SessionStart`, `SubagentStart`, or `PostModelSwitch` hook exits with code 2, the session or subagent proceeds. You see the stderr under a `<hook name> hook failed` notice in the terminal transcript. For a `SubagentStart` hook, look in the subagent's transcript.
10701074 
10711075### HTTP response handling
10721076 
from line 1207
12031207 
12041208#### Decision control
12051209 
1206Not every event supports blocking or controlling behavior through JSON. The events that do each use a different set of fields to express that decision. Use this table as a quick reference before writing a hook:
1210Not every event supports blocking or controlling behavior through JSON. The events that do each use a different set of fields to express that decision.
12071211 
1212This table shows the decision pattern and key fields for each group of events:
1213 
12081214| Events | Decision pattern | Key fields |
12091215| :- | :- | :- |
12101216| UserPromptSubmit, UserPromptExpansion, PostToolUse, PostToolUseFailure, PostToolBatch, Stop, SubagentStop, ConfigChange, PreCompact | Top-level `decision` | `decision: "block"`, `reason`. Stop and SubagentStop also accept `hookSpecificOutput.additionalContext` for [non-error feedback that continues the conversation](#stop-decision-control) |
from line 3011
30053011| :- | :- |
30063012| `decision` | `"block"` prevents Claude from stopping. Omit to allow Claude to stop |
30073013| `reason` | Required when `decision` is `"block"`. Tells Claude why it should continue |
3008| `hookSpecificOutput.additionalContext` | Non-error feedback for Claude. The conversation continues so Claude can act on it, but unlike `decision: "block"` it is shown in the transcript as hook feedback rather than a hook error |
3014| `hookSpecificOutput.additionalContext` | Non-error feedback for Claude. The conversation continues so Claude can act on it |
30093015 
30103016A hook that blocks by exiting 2 routes the same way as `reason`: Claude receives the stderr message as the explanation for why it should continue.
30113017 
from line 3022
30163022}
30173023```
30183024 
3019Use `additionalContext` when the hook is working as designed and giving Claude guidance, such as "run the test suite before finishing". It keeps the conversation going through the same loop protections as `decision: "block"`, namely the `stop_hook_active` input and the 8-consecutive-continuation cap, but the transcript labels it `Stop hook feedback` and no hook error notification is shown:
3025To give Claude one more instruction before it stops, such as running the tests, return the instruction in the `additionalContext` field. Claude keeps working and receives your text.
30203026 
3027When your `Stop` hook returns the following JSON, you see `Stop hook says: Please run the test suite before finishing` in the terminal transcript:
3028 
30213029```json theme={null}
30223030{
30233031 "hookSpecificOutput": {
from line 3671
36633671 
36643672#### PreModelSwitch decision control
36653673 
3666`PreModelSwitch` hooks can cancel the switch, ask the user to confirm it, or let it proceed. Exit code 2 o
3674`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.
3675 
3676For finer control, return `permissionDecision` and `permissionDecisionReason` in a `hookSpecificOutput` object, as on [PreToolUse](#pretooluse-decision-control). `PreModelSwitch` accepts `"allow"`, `"deny"`, and `"ask"`. It doesn't accept `"defer"`, `updatedInput`, or `additionalContext`. The table below describes both fields:
3677 
3678| Field | Description |
3679| :- | :- |
3680| `permissionDecision` | `"allow"` proceeds and skips the [confirmation Claude Code shows while the prompt cache is warm](https://code.claude.com/docs/en/prompt-caching.md#switching-models). `"deny"` cancels the switch. `"ask"` prompts the user to confirm it |
3681| `permissionDecisionReason` | For `"deny"`, shown to the user as the reason the switch was blocked, or returned as the error for a `set_model` request. For `"ask"`, shown in the confirmation prompt. Ignored for `"allow"` |
3682 
3683Only `/model` in an interactive session can show the `"ask"` prompt. On every
Feedback