Claude Code Router: Complete Guide to Smarter AI Coding

/ Cut AI coding costs with CCR

Published: June 24, 2026 at 2:00 PM EDT | Updated: June 27, 2026 at 3:32 PM EDT
Claude Code Router
Image: Stephanie Smith / TheTweaks, Unsplash

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.

How Claude Code Router Works

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:

  • CCR intercepts the outgoing request
  • Transforms the payload to the target provider API format
  • Applies the routing rules you have set (task type or token number based)
  • Forwards the request and returns the response back to Claude Code
Claude Code Router Working
Image: A brief description of how claude code router works / Stephanie Smith, TheTweaks

Why Developers Are Using CCR in 2026

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.

Is Claude Code Router Worth It?

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.

Comparison: Native Claude Code vs CCR

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

Why Use CCR Instead of the Default Claude API?

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.

Reduce Claude API Costs

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%
Claude code router cost saving
Image: Real world cost saving of claude code router on multiple setups / Stephanie Smith, TheTweaks

Avoid Anthropic Rate Limits

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.

Use Multiple AI Models in One Workflow

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.

Who Should Use Claude Code Router?

CCR Should Be Used By:

  •  Users who actively use Claude Code daily
  •  Users working with large repositories
  •  Users who constantly hit Claude usage limits
  •  Users who use OpenRouter
  •  Users who want DeepSeek or Gemini to handle background tasks
  •  Users concerned with AI coding costs

CCR Should Not Be Used By:

  • Casual users who use Claude Code from time to time
  •  Users who dislike configuration complexity
  •  Users who need maximum stability
  •  Users whose workflow involves a lot of tool calling
  •  Users who want to connect only one provider account

Route Tasks Automatically Based on Complexity

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.

My Actual Claude Code Routing Strategy

My Actual CCR Configuration

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

Real World Cost Savings with Claude Code Router

A very detailed cost scenario and I highly recommend taking a look at it.

Cost Breakdown by Task Type

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

Reasons Behind This Configuration Choice

  • Claude still does the best job in code generation.
  • DeepSeek makes file indexing extremely cheap.
  • Gemini handles large repository reading better.
  • Ollama makes sure all the sensitive code stays local.

This routing strategy helped reduce the unnecessary costs without compromising the coding quality.

My Actual 7-Day Results With CCR

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

Key Results

  • The cost decreased by around 70-75%.
  • The token usage remained almost the same.
  • The latency increased due to the extra routing layer.
  • The coding quality was not affected in most cases.

Monthly Cost Saving Scenarios

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.

Is Claude API Free?

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.

Supported Models and Providers in Claude Code Router

CCR supports over 8 providers out of the box each one is added to the config as a block.

Claude Code Router with OpenRouter

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.

Claude Code Router with Gemini

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.

Claude Code Router with DeepSeek

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.

Claude Code Router with Codex CLI

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.

Claude Code Router with Ollama

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.

Claude code router integration
Image: Integration of claude code router with different AI models / Stephanie Smith, TheTweaks

How to Install Claude Code Router

Claude Code CLI NPM Installation

bash

# Install Claude Code globally first

Terminal

install -g @anthropic-ai/claude-code

# Then install CCR

Terminal

npm install -g @musistudio/claude-code-router

On Linux, you might face a permission error while installing. Fix it by setting a different global directory for npm:

bash

Terminal

mkdir -p ~/.npm-global
npm config set prefix ‘~/.npm-global’
export PATH=~/.npm-global/bin:$PATH

Add that export line to your  ~/.bashrc or ~/.zshrc permanently, a standard fix most of the guides omit.

CCR Installation from GitHub

bash

Terminal

git clone https://github.com/musistudio/claude-code-router
cd claude-code-router
npm install
npm run build

Use the claude code router github, install if you want to track a particular commit or contribute to the project directly.

How to Open Claude Code in Terminal

Launching Claude Code Using CCR

After installing and configuring CCR, the only command you’ll ever use is:

bash

Terminal

ccr code

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.

Running ccr code commands

You can also manage the service separately:

bash

Terminal

ccr start      # Starts the proxy only
ccr restart    # Restarts after config changes
ccr activate   # Sets the environment variables in your shell

Common Terminal Commands

For making CCR persistent across the sessions, add that line to your shell profile:

bash

Terminal

eval “$(ccr activate)”

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.

Claude Code Router Configuration Guide

All the configurations reside in one file: ~/.claude-code-router/config.json.

Understanding the CCR Config File

The file contains two mandatory top level objects: Providers (sources of your models) and Router (which model to use for each task type).

JSON

