Claude Code Router: Route to DeepSeek & Cut Costs
By: Evgeny Padezhnov
Claude Code is locked to Anthropic's API by default. Claude Code Router breaks that lock. It sits between the CLI and any model provider you want.
The tool solves a real cost problem. Claude Code sends a lot of tokens per session. Running every request through Opus or Sonnet adds up fast. Claude Code Router lets developers route cheap work to DeepSeek or a local model, and keep the expensive model only where it matters.
What Claude Code Router Actually Does
Claude Code Router (CCR) is an open-source proxy. It is published on GitHub as musistudio/claude-code-router. It runs a local server that speaks the Anthropic API format.
Claude Code talks to this server instead of api.anthropic.com. The router receives the request, rewrites it for the target provider, and forwards it. The response gets translated back into the format Claude Code expects.
Claude Code CLI
| Anthropic API request (/v1/messages)
v
CCR local proxy (127.0.0.1, speaks Anthropic API format)
| classify request + rewrite to provider format
v
Provider (DeepSeek / Ollama / Gemini / ...)
| provider-native response
v
CCR local proxy (translate response back to Anthropic format)
| Anthropic-shaped response
v
Claude Code CLI
The short version: CCR tricks Claude Code into thinking it is talking to Anthropic, while the real work runs on DeepSeek, Gemini, Qwen, or a model on your own machine.
The router supports many backends:
- DeepSeek (
deepseek-chat,deepseek-reasoner) - OpenRouter (access to hundreds of models through one key)
- Ollama and LM Studio (fully local, offline)
- Google Gemini
- SiliconFlow, Volcengine, and other OpenAI-compatible endpoints
Worth knowing: any provider with an OpenAI-compatible or Anthropic-compatible endpoint can be wired in. That covers almost every commercial and local model in 2026.
How the Router Decides Where Requests Go
CCR does not send everything to one model. It classifies each request and routes by category. This is the feature that saves money.
There are five routing categories:
- default — normal coding requests
- background — lightweight tasks that Claude Code would send to Haiku
- think — reasoning and plan mode, where a thinking model helps
- longContext — requests above a token threshold (default 60000)
- webSearch — requests that need a web-search-capable model
Each category maps to a provider,model pair. A common setup routes background to a free local model, default to DeepSeek, and longContext to Gemini for its large window.
| Category | Fires on | Typical provider/model |
|---|---|---|
default |
Normal coding requests | deepseek, deepseek-chat |
background |
Lightweight tasks (Claude Code's Haiku-tier calls) | ollama, qwen2.5-coder (local, free) |
think |
Reasoning / plan mode | deepseek, deepseek-reasoner |
longContext |
Requests above longContextThreshold (default 60000 tokens) |
openrouter, google/gemini-2.5-pro |
webSearch |
Requests needing a web-search-capable model | openrouter, google/gemini-2.5-pro |
Easy to get wrong: sending large-context requests to a model with a small window. The longContextThreshold value exists exactly to catch this. When a request crosses it, CCR redirects to the model you picked for big context.
Advanced users can go further with a custom router script. Point CUSTOM_ROUTER_PATH at a JavaScript file and write your own logic. That file receives the request and returns the model string to use.
Installation
CCR needs Node.js and the official Claude Code CLI installed first. Both are on npm.
Install Claude Code, then the router:
npm install -g @anthropic-ai/claude-code
npm install -g @musistudio/claude-code-router
Verify the router binary:
ccr version
The main command replaces claude with ccr code:
ccr code
That command starts the router server if it is not running, then launches Claude Code pointed at it. No manual environment variable export is needed. CCR sets ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY for the spawned process.
Other lifecycle commands are useful during setup:
ccr start # start the server manually
ccr status # check if it is running
ccr stop # stop it
ccr restart # reload after editing config
Common mistake: editing the config while the server runs and expecting changes to apply. Run ccr restart after every config edit, or the old settings stay live.
Configuration: The config.json Breakdown
CCR reads one file: ~/.claude-code-router/config.json. This file holds providers and routing rules. Create it before the first real run.
A working example with three providers looks like this:
{
"LOG": true,
"HOST": "127.0.0.1",
"Providers": [
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "sk-your-deepseek-key",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": {
"use": ["deepseek"],
"deepseek-chat": { "use": ["tooluse"] }
}
},
{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "sk-or-your-key",
"models": ["google/gemini-2.5-pro", "anthropic/claude-sonnet-5"],
"transformer": { "use": ["openrouter"] }
},
{
"name": "ollama",
"api_base_url": "http://localhost:11434/v1/chat/completions",
"api_key": "ollama",
"models": ["qwen2.5-coder:latest"]
}
],
"Router": {
"default": "deepseek,deepseek-chat",
"background": "ollama,qwen2.5-coder:latest",
"think": "deepseek,deepseek-reasoner",
"longContext": "openrouter,google/gemini-2.5-pro",
"longContextThreshold": 60000,
"webSearch": "openrouter,google/gemini-2.5-pro"
}
}
Providers
Each provider needs four fields: name, api_base_url, api_key, and models. The name is your own label. The models array lists what you can route to from that provider.
The api_base_url must be the full endpoint path, not just the host. For most OpenAI-compatible providers that ends in /chat/completions. A wrong path is the most frequent first-run failure.
Router rules
The Router block maps categories to provider,model strings. The format is the provider name from the list, a comma, then the model id. No spaces around the comma.
Only default is strictly required. If a category is missing, CCR falls back to default. Set background to a cheap or local model first — it handles the highest-volume, lowest-value calls.
Transformers
Transformers adapt request and response shapes between the Anthropic format and each provider's format. Without the right transformer, tool calls and reasoning fields break.
CCR ships built-in transformers, including deepseek, openrouter, gemini, tooluse, reasoning, and maxtoken. Attach them per provider or per model.
The maxtoken transformer is useful when a model rejects the token limit Claude Code sends. The tooluse transformer improves function-calling reliability on models that handle tools poorly.
From real setups: DeepSeek needs the deepseek transformer, and deepseek-chat benefits from tooluse for stable tool calls inside Claude Code. Skipping it causes silent tool failures.
Provider Examples That Work
DeepSeek — the cheap default
DeepSeek is the most common default choice. deepseek-chat handles general edits. deepseek-reasoner fits the think category for plan mode.
Get a key from the DeepSeek platform, drop it in the provider block, and route default to it. The cost per token is a fraction of frontier models.
| Model | Input ($/1M) | Output ($/1M) |
|---|---|---|
| Claude Opus 4.8 | $5.00 | $25.00 |
| Claude Sonnet 5 | $3.00 | $15.00 |
| Google Gemini 2.5 Pro | $1.25 | $10.00 |
DeepSeek (deepseek-chat) |
$0.14 | $0.28 |
| Ollama (local) | $0 | $0 |
Published rates per 1M tokens (July 2026); prompt-caching and batch discounts not shown. Gemini 2.5 Pro rises to $2.50 / $15.00 once a prompt crosses 200k tokens. On these numbers deepseek-chat runs roughly 30-90x cheaper than Opus 4.8 per token, which is why it is the usual default.
Ollama — fully local and free
Ollama runs models on your own hardware. No API cost, no data leaving the machine. Point the router at http://localhost:11434/v1/chat/completions.
The api_key for Ollama can be any placeholder string, such as "ollama". The endpoint ignores it. Pull a coding model first with ollama pull qwen2.5-coder.
Key point: local models are weaker at long agentic chains. Use Ollama for background tasks, not for complex multi-file refactors. Practice shows small local models lose track of tool state.
OpenRouter — one key, many models
OpenRouter proxies hundreds of models behind a single key. It is the flexible option for the longContext and webSearch categories. Documentation lives at openrouter.ai/docs.
Route large-context work to a model with a big window, like Gemini, through OpenRouter. This keeps expensive frontier calls rare and targeted.
Switching Models Inside a Session
Routing rules are the automatic path. Manual override also works mid-session.
Inside a running Claude Code session, type:
/model deepseek,deepseek-reasoner
That switches the active model to the DeepSeek reasoner for the rest of the session. The format matches the config: provider,model. This helps when one task suddenly needs a stronger model.
CCR also ships a web UI for editing config without touching JSON:
ccr ui
The UI opens a local page to manage providers, keys, and routing. It writes the same config.json. Try it: run ccr ui once to validate provider fields visually before hand-editing the file.
Common Mistakes and Fixes
Server not restarting after edits. Config is cached in memory. Run ccr restart after every change to config.json.
Wrong endpoint path. The api_base_url must include the full path such as /chat/completions. A host-only URL returns 404s that look like auth errors.
Missing transformer. Tool calls fail silently on some providers. Add the provider's transformer and tooluse where needed.
Model name typos. The model id in Router must match the id in the provider models array exactly. A mismatch falls back or errors.
Reading logs. Set "LOG": true in config. Logs land in the ~/.claude-code-router/ directory. They show the resolved model per request, which reveals routing bugs fast.
Key point: if a request behaves oddly, check the log for which provider actually handled it. Routing errors hide behind normal-looking output. If it works — it is correct, but verify the model in the log before trusting the setup.
Trade-offs to Know Before Switching
Claude Code was tuned for Anthropic models. Its agentic loop, tool prompts, and system instructions assume Claude behavior. Other models handle these prompts with varying quality.
DeepSeek and Qwen perform well on straightforward edits. They lag on long autonomous sequences and complex tool orchestration. Frontier Anthropic models still lead there.
The practical pattern is a mix. Route bulk and background work to cheap models. Keep a frontier model wired in for the think and hard default cases, switched in with /model when a task demands it.
What to Try Right Now
Install both CLIs, create ~/.claude-code-router/config.json with one DeepSeek provider, and set default to deepseek,deepseek-chat. Run ccr code and give it a small refactor task.
Watch the cost and the log. Compare the result against a normal Claude Code run on the same task. That single comparison shows whether the trade-off fits your workflow before you wire in more providers.
The official docs for the CLI itself stay useful alongside the router — see the Claude Code documentation for command and permission details that CCR does not change.
Related guides
- Claude Code — the complete guide.
- Is Claude Code free? Pricing & limits — what you'd otherwise pay Anthropic.
Information is accurate as of the publication date. Terms, prices, and regulations may change — verify with relevant professionals.