Claude Code Router: Complete Guide to Smarter AI Coding
/ Cut AI coding costs with CCR
by /
Published: June 24, 2026 at 2:00 PM EDT | Updated: June 27, 2026 at 3:32 PM EDT
Others
/ Cut AI coding costs with CCR
Quick Verdict: Claude Code Router (CCR) is a free local proxy sitting between Claude Code and the AI provider. CCR intercepts each outgoing request and routes it to a respective model based on its task type, reasoning to Claude Opus and background file scans to DeepSeek at a much lower price. You can use it via npm install -g @musistudio/claude-code-router and ccr code.
I have been using Claude Code for more than a week now, and what i noticed is that it is one of a great product. However, there is another thing that happens slowly without your notice, bills grow. Each docstring request, each background file scan, each context compaction request hits the same Anthropic endpoint at the same premium price point whether it should or not.
This is when Claude Code Router comes to the rescue. It is an open source proxy tool created by @musistudio that intercepts Claude Code API requests before they leave your machine and redirects them to a proper model based on their task type. The Claude Code Router project has over 35,300 GitHub stars and 2,900+ forks as of June 2026 and that is a sign that this is not a workaround but a movement among developers.
CCR binds to a local port on your machine (default 127.0.0.1:3456). Claude Code believes it talks to Anthropic. In fact, all requests go through Claude Code Router first, where the routing rules are applied, the payload is transformed to target provider API format and passed further. Finally, the response is received, translated back and passed back to Claude Code.
The process step by step:

One thing that shocked me is that I gave it a try toCCR using OpenRouter API and got a bill of $40 for 4 to 5 hours of work. At that point, subscription to the Anthropic plan became a no brainer. This is quite a common experience, yet CCR gives you a third way of dealing with the problem. Not just paying extra money to have API access or subscribing, you route selectively. The expensive model is reserved for the expensive tasks, and everything else goes somewhere cheaper.
After using Claude Code Router (CCR) for more than a week, here’s what I have to say about it: CCR is absolutely worth using if you spend any decent money on AI coding or often hit Anthropic limits.
For casual users sending several prompts per day, the configuration complexity will likely outweigh the savings.
For developers paying $20-$100+ monthly on coding agents, CCR is a great choice since it helps expensive models get reserved exclusively for their tasks.
| Feature | Native Claude Code | Claude Code Router |
|---|---|---|
| Provider support | Anthropic only | 8+ providers |
| Cost optimization | None | 50–99% savings |
| Model switching | Manual | Automatic by task type |
| Local model support | No | Yes (Ollama) |
| Anthropic account required | Yes | Optional |
| GitHub Actions support | Limited | Built-in |
The native Claude Code API integration is quite straightforward but quite inflexible at the same time. All the requests go to the same model at the same price. Such an all models approach raises multiple issues that CCR solves directly.
Using CCR as a part of your Claude workflow and applying a smart routing strategy, a developer working on 100 million tokens per month will be able to reduce costs from $1,500-$1,800 (all Claude Sonnet 4.6) to $300-$500 by routing background requests to DeepSeek and long context reads to Gemini. That is 70%-80% less spending on the same result without changing a line of your code.
| Setup | Est. Monthly Cost | Savings |
|---|---|---|
| All Claude Sonnet 4.6 | $1,500 – $1,800 | Baseline |
| Smart routing (CCR) | $300 – $500 | ~75% |
| Router + free credits | $0 – $50 | ~97% |

