Claude Code model-switch hooks: gate the model mid-session
Claude Code 2.1.251 adds PreModelSwitch and PostModelSwitch hooks so a script can block or confirm a model change mid-session, plus spend and cache visibility.
Anthropic shipped Claude Code 2.1.251 on August 28 with model-switch hooks — PreModelSwitch and PostModelSwitch. A script can now block, confirm, or annotate a model change while a session is running. That sounds small. It is the first control that treats "which model is answering" as a governed event instead of a dropdown.
What actually happened
From the Claude Code changelog, 2.1.251 adds PreModelSwitch and PostModelSwitch hook events that block, confirm, or annotate a model switch. The same entry gives SessionStart resume hooks two new inputs: session staleness and the estimated re-cache cost of picking that session back up.
Cost visibility landed alongside it. /usage now shows a spend limit bar, with a matching rate_limits.spend_limit field for status line scripts behind a Claude apps gateway. /cost gained a per-session prompt-cache line — hit ratio, misses, tokens re-cached, warm or cold — exposed to status line scripts as a prompt_cache object.
Two other changes matter for anyone running fleets. CLAUDE_CODE_SUBAGENT_MODEL is now a default rather than an override: an agent definition's model: field and an explicit per-spawn model both win over it. And /effort saves a default effort level per model, so switching models no longer drags your effort setting along with it.
Why model governance matters for your business
Model choice is a cost decision your agents currently make unsupervised. A session that starts on a cheap model and quietly escalates is a budget line nobody approved. PreModelSwitch is where you put the rule — deny escalation in CI, require confirmation on a client repo, log every switch to your own audit trail.
It is also a compliance surface. If you told a client their data goes to one model tier, a mid-session switch breaks that promise silently. A hook that annotates every change gives you the record.
The re-cache cost number is the one to instrument. Resuming a stale session is not free — you pay to warm the prompt cache again. Now SessionStart resume hooks get that estimate as an input, so a script can decide: resume this one, start fresh on that one. Wire it into the prompt_cache status line fields and you can actually see where your token spend goes instead of guessing at month end.
Key takeaways
- Claude Code 2.1.251 (August 28, 2026) adds
PreModelSwitchandPostModelSwitchhooks - Hooks can block, confirm, or annotate a mid-session model change
SessionStartresume hooks now receive session staleness and estimated re-cache cost/usagegained a spend limit bar;/costgained a per-session prompt-cache lineCLAUDE_CODE_SUBAGENT_MODELis now a default, overridden by agent definitions and per-spawn models/effortstores a separate default per model
Most teams cannot answer "which model ran that job, and what did it cost?" We wire coding-agent fleets with hook-level policy and spend telemetry you own, not a vendor dashboard you rent. See how we build agent systems, or tell us what your agents are allowed to switch to.
Sources: Claude Code changelog.
- #claude-code
- #ai-agents
- #hooks
- #cost-control
- #dev-tools
Tommy Rush — Founder, Rush Commerce
Operator turned builder. 15+ years running operations — now shipping the systems businesses run on. More
Get The Rush Report weekly — one email, zero fluff.
Keep reading
Google Play personal apps: vibe-coded Android apps, no dev account
Google Play now runs private vibe-coded Android apps built in AI Studio, no developer account needed. Great for one-off tools; know where the line to a real app is.
Read itBricksforge CVE-2026-85097 exploited: WordPress RCE, update now
Bricksforge CVE-2026-85097 is a CVSS 10 unauthenticated upload-to-RCE flaw under active attack. Update to 3.1.8.10, then hunt for planted PHP files.
Read it