Claude Code Router: How to Run Claude Code With Any Model

Want to run Claude Code with any model? Learn how Claude Code Router connects GLM, DeepSeek and OpenRouter, then set up routing and fallbacks.

Ashley Innocent

Ashley Innocent

1 December 2026

Claude Code Router: How to Run Claude Code With Any Model

Apidog for Enterprise

On-Premises Deploy

SSO & RBAC

SOC 2 Compliant

Explore Apidog Enterprise

Claude Code Router (CCR) is a free, open-source local gateway that lets you run Claude Code with any model: GLM, DeepSeek, Kimi, OpenRouter, or a model on your own machine. You install it, add a provider and an API key, start its gateway on 127.0.0.1:3456, and launch Claude Code through a CCR profile. Claude Code keeps its tools and workflow; CCR decides which model answers each request.

What is Claude Code Router?

Claude Code Router is an MIT-licensed project by musistudio that sits between your coding agent and your model providers. It exposes one local endpoint, translates each request into the format the upstream provider speaks, applies your routing rules and fallbacks, and logs which model answered.

The project has more than 38,000 stars on GitHub as of December 1, 2026. Version 3 also has profiles for Codex, OpenCode, Grok CLI and Kimi CLI. Upstream, it speaks OpenAI Chat and Responses, Anthropic Messages and Gemini, with presets for OpenRouter, DeepSeek, Moonshot, Z.AI and custom endpoints.

That translation is the point. Claude Code sends Anthropic Messages requests, many cheap or open models only expose an OpenAI-compatible API, and CCR converts between the two.

Schema: Claude Code calls the CCR gateway on port 3456, which routes to OpenRouter, DeepSeek, Z.AI or a local model

Do you need a router at all?

You don’t need CCR if you only want one provider that already speaks Anthropic Messages. Several do, and Claude Code reads two environment variables to reach them:

Provider ANTHROPIC_BASE_URL Router needed?
DeepSeek https://api.deepseek.com/anthropic No
Z.AI (GLM Coding Plan) https://api.z.ai/api/anthropic No
OpenRouter https://openrouter.ai/api No, for one model
OpenAI-only APIs, local servers none Yes
Several providers, per-task models, fallbacks none Yes

For DeepSeek, the official Anthropic API guide shows the whole setup:

export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
export ANTHROPIC_API_KEY=<your DeepSeek key>
claude

OpenRouter’s Claude Code guide uses ANTHROPIC_AUTH_TOKEN for your OpenRouter key instead. Z.AI’s Claude Code page does the same with ANTHROPIC_AUTH_TOKEN and maps each Claude tier to a GLM model through ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL and ANTHROPIC_DEFAULT_HAIKU_MODEL. If that covers you, stop here and skip the router.

Reach for CCR when you want:

  1. A provider with no Anthropic-compatible endpoint.
  2. Different models for different jobs.
  3. Retries and failover when a provider rate-limits you.
  4. Request logs with tokens, latency and estimated cost.
  5. One place to manage keys for several agents.

How to set up Claude Code Router

The README recommends the desktop app (macOS, Windows, Linux). The npm CLI runs the same gateway with a browser UI, which suits servers and SSH sessions, and needs Node.js 22 or newer.

node --version          # must be 22 or newer
npm install -g @musistudio/claude-code-router@latest
ccr ui                  # starts the service and opens the management UI

On a headless machine, run ccr ui --no-open and open the URL it prints. Two ports matter:

Then work through the UI in this order:

  1. Providers, Add Provider. Pick a preset (OpenRouter, DeepSeek, Z.AI, Moonshot) or a custom endpoint, paste your key, and let CCR detect the protocol and models. Click Check Connection before you save. It sends a real, short request, so it costs a few tokens.
  2. Server, Start. This brings the gateway up on port 3456.
  3. Agent Config, Add profile, Claude Code. Name it, for example Claude Code - Work, and choose a default model such as OpenRouter/z-ai/glm-5.3.
  4. Launch it. Run the profile from your terminal:
