A local gateway for coding agents
Claude Code Router is an open-source project by musistudio
on GitHub, MIT licensed, with more than 38,000 stars. It
runs a model gateway on your own machine and gives your
coding agents one local endpoint,
http://127.0.0.1:3456 by default. Behind that
endpoint you add providers, models, accounts and routing
rules, and CCR sends each request where you said.
It began as a way to run Claude Code on other models.
Version 3 supports Claude Code, Claude Design, Codex, Grok
CLI, Kimi CLI, Kilo Code, OpenCode, Pi, ZCode and WorkBuddy.
It speaks the OpenAI, Anthropic and Gemini APIs and has
presets for providers such as OpenRouter, DeepSeek,
Moonshot, Mistral and Z.AI, plus any compatible endpoint (README).
How setup works in version 3
The README recommends the desktop app for macOS, Windows or
Linux. Open Providers and add a provider from a preset or a
custom endpoint, with its API key, protocol and models. Open
Server and click Start. Open Agent Config, choose your agent
and a model, and apply the profile. Then use your agent as
usual and check Logs for the provider and model each request
went to.
Without the desktop app,
npm install -g @musistudio/claude-code-router
and then ccr ui open the same screens in a
browser on port 3458. The CLI needs Node.js 22 or newer, and
the repository also has a Docker setup. Settings live in
~/.claude-code-router/config.sqlite; the docs
say to use Settings, Export data, instead of copying that
file while CCR runs (CLI reference).
If you used it before: config.json and ccr code
Guides written before version 3 describe a hand-edited
~/.claude-code-router/config.json with a
Providers list and a Router block,
started with ccr code. The version 2 README
shows this shape:
{
"Providers": [
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "sk-xxx",
"models": ["deepseek-chat", "deepseek-reasoner"]
}
],
"Router": {
"default": "deepseek,deepseek-chat",
"background": "ollama,qwen2.5-coder:latest",
"think": "deepseek,deepseek-reasoner",
"longContext": "openrouter,google/gemini-2.5-pro-preview",
"longContextThreshold": 60000,
"webSearch": "gemini,gemini-2.5-flash"
}
}
Each Router key named a provider and model for
one kind of request: default for most turns,
background for small background tasks,
think for reasoning such as Plan Mode,
longContext above the token threshold (60,000
by default) and webSearch for search.
/model provider,model switched models inside a
session, and CUSTOM_ROUTER_PATH pointed at your
own routing script (version 2 README). The version 3 CLI reference launches agents with
ccr <profile> and doesn't list
ccr code.
How routing rules work now
Rules are checked in list order, and the first enabled match
rewrites the request. A condition reads a request header or
a body field, such as messages.0.role, with
operators like ==, contains or
>. To route by model, a rule sets
request.body.model. For logic a condition can’t
express, a rule can run a Node.js script that returns a
model, rewrites and a fallback (routing docs).
When the chosen model fails, CCR can send once, retry the
same model, or try an ordered chain of fallback models,
honoring Retry-After or backing off for up to
30 seconds. Subagents can name their own model with a
<CCR-SUBAGENT-MODEL> tag, and CCR
converts Codex’s apply_patch tool so models
outside GPT can edit files.
What it does well
-
It’s free and open source, so you can read the code that
handles your requests.
- It runs on macOS, Windows and Linux, and in Docker.
-
It reaches almost any provider through presets or a custom
compatible endpoint, including local servers.
-
One endpoint serves many agents, so changing a provider
doesn’t mean editing each agent’s settings.
-
Credential pools, key rotation, retries and fallback
chains keep long sessions going through rate limits and
outages.
-
Logs show the provider, model, credential, latency, tokens
and estimated cost of each request.
Where it gets hard
-
You choose the models and write the rules. CCR applies
what you set and doesn’t judge how hard a request is on
its own.
-
Each provider needs its own account and key, and you pay
and track each one separately.
-
The gateway has to be running while you work, or most
agent profiles can’t connect.
-
Claude Code and Codex are built around their own models’
tools. CCR converts tool calls for other models, and how
well each model handles them varies, so test a model
before you rely on it.
-
Version 3 changed the config format and commands, so many
tutorials no longer match what you install.
-
Reaching it from another machine takes care: the
management URL carries a token to treat as a password, and
the
Docker guide
says to keep the UI off untrusted networks.