r/ClaudeCode • • 6h ago

Built with Claude I built a Claude Code plugin that picks model and effort per turn. The prompt cache math was the interesting part

Post image

Disclosure: this is my project. Free, MIT, no referral links. Hosted classifiers need your own API key (their pricing applies), or you can run one locally with Ollama.

What it is

Claude Model Router is for sessions with mixed work: a quick search, a small edit, a bug that only fails in CI, a design question. Instead of switching /model by hand:

  • a small classifier rates each prompt: how hard it is, and what kind (code, debug, explore, plan, review, ops, docs)
  • local rules pick model and effort (Haiku, Sonnet or Opus on the default profile)
  • /router mode cost|balanced|quality, or start a prompt with maxthink / lessthink for one turn
  • a failing model is held out, and turns go to another one until it recovers

A line above the prompt shows what ran and why, and /router decisions has the history. For example:

▂▄▆█ Opus 5.5 · xhigh   debug   ↑ clearly stronger   balanced

Optional and separate: claude-proxy lets the same session use other providers (API-key models, or GPT on your ChatGPT plan). Anthropic doesn't support non-Claude models in Claude Code, so treat that part as unofficial. The router itself is not a proxy.

How I built it with Claude Code

  • AGENTS.md holds the rules that most often break a build or a review, such as "no engine API newer than the minimum version", so every session starts with them
  • bigger features start as a design doc in docs/plans/. UI changes start as two or three HTML prototypes, and I pick one before any code
  • each feature gets its own git worktree, so main stays as released
  • for live checks, one Claude Code session drives another in a real terminal, typing prompts and reading the screen
  • about 1,800 tests, and CI also loads the plugin into the real Claude Code engine at the minimum supported version, which catches things unit tests miss
  • a six-agent review of 1.33.0 (new user, power user, routing scientist, architect, strategist, reliability) agreed on one thing: I model cost to the cent and haven't measured quality. It also found safety gaps. Two are fixed in 1.33.1, one is still open (no redaction)

What I learned

  1. Switching models is not free. Setup: about 350K tokens of context, list prices per million tokens (Opus 5.5 $4 in, $20 out, $0.20 cached read; Sonnet 5.5 half of each), 1-hour cache writes at 2x input, about 3K output tokens per request. Moving Opus → Sonnet saves about $0.07 a request but costs about $1.40 to write the new cache, so about 22 requests to pay back. Haiku pays back after about 4. In the sessions I replayed, command runs lasted 6 to 11 requests at the median and Q&A runs 1 to 3, so the Sonnet move rarely pays. The router weighs this before moving down.
  2. Effort changes mostly keep the cache. In 30 days of my transcripts (main thread, under 270 s between requests, mostly Opus and Haiku), 102 of 104 same-model effort changes still read it. Observational, not a controlled test.
  3. If you write mods: store calls run one at a time and each reads the whole store file. At 4.9 MB (about 3,000 keys) my session start took 28 s. After reworking the reads it took under 0.6 s. One measurement each.

What to know first

  • answer quality is not benchmarked
  • no savings promise: it can cost more than staying on one cheap model
  • the classifier gets your prompt, recent dialogue and routed subagent tasks, unredacted, unless it runs locally
  • the auto routing engine is opt-in and experimental

Try it (Claude Code 2.1.332 or newer)

claude plugin marketplace add alexei-led/claude-router
claude plugin install router@alexei-led-claude-router

Then run /plugin configure router.

Repo: https://github.com/alexei-led/claude-router

Do you switch models mid-session, or start a new one? If you've measured what a /model switch costs you in cache, I'd like to compare numbers.

0 Upvotes

3 comments sorted by

•

u/AutoModerator 6h ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/EndlessZone123 5h ago

I never see a reason to change models during one chat.

Either select the right model and effort as a subagent for a specific task with a more orchestrator setup.

Or only change the effort level between low medium and high.

The model used is typically smart enough to figure out what difficulty a task is with a simple system prompt to guide tasks to model and effort presets for subagents.

1

u/alexei_led 3h ago

unless you hit capacity, price or performance limits. Or some models better suited for specific activity types. I build claude router for these cases and use it daily.

if you can allow to use one model for all - choose Opus and no need to change effort either (unless you want a faster reply)