When I get rate-limited by Anthropic, my entire claude for coding workflow breaks. CCR solves this problem bypassing Anthropic completely and failing over to an alternative provider without breaking your session.
A single CCR session can use 3 to 5 different providers seamlessly. You can have Claude Sonnet to handle architectural decisions, DeepSeek Chat to handle background requests, Gemini 2.5 Pro to handle long context repository reads, all in the same terminal session without any manual switching.
Here is what is really cool about CCR. Claude Code constantly fires background requests during a session to compact the context and index the files. These requests never need a frontier model. In case of a standard Claude installation, such requests have become invisible costs. In the case of CCR, they are automatically routed to a fast and cheap model.
Having tried a number of different routing strategies, I chose the following one:
|
Route Type |
Model |
|---|---|
|
Default Coding |
Claude Sonnet |
|
Background Tasks |
DeepSeek Chat |
|
Think Mode |
DeepSeek Reasoner |
|
Long Context |
Gemini 2.5 Pro |
| Private Tasks |
Ollama |
A very detailed cost scenario and I highly recommend taking a look at it.
| Task Type | % of Traffic | Provider | Cost per 1M Tokens |
|---|---|---|---|
| Default coding | 40% | Claude Sonnet 4.6 | $3 in / $15 out |
| Background tasks | 30% | DeepSeek Chat | $0.14 in / $0.28 out |
| Long context reads | 20% | Gemini 2.5 Pro | $1.25 in / $10 out |
| Local/private tasks | 10% | Ollama (local) | $0 |
This routing strategy helped reduce the unnecessary costs without compromising the coding quality.
|
Day |
Cost Before CCR | Cost After CCR | Token Usage | Avg Latency Before |
Avg Latency After |
|---|---|---|---|---|---|
|
Day 1 |
$12.40 |
$3.10 |
Same |
2.3s |
2.5s |
|
Day 2 |
$11.90 | $2.95 | Same | 2.1s |
2.4s |
|
Day 3 |
$13.20 | $3.35 | Same | 2.4s |
2.7s |
|
Day 4 |
$10.80 | $2.75 | Same | 2.2s |
2.5s |
|
Day 5 |
$12.10 | $3.00 | Same | 2.3s |
2.6s |
|
Day 6 |
$11.70 | $2.90 | Same | 2.1s |
2.4s |
|
Day 7 |
$12.60 | $3.20 | Same | 2.4s |
2.8s |
A heavy user will pay $300-$500 routing in such a manner instead of $1,500+. The biggest saving here is background routing. Those constant file scanning requests were invisible costs previously.
No, the Claude API is not free. Anthropic charges per token. Claude Sonnet 4.6 costs $3 per million input tokens and $15 per million output tokens as of mid 2026. CCR does not make Claude API free but allows you to use cheaper models for tasks that do not require Claude’s full power. Local Ollama routing is the only truly zero cost option and runs on your own hardware.
CCR supports over 8 providers out of the box each one is added to the config as a block.
OpenRouter gives you access to 200+ models through one API key. It is a perfect starting point for CCR because it has several free tier models and lets you check routing before spending any money. For coding tasks, anthropic/claude-3.5-sonnet through OpenRouter provides Claude’s quality with an additional reliability layer.
What I personally feel is that Gemini 2.5 Pro is the model you need for longContext routing. With 1 million token context windows, it can handle large codebases where Claude remove it silently. Set longContextThreshold to 60,000 tokens in your config and requests above that threshold will go automatically to Gemini.
As per my verdict, DeepSeek is the most cost effective solution for default and background routes. DeepSeek Chat is approximately 50 times cheaper than Claude Opus per token. DeepSeek Reasoner works well with thin routing for complex planning tasks.
Codex CLI by OpenAI is a compatible coding agent that works with CCR proxy. Just point it to your local router by setting ANTHROPIC_BASE_URL to your CCR endpoint and you’ll benefit from multi-model routing with your existing config.json.
Ollama runs models entirely on your own hardware, no API cost and no data leakage. It is a perfect choice for private or proprietary codebases where a claude code router will send your sensitive code to external APIs. qwen2.5-coder and llama-3.3-70b are the most popular models among CCR community for the background route.

