Claude Code 2.1.251: hooks for model switches
Most releases add something to the interface. This one adds something to the seams: the moment a session changes model, and the moment a stale conversation is resumed. Both are places where a team's policy has an opinion: before this release no hook could act on the model switch at all, and a hook on resume had no way to know what the resume would cost.
Below: what each event sees, when it does and does not run, the matcher trap worth knowing before you write one, and the rest of the release.
Last checked against Anthropic's changelog entry for 2.1.251 and its documentation on November 25, 2026. By the Omniscio team. Updated .
Hooks that see a model switch
PreModelSwitch runs before Claude Code applies a model switch that you or a client requested, and it can block the switch, require confirmation, or let the switch through while showing what it will cost. That confirmation has a catch: only /model in an interactive session can show the prompt. On every other surface — non-interactive -p, /config, and set_model requests — Claude Code treats an "ask" decision as a refusal. Anthropic lists the requests it runs for: /model and the /model picker, the Option+P or Alt+P picker, the Model setting in /config, turning on fast mode when that changes the session's model, and a set_model request, or a model change in an apply_flag_settings request, from an Agent SDK host or Remote Control.
Just as important is what it does not cover. Claude Code does not run PreModelSwitch for switches it makes on its own, such as an automatic model fallback or restoring the model when you resume a session; those reach PostModelSwitch only. A policy built on the blocking event, then, governs what people choose, not what the program does to recover. How a hook says no has the mechanics and a settings example.
PostModelSwitch is the other half: it runs after the session's model has changed, as an async event, which makes it the place to record a switch rather than to refuse one. Both events need Claude Code v2.1.251 or later.
The hooks guide covers where a hook lives and how a blocking event differs from a notice.
Sources: the "Added `PreModelSwitch` and `PostModelSwitch` hook events" line in the 2.1.251 entry of Claude Code changelog, and the PreModelSwitch section and hook-event table in Hooks reference, read November 25, 2026.
The matcher trap
A hook on this event matches against the canonical name of the model the session is switching to, ignoring any [1m] suffix — the marker that asks for the 1M-token context window. That is what makes an alias, a dated model id and a provider-specific Bedrock id all match the one name they resolve to, so claude-opus-5 covers every spelling of Opus 5.
The trap is the case where no canonical name can be worked out, for example a custom model id that only your LLM gateway knows. Claude Code then runs every PreModelSwitch hook regardless of matcher. Anthropic's advice follows directly: a hook that blocks should read to_model from its input rather than rely on the matcher alone.
Matchers can be an exact name, a |-separated list such as claude-opus-4-6|claude-opus-5, or a regular expression such as .*opus.*. To block, a command hook exits with code 2, which is the same refusal mechanism other blocking events use.
Source: the PreModelSwitch section of Hooks reference, read November 25, 2026.
How a hook says no
Three ways, and they are the same ones other blocking events use. Exit code 2, or a top-level decision: "block", cancels the switch. For finer control, return permissionDecision and permissionDecisionReason inside a hookSpecificOutput object, with "allow", "deny" or "ask" as the decision.
The hook sits in a settings file like any other, under an event name and a matcher:
{
"hooks": {
"PreModelSwitch": [
{ "matcher": "claude-opus-4-6",
"hooks": [ { "type": "command", "command": ".claude/hooks/block-opus-46.sh" } ] }
]
}
}Its input is where the detail lives. Alongside the common fields it receives from_model, to_model, requested_model and source (where the request came from), and the cost fields that make the "show the cost" idea work: context_tokens, prompt_cache_warm, cache_ttl, estimated_cache_write_usd, and pricing, which says whether that estimate used your organization's configured rates, list price, or a default.
To check one, Anthropic suggests running /model claude-opus-4-6 from a session on a different model: Claude Code keeps the current model and reports that a hook blocked the switch, with your message as the reason.
Deployment is the part teams ask about next. A hook in a project's .claude/settings.json travels with the repository; a managed settings file reaches every machine whether or not the developer opts in. Managed settings covers that delivery, and the settings file guide covers where the project file lives.
Source: "PreModelSwitch decision control", "PreModelSwitch input" and the settings example in the PreModelSwitch section of Hooks reference, read November 25, 2026.
What resuming a stale session costs
Resuming yesterday's conversation is not free: the first request re-sends the context, and if the prompt cache has expired, that context is written to the cache again rather than read from it. 2.1.251 gives a SessionStart hook the numbers before that happens.
When source is "resume" or "fork" and the transcript holds at least one response from Claude, the hook also receives four fields: seconds_since_last_response, context_tokens, prompt_cache_likely_expired, and estimated_cache_write_usd. Anthropic suggests reporting that cost, for example in a systemMessage shown before the first request goes out.
Those fields need v2.1.251 or later, so an older hook receives the event without them. The hooks guide covers SessionStart, and the prompt cache guide covers how cache lifetime decides whether a resume is cheap.
Sources: the "Added `PreModelSwitch` and `PostModelSwitch` hook events… `SessionStart` resume hooks now receive session staleness and the estimated re-cache cost" line in the 2.1.251 entry of Claude Code changelog, and the "SessionStart input" table in Hooks reference, read November 25, 2026.
Live subagent detail in Remote Control
Remote Control clients now get a foreground subagent's tool calls and results as they happen, rather than a status line. Background subagents — which Anthropic notes are the default — still show status only.
In practice that decides where you can watch work from. A subagent you started in the foreground is now legible from another device; one running in the background is not. The Remote Control guide covers the connection, and subagents covers foreground against background.
Source: the "Added live streaming of a foreground subagent's tool calls and results to Remote Control clients" line in the 2.1.251 entry of Claude Code changelog, read November 25, 2026.
The smaller changes worth knowing
- A cache line in
/cost. A per-session prompt-cache line now shows the hit ratio, misses, tokens re-cached and whether the cache is warm or cold, and status line scripts get a matchingprompt_cacheobject. See the cost guide and the prompt cache guide. - Effort is saved per model.
/effortnow saves your default effort level per model, so each model keeps its own setting when you switch. See effort levels. - A spend limit bar.
/usagegains a spend limit bar, and the status line arate_limits.spend_limitfield, for developers behind a Claude apps gateway that sets spend limits. See usage limits. - Subagent model default.
CLAUDE_CODE_SUBAGENT_MODELnow sets the default subagent model instead of overriding everything: an agent definition'smodel:and an explicit per-spawn model take precedence. - Sandbox settings need approval. Server-managed settings that terminate sandbox TLS, route sandbox traffic through your own proxy, inject credentials or weaken sandbox isolation now require approval before they apply, and so does an
ANTHROPIC_CUSTOM_HEADERSset from managed or project settings that names a credential, org or tenant, routing, or API-behaviour header. See the sandbox guide. - Project settings lost some env keys. A project-level
.claude/settings.jsoncan no longer setCLAUDE_CONFIG_DIR,CLAUDE_CODE_TMPDIRorTMPDIR/TMP/TEMP; set them in your shell, user or managed settings. - Smaller binary. Syntax highlighting is gone for six rarely used languages (1c, gml, isbl, mathematica, maxima, sqf), which Anthropic says makes the binary 2.5 MB smaller.
Sources: the "Added a per-session prompt-cache line", "Changed `/effort` to save your default effort level per model", "Added a Spend limit bar", "Changed `CLAUDE_CODE_SUBAGENT_MODEL`", "Changed server-managed settings", "Changed `ANTHROPIC_CUSTOM_HEADERS`", "Changed project-level `.claude/settings.json` `env`" and "Removed syntax highlighting for six rarely used languages" lines in the 2.1.251 entry of Claude Code changelog, read November 25, 2026.
What got fixed
The entry's bug-fix list holds 41 items, and several of them are security fixes worth reading even if you skip the rest:
- A symlink swapped after the permission check. Read, Write and Edit followed a symlink swapped inside the working directory after the permission check, which could reach outside the approved location.
- Plugin paths out of the directory. Plugin commands declared in a marketplace entry could point outside the plugin directory; those paths are now rejected as path traversal.
- Grep and Glob and deny rules. They did not apply
Read(...)deny rules to files reached through a symlinked search path. - A turn that produced only thinking. Conversations could get stuck on "text content blocks must be non-empty" errors after a turn where the model produced only thinking.
- A teammate's answer that never arrived. In agent teams, a teammate's final answer did not reach the team lead, which got a content-free "available" notice instead.
Sources: the "Fixed" lines under "41 bug fixes" in the 2.1.251 entry of Claude Code changelog, read November 25, 2026.
Who 2.1.251 matters to
| If you… | Read this part |
|---|---|
| Write hooks, or run a team with a policy about which model may be used | Hooks that see a model switch, then the matcher trap |
| Resume long sessions and wonder what they cost | What resuming a stale session costs |
| Watch sessions from another device | Live subagent detail |
| Track spend, or set effort per model | The smaller changes |
If none of those is you, this is a fixes release with several security fixes in it, and updating is the whole action.
If you are not on this version yet, claude --version prints the version you have and claude update updates the install; the update guide covers each install type. Newer releases exist: Anthropic's changelog lists them.
This table is our summary of the sections above; every row rests on the changelog and documentation lines cited in those sections, read November 25, 2026.
Where these answers come from
- The release, its date and every change listed: the 2.1.251 entry in Claude Code changelog, generated from CHANGELOG.md, read November 25, 2026.
- When the model-switch hooks run, how their matcher is evaluated, and the resume fields: Hooks reference, read the same day.
claude updateandclaude --version: CLI reference, read the same day.
No Claude Code release was installed on this site's machine to check this page. Every claim about 2.1.251 is taken from Anthropic's changelog entry and the documentation pages named above.
Common questions
What is PreModelSwitch in Claude Code?
A hook event that runs before Claude Code applies a model switch you or a client requested, and can block it or require confirmation. It needs Claude Code v2.1.251 or later and runs for /model, the model picker, the Model setting in /config, fast mode when it changes the model, and set_model requests, or a model change in an apply_flag_settings request, from an SDK host or Remote Control.
Does PreModelSwitch run for automatic model fallbacks?
No. Claude Code does not run PreModelSwitch for switches it makes on its own, such as an automatic fallback or restoring a model when you resume a session. Those changes reach PostModelSwitch only.
What do the new SessionStart fields tell me?
When a session is resumed or forked and the transcript holds a response, SessionStart hooks receive seconds since the last response, the context tokens the first request re-sends, whether the prompt cache probably expired, and the estimated cost of writing that context back to the cache.
Does Remote Control show subagent work now?
Yes, for a foreground subagent: its tool calls and results stream live to Remote Control clients as of 2.1.251. Background subagents, which are the default, still show status only.