ccr "Claude Code - Work"
# pass Claude Code's own flags after --
ccr "Claude Code - Work" cli -- --model sonnet

Inside Claude Code, type /model to list every model CCR exposes and switch between them.

What changed from older guides. Older tutorials, including our walkthrough on using Claude Code with OpenRouter, hand-edit a config.json and start Claude Code with ccr code. Version 3 keeps settings in config.sqlite under ~/.claude-code-router, and the CLI reference warns against editing it while CCR runs. Use the UI, and Settings, Export data for backups.

Route GLM, DeepSeek and Kimi by task

Claude Code picks a model tier per request, and a CCR profile points each tier at a different provider model.

Claude Code tier What it does Example CCR model
Opus Planning, hard reasoning OpenRouter/deepseek/deepseek-v4-pro
Sonnet Main coding loop OpenRouter/z-ai/glm-5.3
Haiku Small, fast background calls a cheap flash model
Subagents Spawned Task and Agent runs chosen from your model descriptions

The model IDs above were listed by OpenRouter’s public models API on December 1, 2026. Swap in whatever your account can call.

Schema: a CCR profile maps the Opus, Sonnet and Haiku tiers and subagents to different models

The subagent row is new in version 3. On the Models page, give a model a Description such as “Good for code search, file triage, summaries and small edits.” CCR then injects your described models into Claude Code’s Agent and Task tool descriptions. When Claude Code spawns a subagent, it tags the prompt with <CCR-SUBAGENT-MODEL>provider/model</CCR-SUBAGENT-MODEL>, and CCR strips the tag and routes that request to the tagged model. Leave every description empty and CCR injects nothing.

For anything finer, add custom rules on the Routing page. A rule matches on a request header or body field, rewrites parameters such as the model, and the first enabled match wins. When one condition isn’t enough, a rule can run a local Node.js script that returns the model, rewrites and fallback chain. The routing docs cover the script API.

Set retries and fallbacks

Cheap providers rate-limit. CCR’s Default on failure setting, plus a per-rule On failure override, decides what happens next:

Between attempts, CCR honors a provider’s Retry-After header. Without one, it backs off exponentially from 1 second, capped at 30 seconds per attempt.

Sequence diagram: CCR gets a 429 from the primary model, backs off, then answers from the fallback model

Turn on Settings, Logs and Observability before you trust a setup. Each request log shows the requested model, the resolved provider and model, status, tokens, latency and an estimated cost. Regular logs only cover the current day, so they’re for debugging, not audits.

Check your route targets with Apidog CLI

Router configs fail in boring ways: a renamed model ID, a moved endpoint, a key that never reached the gateway. Let your coding agent check the targets with Apidog CLI. Set it up once:

npm install -g apidog-cli@latest
apidog login --with-token <YOUR_TOKEN>
npx -y skills add https://apidog.com   # pick Claude Code when prompted

Then give Claude Code one prompt:

Create an Apidog test scenario in project <id> called "Claude Code Router pre-flight".
Step 1: GET https://openrouter.ai/api/v1/models and assert z-ai/glm-5.3,
deepseek/deepseek-v4-pro and moonshotai/kimi-k3 are listed.
Steps 2 and 3: POST a Messages request with no key to DeepSeek's Anthropic endpoint
and to OpenRouter's Messages endpoint, and assert a 401 in the Anthropic error shape.
Run it and tell me which route target failed.

The agent reads the payload schema, validates it, creates the scenario and runs it:

apidog cli-schema get test-scenario-create
apidog test-scenario create --project <id> --name "Claude Code Router pre-flight" --folder-id 0 --priority 1
apidog cli-schema validate test-scenario-update --file steps.json
apidog test-scenario update <scenarioId> --project <id> --file steps.json
apidog run -t <scenarioId> --project <id> -e <envId> -r cli