{“Providers”: [
{
“name”: “deepseek”,
“api_base_url”: “https://api.deepseek.com/chat/completions”,
“api_key”: “$DEEPSEEK_API_KEY”,
“models”: [“deepseek-chat”, “deepseek-reasoner”]
},
{
“name”: “openrouter”,
“api_base_url”: “https://openrouter.ai/api/v1/chat/completions”,
“api_key”: “$OPENROUTER_API_KEY”,
“models”: [“google/gemini-2.5-pro-preview”]
}
],
“Router”: {
“default”: “deepseek,deepseek-chat”,
“background”: “deepseek,deepseek-chat”,
“think”: “deepseek,deepseek-reasoner”,
“longContext”: “openrouter,google/gemini-2.5-pro-preview”
}
}

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.

Setting the Default Models

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.

Creating Task Based Routing Rules

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

Claude Code Router Transformers

This is what almost all the guides misses, yet this is where the power of CCR lies.

What Is a Transformer?

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.

Request Transformation

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:

JSON

“transformer”: {
“use”: [“openrouter”]
}

Response Transformation

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.

Provider Compatibility Layer

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.

OpenRouter with Claude Code Router

OpenRouter Setup

Add OpenRouter to your providers list in config.json:

JSON

{
“name”: “openrouter”,
“api_base_url”: “https://openrouter.ai/api/v1/chat/completions”,
“api_key”: “$OPENROUTER_API_KEY”,
“models”: [“anthropic/claude-3.5-sonnet”, “google/gemini-2.5-pro-preview”],
“transformer”: { “use”: [“openrouter”] }
}

Adding API Keys

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.

Routing Claude Code Requests Through OpenRouter

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.

Best OpenRouter Models for Coding

  • anthropic/claude-3.5-sonnet – best Claude quality output through OpenRouter
  • google/gemini-2.5-pro-preview – best for long context repository analysis
  • deepseek/deepseek-chat – cheapest capable claude for coding

Gemini with Claude Code Router

Gemini Setup

JSON

{
“name”: “gemini”,
“api_base_url”: “https://generativelanguage.googleapis.com/v1beta/openai/chat/completions”,
“api_key”: “$GEMINI_API_KEY”,
“models”: [“gemini-2.5-pro”, “gemini-2.5-flash”]
}

Long Context Routing

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.

Gemini vs Claude for Large Repositories

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.

Ollama for Local AI Coding

Why Run Models Locally

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.

Ollama Integration Setup

JSON

{
“name”: “ollama”,
“api_base_url”: “http://localhost:11434/v1/chat/completions”,
“api_key”: “ollama”,
“models”: [“qwen2.5-coder:latest”, “llama-3.3-70b”]
}

Firstly, pull the model with ollama pull qwen2.5-coder:latest and then route background requests to the Ollama in the Router block.

Best Local Models for Claude Code Router

  • Qwen2.5-coder:latest – best local coding model, most popular in the CCR community
  • Ollama-3.3-70b – good general-purpose model for reasoning tasks
  • Deepseek-coder-v2:latest – good alternative for code-heavy background routing

Claude Code Router vs CC Switch

Feature Comparison

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

Routing Flexibility

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.

Model Support

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.

Which Tool Should Developers Choose?

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.

Claude Code Router Alternatives

CC Switch

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.

Direct Claude Code + OpenRouter Setup

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.

Continue.dev

VSCode extension with multi provider support. Better integration with IDE than CCR, but no native CLI workflow.

Cursor

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 CLI

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.

Advanced Claude Code API Integration

Team Deployment Strategies

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.

CI/CD integration

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.

Enterprise Use Cases

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.

When Does Claude Code Router Make Things Worse?

Tool Calling Failures

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.

Increased Latency

CCR adds an extra routing layer.

Most of the time, I noticed additional 200-500 ms latency.

Context Fragmentation

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.

Routing Mistakes

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.

More Configuration Complexity

Native Claude Code is ready for usage right away.

CCR requires:

  • API keys
  • Routing rules
  • Testing
  • Monitoring

This setup complexity is not always worth the trouble for every developer.

Claude Code Router Common Issues & Solutions

Router Does Not Start

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.

Authentication Errors to API

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 Connection Issues

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.

Gemini Configuration Issues

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.

Model Routing Issues

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.

When I Wouldn’t Use Claude Code Router

I wouldn’t use CCR when:

  • Building production-critical software
  • Handling highly sensitive enterprise code
  • Testing new models
  • Working with complex tool-calling workflow
  • In case of maximum reliability requirement

Final Verdict

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.

Frequently Asked Questions

No. CCR works without an Anthropic account if you route entirely through alternative providers like OpenRouter, DeepSeek, Gemini, or Ollama. An Anthropic account is only needed if you include Anthropic's models in your routing config.
DeepSeek Chat for background and default (cheapest capable option), DeepSeek Reasoner for think, Gemini 2.5 Pro for longContext, and Claude Sonnet 4.6 or Opus 4.6 for high-stakes tasks where quality is non-negotiable.
CCR supports task-based routing across four route types with a full transformer system and 8+ providers. CC Switch is simpler but has no dynamic routing by task type and no transformer layer for provider compatibility.
Most Related