◉CLAUDE LABJP
●2.1.334 — Claude Code 2.1.334: /model now has a search box once the list passes 25 models, matching names and model IDs●FAST — Fast mode for Claude Opus 4.8 ended on 11/30. Drop speed: "fast" and Opus 4.8 keeps working●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 50 days from now. The replacement is claude-opus-5-5●IME — On the Windows desktop app, pressing Enter to confirm Japanese IME input can send the message early●NEW — New: Compare tool-use requests across three routes before moving to Bedrock●MCP — More setups now share one local MCP server across Claude Code, Cursor and Antigravity●2.1.334 — Claude Code 2.1.334: /model now has a search box once the list passes 25 models, matching names and model IDs●FAST — Fast mode for Claude Opus 4.8 ended on 11/30. Drop speed: "fast" and Opus 4.8 keeps working●OPUS 4.5 — claude-opus-4-5 retires on 2027/1/22, 50 days from now. The replacement is claude-opus-5-5●IME — On the Windows desktop app, pressing Enter to confirm Japanese IME input can send the message early●NEW — New: Compare tool-use requests across three routes before moving to Bedrock●MCP — More setups now share one local MCP server across Claude Code, Cursor and Antigravity
Articles/Claude Code
⟐ Claude Code/2026-09-02Intermediate

Two hooks that record every model switch and stop the ones you never agreed to

Build a PostModelSwitch hook that logs every model change and a PreModelSwitch hook that blocks unapproved switches during unattended runs. Complete scripts, measured timings, and the reason the two jobs must stay separate.

Claude Code296hooks23PreModelSwitchPostModelSwitchautomation110

✦ Premium Article

Last week my weekly usage on a set of unattended scheduled runs came in higher than I expected, so I went looking for the breakdown. My logs had the outcome of every run and the artifacts it produced. What they did not have, anywhere, was a record of when the session changed models.

As an indie developer running routine work on scheduled automation, splitting work across models is the obvious design. Formatting and search-and-replace go to something light; rewriting prose goes to something heavier. The problem was that this split existed as an intention, not as an observation. I had never once written down what actually happened.

Claude Code v2.1.251 added two hook events for exactly this: PreModelSwitch and PostModelSwitch. We are going to build a recorder and a guard — as two separate hooks, on two separate events. The separation is the interesting part, so let's start there.

A usage total cannot be decomposed after the fact

The Claude Code weekly limit is a shared pool across models. The status line JSON exposes rate_limits.seven_day alongside seven_day_opus and seven_day_sonnet, which tells you the pool carries per-model sub-buckets inside a single ceiling.

Practically, that means any run that used a heavier model than intended has already eaten into the room left for everything else. On September 14, 2026 the weekly limit settled permanently at +25% over the pre-promotion baseline. That is lower than the +50% the promotion had been giving, so re-measuring how the allocation actually behaves matters more now, not less.

Re-measuring needs data. Checking /usage afterwards gives you a total, not an attribution. Some information exists only at the instant the switch happens, so the recorder has to be in place first.

What the two events hand you

PreModelSwitch fires immediately before a switch. PostModelSwitch fires after the session's model has changed. Where other hooks receive things like tool_name, these two receive fields that describe the switch itself.

FieldTypeMeaning
from_modelstringModel in use before the switch
to_modelstringModel being switched to
requested_modelstring | nullThe explicitly requested model; null when the switch was automatic
source"command" | "picker" | "sdk"How the switch was triggered: the /model command, the interactive picker, or the SDK
context_tokensnumberContext size at that moment
prompt_cache_warmbooleanWhether the prompt cache is currently warm
cache_ttl"5m" | "1h"Cache lifetime in effect
estimated_cache_write_usdnumberEstimated cost of the cache write, in USD
pricing"configured" | "catalog" | "default"Which price table produced that estimate

The usual session_id, transcript_path, and cwd come along too. PostModelSwitch carries the same fields, but source can take more values there than on the Pre side. Because that list may grow from release to release, I do not enumerate it here; I check the official hooks reference before writing any branch on it (as of November 2026).

That source field is what lets you tell a human choosing a model at a picker apart from a switch that happened inside an unattended run. That distinction becomes the hinge for the guard.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦You will be able to explain, after the fact, which unattended run consumed which model instead of guessing from a single usage total
✦You will avoid the failure mode where a heavy step inside PreModelSwitch quietly stops model switching altogether
✦You will be able to fold the cache write cost reported by estimated_cache_write_usd into a switching decision you were making on per-token price alone
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-08-28
Don't let your verification script's full output flow back through a hook
The check was working the whole time. The conversation was what ran out of room. Measured side by side: 58 bytes from one scan of 833 files, 42KB from another. Which paths actually reach the model, and how to enforce a budget on them.
⟐ Claude Code2026-11-08
Before a Nightly Job Hangs on a Prompt: Designing Around denyInsteadOfPrompting
Claude Code 2.1.319 adds permissions.denyInsteadOfPrompting. Here is how it compares with other ways to answer permission prompts unattended, and how to catch what a denial quietly drops.
⟐ Claude Code2026-10-20
You Stepped Away and Came Back to a Summary — Spotting Idle Compaction and Keeping the Details You Can't Lose
Leave a long conversation for about an hour and Claude Code swaps it for a summary. Checked against the docs as of November 2026: when it runs (terminal, VS Code, the desktop Code tab), how to tell it happened, and how to choose between turning it off, moving the threshold, and keeping the details outside the conversation.