Here is that run against live endpoints. All eight assertions pass, which tells you the three model IDs exist and both Messages endpoints answer in the format Claude Code expects:

Apidog CLI run of the Claude Code Router pre-flight scenario: three model IDs listed, two Messages endpoints up, 8 of 8 assertions pass

Once your gateway runs, add a fourth step that sends a real Messages request to http://127.0.0.1:3456 with your CCR client key, and run the same apidog run with -r junit in CI. The Apidog CLI in Claude Code guide and the apidog run reference cover the flags.

If your team runs several of these agents at once, Sharkly is a board where you hand coding work out as tasks to the agents on your own computers (Claude Code, Codex, OpenCode and others on your own plans), run them in parallel and review what they ship before it merges. It’s free to start.

Troubleshooting Claude Code Router

Requests skip CCR. A Claude Code you open directly ignores CCR unless the profile’s scope is System default. Launch it with ccr "<profile>", or switch the scope.

/model shows no CCR models. You haven’t saved a provider with at least one model, or the gateway isn’t started. Check the Server page.

Startup fails silently. Run ccr serve instead of ccr ui. It stays in the foreground and prints errors to the terminal.

Tool calls break on a cheap model. Keep the main coding loop on a stronger model and send only search or summary subagents to the cheap one.

Conclusion

Claude Code Router turns Claude Code into a front end for any model you can reach. Skip it if one Anthropic-compatible endpoint covers you; use it for per-tier routing, subagent models, fallbacks and request logs. Check your route targets with Apidog CLI and read the first day of logs before you trust it. For more ways to reach these models, see our list of OpenRouter alternatives.

FAQ

Is Claude Code Router free? Yes. CCR is open source under the MIT license, and the desktop app and npm CLI cost nothing. You still pay each provider for the tokens your requests use.

What is the default Claude Code Router port? The model gateway listens on 127.0.0.1:3456 and the management UI on 127.0.0.1:3458. If 3458 is busy, CCR picks the next free port and prints the real URL.

Does Claude Code Router still use config.json? Not in version 3. Settings live in config.sqlite under ~/.claude-code-router (%APPDATA%\claude-code-router on Windows), and you change them in the UI. Guides that edit config.json describe earlier versions.

Can I run Claude Code with GLM or DeepSeek without CCR? Yes. Both DeepSeek and Z.AI publish Anthropic-compatible endpoints, so setting ANTHROPIC_BASE_URL and your key is enough for a single provider. Use CCR when you need several providers, routing or fallbacks.

Does CCR work with Codex and OpenCode too? Yes. Version 3 ships Agent Config profiles for Codex, OpenCode, Grok CLI, Kimi CLI and others, so one gateway can serve all your agents with the same providers and keys.

Explore more

MCP Skills: How MCP Servers Deliver Agent Skills (and What You Now Approve)

MCP Skills: How MCP Servers Deliver Agent Skills (and What You Now Approve)

MCP servers can now ship Agent Skills next to their tools. See how skills/list and digests work, which clients support it, and how to catch a skill that changed.

30 November 2026

Antigravity Quota: Why ACP Custom Agents Burn 4x Per Token

Antigravity Quota: Why ACP Custom Agents Burn 4x Per Token

Since Antigravity CLI 1.5.17, custom agents draw about 4x the Gemini quota per token. See the evidence, measure your own burn, and switch to setups that bill at the standard rate.

30 November 2026

How to Fix a Leaked API Key: Revoke, Rotate and Verify

How to Fix a Leaked API Key: Revoke, Rotate and Verify

A provider-neutral runbook for a leaked API key: revoke first, rotate without downtime, read the usage logs, clean Git history and prove the old key returns 401.

30 November 2026

Practice API Design-first in Apidog

Discover an easier way to build and use APIs

Claude Code Router: How to Run Claude Code With Any Model