Route each task to the cheapest model that can do it
Send the grunt work to a cheap open model and keep the hard thinking on Claude, automatically, with one small local router.
Distilled from claude-code-router on GitHub.
The outcome
By the end you'll have a router that sends routine, high-volume work to a cheap model and the hard reasoning to a strong one, picking which is which on its own, so you stop overpaying for easy work and stop under-powering the hard work.
- The OpenRouter setup from the open-source-models guide, already working
- Node and npm on your machine (to install one command-line tool)
- An OpenRouter key, and about fifteen minutes
Pointing Claude Code at one open model is already a big saving, but it is a blunt instrument: the same model answers a one-line rename and a gnarly multi-file refactor, so you either overpay on the easy stuff or under-power the hard stuff. A router fixes that. It is a small program that runs on your own machine, sits between Claude Code and the models, looks at each request, sorts it into a tier (quick background task, everyday work, hard thinking, huge context), and forwards it to whichever model you put on that tier. It is the automatic version of the manual split from the open-source-models guide: cheap models for the grunt work, Claude for the thinking, decided for you, request by request.
1. Install the router
The router is one small command-line tool, installed once. It needs Node and npm, which most machines set up for modern tools already have (if npm is missing, install Node from nodejs.org first). The install gives you a new command called ccr, short for Claude Code Router. You do not point Claude Code at anything yet; that happens when you start it in step 3.
Install once. It adds a new command, ccr. If npm is unfamiliar, it ships with Node from nodejs.org. npm install -g @musistudio/claude-code-router # you now have the `ccr` command. You'll start it in step 3 with: ccr code2. Tell it your models and your routing
The router reads one file: ~/.claude-code-router/config.json. It has two parts. Providers is where models come from: a name you make up, the address, your key, the list of model ids you'll use, and a transformer line that reshapes requests for that provider (openrouter for OpenRouter). Router is the actual routing: each tier name points at one provider,model-id pair. The block below is the hybrid setup, a free model for throwaway background calls, GLM for everyday work, Claude for the hard thinking, and a long-context model for anything over the threshold. Swap the ids for whatever you like (copy exact ids from OpenRouter's models page), then save.
~/.claude-code-router/config.json. Background goes cheap, the hard tier stays on Claude. Your keys live here, so never commit this file. { "Providers": [ { "name": "openrouter", "api_base_url": "https://openrouter.ai/api/v1/chat/completions", "api_key": "sk-or-your-openrouter-key", "models": [ "z-ai/glm-5.2", "anthropic/claude-opus-4-8", "openai/gpt-oss-120b:free" ], "transformer": { "use": ["openrouter"] } } ], "Router": { "default": "openrouter,z-ai/glm-5.2", "background": "openrouter,openai/gpt-oss-120b:free", "think": "openrouter,anthropic/claude-opus-4-8", "longContext": "openrouter,z-ai/glm-5.2", "longContextThreshold": 60000 } }What each tier means, so you can tune the split
- background: the small automatic calls Claude Code fires constantly (summaries, titles, quick lookups) plus low-stakes grunt work. Put the cheapest model here; it runs the most.
- default: your everyday work, anything that doesn't match a more specific tier. A cheap-but-capable model like GLM 5.2 belongs here.
- think: hard reasoning and plan-mode work. This is the tier to keep on a strong model like Claude, even though it costs more, because it runs least and matters most.
- longContext: requests larger than longContextThreshold tokens (60000 above). Point it at a model that handles big context well.
- You override any of these for a single session with the /model command in step 5.
Routing the think tier to anthropic/claude-opus-4-8 still goes through OpenRouter, so it carries OpenRouter's small markup. If you'd rather pay Anthropic directly for that tier, you can add a second provider that points at your Claude account; see the repo for the exact shape.
3. Start Claude Code through the router
One command does it: ccr code starts the router (if it isn't already up) and opens a Claude Code session pointed at it. The router runs locally at 127.0.0.1:3456 and has to stay alive for routing to work, so leave it running. One thing trips everyone up: editing the config does not take effect live. After any change to the file, run ccr restart. The other commands are ccr start (run it in the background), ccr stop, ccr status, and ccr ui (a small web page for editing the config).
ccr code starts the router and launches Claude Code through it, in one step. Claude Code❯ ccr code
Router running on 127.0.0.1:3456
Claude Code · routing by task
# Leave it running. Edited the config? Run ccr restart, it does not reload on its own.
4. Use it in VS Code
Same split as the other guides. In VS Code's integrated terminal, run ccr code and you're routing, exactly like the native terminal. The chat sidebar does not go through ccr, so to route it you keep the router running with ccr start and point the extension at the local router by setting ANTHROPIC_BASE_URL to the router's address in claudeCode.environmentVariables, then reload the window. If that's more bother than it's worth, just use the integrated terminal, which needs none of it.
To route the VS Code sidebar too: keep the router running (ccr start), add this to VS Code's own settings, then reload the window. // VS Code settings.json (the router must be running: ccr start) { "claudeCode.environmentVariables": [ { "name": "ANTHROPIC_BASE_URL", "value": "http://127.0.0.1:3456" } ] }5. Switch on the fly, and switch back
To override the route for one session without touching the config, use /model with the same provider,model-id form: handy when you want one task on a bigger model. To stop routing entirely, run ccr stop and go back to a plain claude session, which talks to Claude directly again; a normal session never goes through the router. Your config file stays put for next time, so turning the router back on is just ccr code.
Override for one session, or stop the router and return to plain Claude. Claude Code❯ /model openrouter,z-ai/glm-5.2
This session now uses z-ai/glm-5.2 for everything.
❯ ccr stop
# Router off. Run claude (not ccr code) and you're back on Claude directly.
The takeaway
A router reads each request, sorts it into a tier, and sends it to the model you mapped there. Cheapest model on background, a capable one on default, Claude on think. The automatic version of doing the split by hand.
Prefer to learn by doing?
The interactive version of this playbook lives on melwyn Class, with animated terminal demos, Claude Code walkthroughs, and a library that saves your takeaways.