bash
# Install Claude Code globally first
# Then install CCR
On Linux, you might face a permission error while installing. Fix it by setting a different global directory for npm:
bash
Add that export line to your ~/.bashrc or ~/.zshrc permanently, a standard fix most of the guides omit.
bash
Use the claude code router github, install if you want to track a particular commit or contribute to the project directly.
After installing and configuring CCR, the only command you’ll ever use is:
bash
It replaces the native claude command. Starts the proxy on 127.0.0.1:3456 and launches Claude Code with the ANTHROPIC_BASE_URL being your local router automatically.
You can also manage the service separately:
bash
For making CCR persistent across the sessions, add that line to your shell profile:
bash
Note: the command above does only the ccr activate part. It sets the environment variables and does not start the service – use ccr start separately in this mode.
All the configurations reside in one file: ~/.claude-code-router/config.json.
The file contains two mandatory top level objects: Providers (sources of your models) and Router (which model to use for each task type).
Remember to use $VAR_NAME syntax for the API keys, don’t hardcode them anywhere. The CCR supports the environment variable interpolation in the entire claude code router config.
The default key in the Router block is your fallback. All the requests, which do not fit any other rules, will go there. Start with the DeepSeek Chat, it is powerful, fast and affordable enough to be a reasonable choice.
| Router Key | When It Fires | Recommended Model |
|---|---|---|
| default | All standard prompts | DeepSeek Chat |
| background | Scanning files, context compaction | Ollama / DeepSeek Chat |
| think | Plan Mode, reasoning | DeepSeek Reasoner |
| longContext | Requests more than 60K tokens | Gemini 2.5 Pro |
| webSearch | Web search tasks | Model with native search capabilities |
This is what almost all the guides misses, yet this is where the power of CCR lies.
Not all the providers support Anthropic formatted requests. A claude code router transformer is an adapter that is included in CCR and transforms requests and responses to make different API providers work with Claude Code. It acts as a translation layer between Claude Code protocol and whatever API format your provider uses.
Once CCR sends your request to the OpenRouter, it transforms the payload headers, removes unnecessary fields that are not supported by the provider and maps Anthropic specific parameters to the provider’s equivalent ones. You define the transformation per provider in the Providers block:
Then the response is transformed back to the Claude Code protocol and sent back to your terminal. That’s why Claude Code will never know that the backend model was changed.
Not all the models can go through the translation layer. I also discovered a serious limitation which is one of the main concern is that some AI models do not support Claude Code’s tool calling features correctly. Both Qwen3 and Kimi K2 had problems with tool calling in the CCR GitHub issues. Make sure to test the tool calling behavior separately on a non critical task before choosing the model for your default routing.
Add OpenRouter to your providers list in config.json:
Obtain the key at openrouter.ai/settings/keys and export it: export OPENROUTER_API_KEY=”sk-or-…”. CCR takes $OPENROUTER_API_KEY directly from the environment, the raw key will not end up in the config file.
OpenRouter adds a reliability layer which CCR itself lacks. In case one of the Anthropic providers rate limits your session, OpenRouter will automatically fail over to another provider without any interruption. This failover mechanism is important for developers working with Claude Code in CI pipelines.
The main reason to add Gemini 2.5 Pro to your CCR config is its 1M tokens context window. Set the longContext router key to Gemini and increase the longContextThreshold according to your actual codebase size. 60,000 tokens is a good starting point for most mid-sized projects.
The context window of Claude is quite good. There is a limit that silently cuts off the information in very large sessions. Gemini will not cut and process the whole context. For repository wide refactoring and large codebase analysis, the Gemini is a technically correct choice but not a cheaper option.
There are two reasons to run models locally: save on API fees (cost) and keep your codebase private. From my experience what I can tell you all is that if you have a proprietary codebase, client work or some sensitive internal project, routing through Ollama should be your default choice for claude code router setup, not just the cost optimization.
Firstly, pull the model with ollama pull qwen2.5-coder:latest and then route background requests to the Ollama in the Router block.
| Feature | Claude Code Router | CC Switch |
|---|---|---|
| Installation method | npm global | npm global |
| Configuration format | JSON file | CLI arguments |
| Task based routing | Yes (4 route types) | Limited |
| Transformer system | Yes | No |
| Local model support | Yes (Ollama) | Limited |
| GitHub Actions integration | Yes | No |
| Community size | 33K+ GitHub stars | Smaller |
Claude Code Router is superior in terms of routing flexibility. Its four route types (default, background, think, longContext) and the custom JavaScript router give you fine grained control over routing for every request. CC Switch is easier to configure, but it does not have routing by task type.
CCR supports 8+ providers natively and has the transformer system for providing compatibility with non-Anthropic providers. CC Switch has fewer providers and no equivalent compatibility layer.
Use CC Switch if you need a simple tool for swapping providers without using config file. Use Claude Code Router if you need the automated task based routing, which will help you save your API bill and that applies to most professional use cases.
The closest direct alternative to CCR. Easier to configure but lacks routing by task type and the transformer layer for providing compatibility with non-Anthropic providers.
You can route your Claude Code directly to OpenRouter by changing the ANTHROPIC_BASE_URL to the OpenRouter endpoint. You will get provider failover and 200+ models, but you will not have task based routing between them.
VSCode extension with multi provider support. Better integration with IDE than CCR, but no native CLI workflow.
Cursor IDE, built on top of AI coding. Great tool if you want everything in one place but does not have the same routing flexibility as claude code router for CLI workflow.
Codex is an OpenAI coding agent. You can use it in combination with CCR as the client pointing at your local proxy, not as a direct alternative, providing you the multi model routing of Claude Code.
For team deployments, add the API KEY to your CCR config to require authentication from every client that connects to the router. Without it, CCR will bind to 127.0.0.1. With the API KEY, you will be able to safely expose your proxy to your internal network. Always use environment variable interpolation for all the API keys and never commit your raw credentials to the version control.
Integration guide from OpenRouter confirms the GitHub Actions pattern to pass your OpenRouter API key as the anthropic_api_key and set the ANTHROPIC_BASE_URL to https://openrouter.ai/api in the action’s environment block. For native CI integration of CCR, set NON_INTERACTIVE_MODE: true in your config to disable interactive prompts and unblock the automation.
CCR is a community project not officially supported by Anthropic. For enterprise deployments at scale, layer CCR with the purpose built gateway like LiteLLM or Portkey for audit logging, spend caps and SLAs guarantees. Use CCR as the routing intelligence layer and the gateway for enforcing policies.
Not all providers have full support for Claude Code tool calling.
I faced some issues when testing other models except Claude such as Qwen and Kimi.
CCR adds an extra routing layer.
Most of the time, I noticed additional 200-500 ms latency.
Different models have their way of interpreting the context.
Sometimes, when a task started by Claude was then continued by another model, it lost nuance.
Incorrect routing rules make some coding tasks be sent to cheaper models.
As a result, we get a lower-quality response which requires additional fixes.
Native Claude Code is ready for usage right away.
CCR requires:
This setup complexity is not always worth the trouble for every developer.
Check whether the port 3456 is already taken. Review the logs of startup in ~/.claude-code-router/logs/ccr-*.log. The most common reasons for the issue are port conflict and malformed config.json file, validate your JSON syntax before restarting CCR.
Make sure ANTHROPIC_API_KEY is set to an empty string (“”) and not being undefined. Undefined API key will cause Claude Code to fallback to the default authentication provided by Anthropic and conflict with the router. Use /logout inside Claude Code if you had any Anthropic session cached before.
OpenRouter blocks the usage of free models for sending data to the third party services by default. In case you see “No endpoints found matching your data policy” message, go to your OpenRouter privacy settings and enable free model usage.
Check that the api_base_url points to the full OpenAI-compatible Gemini endpoint. The most common mistake when integrating Gemini into CCR is pointing to the domain without /v1beta/openai/chat/completions path.
The most common configuration error: inconsistency between the model name in Providers and the name in the Router. They should match exactly. Every time after configuration change, don’t forget to restart the CCR as it does not have a hot reloading.
Claude Code Router is among the most useful tools available in the AI coding ecosystem right now but somehow it flies very low compared to the other tools.
There is one basic reason to use the Claude Code Router: the coding session is never one workload. Background file scan, context compacting, branch naming and docstring creation do not need Claude Opus. Architectural planning and refactoring do. CCR lets you take advantage of the difference automatically without interrupting your workflow.
In my own words from my research: the claude code router transformer system is the thing which most developers tend to overlook. This is what makes other non-Anthropic providers compatible with the CCR and this is what breaks first when there is some problem. It always is important to test the tool-calling behavior on the new model before routing any real work to it. The HN thread contains a lot of people, who have learned it with Mistral, Qwen3 and Kimi K2.
The community feedback data suggests that routing everything to OpenRouter for Claude without a subscription can get rather costly very fast. The smart thing to do in this situation is to try a hybrid approach: Claude for the tasks, which justify its cost, and DeepSeek or Ollama for the other stuff.
Solo developers: start with the background route pointing to DeepSeek. You will save tokens quite fast this way.
Teams: put the OpenRouter reliability layer on top of CCR, put the APIKEY into your config in order to secure the local proxy and force the environment variables interpolation for all the credentials.
The CCR does not seem to be hardened enough for enterprise-scale usage right now. The GitHub issues prove it perfectly. But as far as solo developers and small teams are concerned, it is a very useful tool, which pays back for the time needed for its installation each month.
Letty Simone is an expert AI writer. She Covers AI news, reviews tools and updates the audience with the latest AI updates. She joined TheTweaks as an AI writer but Prior to TheTweaks she worked as an AI product tester at a business software company. She thinks that the majority of AI reporters represent the story wrongly and she has an aim to do it in a better way.





Quick Verdict: What Are the Different Types of AI Agents?There are 5 main types of AI agents: simple reflex, model-based reflex, goal-based, utility-based, and learning…
















Be respectful and constructive. Have a question or feedback? We’d love to hear from you. Contact us at contact@thetweaks.com