- Claude Code has built-in model routing via
opusplan— Opus for planning, Sonnet for execution, saving significantly on costs while keeping high-quality reasoning where it matters. - The community
claude-code-routerproject lets you route Claude Code requests to alternative providers like OpenRouter, DeepSeek, Ollama, and Gemini. opusplanis one flag away:claude --model opusplan- Community router requires a proxy install but unlocks hundreds of models from dozens of providers.
Claude Code Router refers to two distinct things in 2026: Anthropic's built-in model routing system and an open-source community proxy tool. The built-in routing is a feature called opusplan — a model alias that automatically uses Claude Opus 4.6 for planning and reasoning, then switches to Claude Sonnet 4.6 for code execution. This gives you Opus-quality thinking on architectural decisions while keeping costs lower on implementation work. The community tool, claude-code-router by @musistudio, is a local proxy with 28k+ GitHub stars that intercepts Claude Code's API requests and routes them to alternative providers — OpenRouter, DeepSeek, Ollama (local models), Google Gemini, and more. Both approaches solve the same core problem: getting the right model for the right task at the right price.
This guide covers both in detail — how to configure the built-in routing, how to set up the community router, and when to use each.
What Is Claude Code Router?
"Claude Code Router" maps to two distinct concepts:
- Built-in model routing (
opusplan) — an official Anthropic feature that automatically switches between Claude models depending on whether you're planning or executing. No extra tools needed. - Community proxy (
claude-code-router) — an open-source project that acts as a local API proxy, letting you use Claude Code's interface with non-Anthropic models from providers like OpenRouter, DeepSeek, and Ollama.
Both are "routing" in the sense that they direct your requests to different models. The built-in version routes between Anthropic models. The community version routes to any provider you configure.
Built-In Model Routing (opusplan)
opusplan is a model alias built into Claude Code that provides automatic hybrid routing between two models based on your current mode:
- Plan mode — uses Opus 4.6 for deep reasoning, architecture decisions, and complex analysis
- Execution mode — switches to Sonnet 4.6 for code generation, file edits, and command execution
The logic is simple: planning benefits from the most capable model (Opus), while code generation is well-served by the faster, cheaper model (Sonnet). Since most of a session's tokens go toward execution, you get significant cost savings without sacrificing reasoning quality on the decisions that matter most.
All available model aliases in Claude Code:
| Alias | Behavior |
|---|---|
default |
Depends on subscription tier (Max/Premium = Opus, Pro/Standard = Sonnet) |
sonnet |
Latest Sonnet model (currently Sonnet 4.6) |
opus |
Latest Opus model (currently Opus 4.6) |
haiku |
Fast, efficient model for simple tasks |
sonnet[1m] |
Sonnet with 1 million token context window |
opusplan |
Opus during plan mode, Sonnet during execution |
Aliases always point to the latest model version. To pin a specific version, use the full model ID (e.g., claude-opus-4-6).
How to Configure Model Routing
There are four ways to set your model in Claude Code, listed from highest to lowest priority:
Method 1: Mid-session command
Type /model opusplan during any session to switch immediately. Use /model by itself to see your current model and browse options.
Method 2: CLI flag at startup
claude --model opusplan
This sets the model for the entire session.
Method 3: Environment variable
export ANTHROPIC_MODEL=opusplan
Add this to your shell profile (~/.zshrc or ~/.bashrc) to make it persistent.
Method 4: Settings file
Edit ~/.claude/settings.json:
{
"model": "opusplan"
}
The priority order determines which method wins when multiple are set:
| Priority | Method | Scope |
|---|---|---|
| 1 (highest) | /model command |
Current session only |
| 2 | claude --model flag |
Current session only |
| 3 | ANTHROPIC_MODEL env var |
Shell session |
| 4 (lowest) | settings.json |
All sessions |
You can also pin what each alias resolves to using environment variables:
ANTHROPIC_DEFAULT_OPUS_MODEL— whatopusandopusplan(plan mode) resolve toANTHROPIC_DEFAULT_SONNET_MODEL— whatsonnetandopusplan(execution mode) resolve toANTHROPIC_DEFAULT_HAIKU_MODEL— whathaikuand background tasks resolve to
Claude Code Router (Community Project)
claude-code-router is an open-source proxy (MIT license) by @musistudio with 28k+ GitHub stars. It solves a specific problem: Claude Code only supports Anthropic models natively. The community router intercepts Claude Code's API requests and routes them to any compatible provider.
How it works:
- The router starts a local Express.js server (default port 3456)
- It sets
ANTHROPIC_BASE_URLto point at the local server - Claude Code sends API requests to the router instead of Anthropic
- The router transforms the request format and forwards it to your configured provider
- Responses stream back through the router to Claude Code
Supported providers include:
- OpenRouter — access to hundreds of models from multiple providers
- DeepSeek — deepseek-chat, deepseek-reasoner
- Google Gemini — gemini-2.5-flash, gemini-2.5-pro
- Ollama — any local model (Qwen, Llama, Mistral, etc.)
- Groq — fast inference for supported models
- Anthropic — native passthrough (useful for mixing providers)
- Volcengine, SiliconFlow, ModelScope, DashScope, AIHubMix
How to Set Up Claude Code Router
Step 1: Install
npm install -g @musistudio/claude-code-router
This installs the ccr command globally. You need Claude Code installed first (npm install -g @anthropic-ai/claude-code).
Step 2: Configure
Create ~/.claude-code-router/config.json with your providers and routing rules:
{
"Providers": [
{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "$OPENROUTER_API_KEY",
"models": ["anthropic/claude-sonnet-4", "google/gemini-2.5-pro"],
"transformer": { "use": ["openrouter"] }
},
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/chat/completions",
"api_key": "$DEEPSEEK_API_KEY",
"models": ["deepseek-chat", "deepseek-reasoner"],
"transformer": { "use": ["deepseek"] }
},
{
"name": "ollama",
"api_base_url": "http://localhost:11434/v1/chat/completions",
"api_key": "ollama",
"models": ["qwen2.5-coder:latest"]
}
],
"Router": {
"default": "deepseek,deepseek-chat",
"think": "openrouter,anthropic/claude-sonnet-4",
"background": "ollama,qwen2.5-coder:latest"
}
}
API keys can reference environment variables with $VAR_NAME syntax for secure key management.
Step 3: Run
The simplest way — start the router and launch Claude Code in one command:
ccr code
Or manage the service separately:
# Start the router in the background
ccr start
# Export environment variables for Claude Code
eval "$(ccr activate)"
# Run Claude Code normally — requests route through the proxy
claude
Context-aware routing
The Router config supports task-type routing. Each rule maps to a "provider,model" string:
| Rule | When it applies |
|---|---|
default |
All general requests |
think |
Complex reasoning tasks (extended thinking) |
background |
Background and lightweight tasks |
longContext |
When token count exceeds longContextThreshold |
webSearch |
Web search tasks |
This lets you use a cheap local model for background tasks, a reasoning-focused model for complex thinking, and a large-context model when your session grows — all automatically.
opusplan vs Claude Code Router: Which Should You Use?
| Criteria | opusplan (built-in) | claude-code-router (community) |
|---|---|---|
| Setup | Zero — one flag or command | Install proxy + configure providers |
| Models available | Anthropic only (Opus, Sonnet, Haiku) | Hundreds (OpenRouter, DeepSeek, Ollama, Gemini, etc.) |
| Routing logic | Plan mode = Opus, execution = Sonnet | Context-aware: default, think, background, longContext |
| Reliability | Official, supported by Anthropic | Community-maintained, MIT license |
| Local models | No | Yes (via Ollama) |
| Cost control | Saves on execution tokens | Full control — use free/cheap models for any task type |
| Tool compatibility | Full Claude Code feature support | Depends on model — some don't support all features |
Use opusplan if you want the simplest path to cost-optimized Claude Code usage with zero setup and full feature compatibility. It's one command and it works.
Use the community router if you want to use non-Anthropic models, run local models via Ollama, or need fine-grained control over which model handles which type of task.
Can you use both? Not directly — the community router overrides ANTHROPIC_BASE_URL, which bypasses Anthropic's API entirely. But you can configure the community router to use Anthropic as one of its providers alongside others, effectively recreating opusplan-style routing with additional providers mixed in.
Tips for Cost-Effective Claude Code Usage
opusplanfor best quality-to-cost ratio — Opus-quality reasoning on architecture decisions, Sonnet efficiency on implementation. This is the recommended starting point for most developers.- Haiku for quick tasks — use
claude --model haikufor simple questions, quick edits, and boilerplate generation. Haiku is significantly cheaper than both Opus and Sonnet. - Community router + cheap models for boilerplate — route background tasks to DeepSeek or local Ollama models. Save Anthropic credits for work that needs Claude's reasoning.
- Monitor your usage — use the
/costcommand in Claude Code to see token consumption and spending for your current session. - Plan before executing — enter plan mode (
Shift+Tabtwice) to think through your approach before the model starts generating code. Better plans mean fewer wasted iterations.
For extending Claude Code's capabilities beyond model routing, browse available skills on PolySkill — portable packages that add coding standards, workflow automations, and specialized prompts to your sessions.
Related: How to Add Skills to Claude Code (2026) | Codex vs Claude Code: Full Comparison (2026) | Claude Code vs Cursor: Full Comparison (2026)
Frequently Asked Questions
What is Claude Code Router?
Claude Code Router refers to two things: (1) built-in model routing via the opusplan alias, which uses Opus for planning and Sonnet for execution to optimize cost; and (2) the open-source claude-code-router proxy by @musistudio, which lets you route Claude Code requests to alternative providers like OpenRouter, DeepSeek, Ollama, and Gemini.
How do I switch models in Claude Code?
Four ways, in priority order: (1) mid-session with /model <alias>, (2) at startup with claude --model <alias>, (3) via the ANTHROPIC_MODEL environment variable, (4) in ~/.claude/settings.json. Available aliases include sonnet, opus, haiku, and opusplan.
Can I use Claude Code with OpenRouter?
Yes, via the community claude-code-router project. Install it with npm install -g @musistudio/claude-code-router, configure your OpenRouter API key and models in ~/.claude-code-router/config.json, then run ccr code. The router proxies requests from Claude Code to OpenRouter, giving you access to hundreds of models.
Is opusplan free?
No. opusplan uses your Anthropic API credits or Claude subscription. It routes to Opus (more expensive) during plan mode and Sonnet (cheaper) during execution. The cost savings come from using the cheaper model for the bulk of code generation work while reserving the more capable model for planning.
Does Claude Code Router support local models?
Yes. The community claude-code-router supports Ollama, which runs models locally on your machine. Configure Ollama as a provider in config.json with api_base_url pointing to http://localhost:11434/v1/chat/completions, and you can route Claude Code requests to any local model like Qwen 2.5 Coder or Llama.