Run Claude Code with any model via OpenRouter — including forked, leaked, and unreleased Claude versions.
This guide shows how to use Claude Code Router (CCR) to route Claude Code traffic through OpenRouter, enabling:
- Use any OpenRouter model with Claude Code's interface
- Free tier models like Qwen 3.6 Plus, Gemma 4, DeepSeek R1
- Bypass Claude Code's model validation which blocks unknown model names
- Custom transformers for memory injection, prompt modification, etc.
Claude Code validates model names against a known list. If you want to use:
- Open-source models not in Claude's whitelist
- Forked Claude Code versions with modified behavior
- Custom providers like Ollama, LiteLLM, or private endpoints
...you need CCR to act as middleware that translates between Claude Code's API and your provider.
npm install -g @musistudio/claude-code-routerCCR needs a claude command. If your Claude Code binary is named differently:
# Find your Claude Code binary
which claude-code
# Create symlink (adjust path as needed)
ln -sf /path/to/claude-code ~/bin/claudeCreate ~/.claude-code-router/config.json:
{
"Providers": [{
"name": "openrouter",
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
"api_key": "sk-or-v1-YOUR-KEY-HERE",
"models": [
"qwen/qwen3.6-plus:free",
"qwen/qwen3.5-flash-02-23",
"google/gemma-4-26b-a4b-it"
],
"transformer": { "use": ["openrouter"] }
}],
"Router": {
"default": "openrouter,qwen/qwen3.6-plus:free"
},
"LOG_LEVEL": "info"
}ccr startccr codeInside Claude Code, switch models with:
/model openrouter,qwen/qwen3.6-plus:free
/model openrouter,google/gemma-4-26b-a4b-it
| Model | Provider | Context | Notes |
|---|---|---|---|
qwen/qwen3.6-plus:free |
Alibaba | 1M | Best free model, SWE-bench 78.8 |
qwen/qwen3.5-flash-02-23 |
Alibaba | 32K | Fast, good for daily tasks |
google/gemma-4-26b-a4b-it |
256K | Multimodal, strong reasoning | |
deepseek/deepseek-r1-distill-qwen-32b |
DeepSeek | 32K | Strong reasoning |
CCR supports multiple providers. To add DeepSeek, Ollama, or others:
{
"Providers": [
{
"name": "deepseek",
"api_base_url": "https://api.deepseek.com/v1",
"api_key": "sk-YOUR-KEY",
"models": ["deepseek-chat"]
}
],
"Router": {
"default": "openrouter,qwen/qwen3.6-plus:free"
}
}Then switch with:
/model deepseek,deepseek-chat
CCR supports custom transformers for request/response modification. Example: inject memory context.
Create ~/.claude-code-router/transformers/memory-transformer.js:
class MemoryTransformer {
name = "memory";
async transformRequestIn(request) {
// Call your memory service
const resp = await fetch('http://localhost:8765/context/inject', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: request.messages?.find(m => m.role === 'user')?.content || '',
entity: 'user',
max_tokens: 8000
})
});
const data = await resp.json();
if (data?.context) {
request.messages.unshift({
role: 'system',
content: data.context + '\n\n[End of memory context]'
});
}
return request;
}
}
module.exports = MemoryTransformer;Add to config:
{
"transformers": [
{ "path": "/home/user/.claude-code-router/transformers/memory-transformer.js" }
],
"Providers": [{
"name": "openrouter",
"transformer": { "use": ["openrouter", "memory"] }
// ...
}]
}If you see Both a token (ANTHROPIC_AUTH_TOKEN) and an API key (ANTHROPIC_API_KEY) are set:
unset ANTHROPIC_API_KEYClaude Code may still validate some model names. Use the exact format:
/model openrouter,qwen/qwen3.6-plus:free
# Verify symlink exists
ls -la ~/bin/claude
# If not, create it
ln -sf $(which claude-code) ~/bin/claude┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Claude Code │────▶│ CCR Server │────▶│ OpenRouter │
│ (CLI) │◀────│ (port 3456) │◀────│ API │
└─────────────┘ └──────┬──────┘ └─────────────┘
│
┌──────▼──────┐
│ Transformers │
│ (memory, │
│ etc.) │
└─────────────┘
This is a guide, not a software project. CCR is by @musistudio. OpenRouter models have their own licenses.
PRs welcome for:
- Additional provider configs
- More transformer examples
- Troubleshooting tips