Claude Code Router - Complete Documentation
Version : 2.4.0
Date : 2026-02-15
Purpose : Multi-provider AI routing through Claude Code with intent-based selection
Overview
Architecture
Supported Providers
Routing Strategy
Installation
Configuration Details
Intent Router Logic
Usage Guide
Troubleshooting
API Key Setup Guide
Claude Code Router acts as a proxy that intercepts Claude Code CLI requests and routes them to different AI providers based on intent analysis. This provides:
Cost Optimization : Simple tasks route to cheaper models
Performance Optimization : Quick responses use fast models
Capability Optimization : Each task uses the most suitable model
Single Interface : Access all models through Claude Code
┌─────────────────┐
│ Claude Code │
│ (CLI/UI) │
└────────┬────────┘
│ localhost:3456
▼
┌─────────────────┐
│ Claude Code │
│ Router │
│ (Proxy Server) │
└────────┬────────┘
│
┌────┴────┐
▼ ▼
┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────────┐ ┌───────────┐
│OpenAI │ │Anthro │ │Gemini │ │ Qwen │ │ GLM │ │OpenRouter │ │ Copilot │
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └───────────┘ └───────────┘
User sends request to Claude Code
Request goes to localhost:3456 (router)
Router analyzes intent using smart-intent-router.js
Request is routed to appropriate provider
Response is returned to user
Feature
Value
API URL
https://api.openai.com/v1/chat/completions
Models
gpt-4o, gpt-4-turbo, gpt-4o-mini, o1, o1-mini
Use Case
Coding, debugging, refactoring
Cost
Medium-High
Env Var
OPENAI_API_KEY
Feature
Value
API URL
https://api.anthropic.com/v1/messages
Models
claude-sonnet-4-latest, claude-3-5-sonnet-latest
Use Case
Deep reasoning, architecture, analysis
Cost
High
Env Var
ANTHROPIC_API_KEY
Transformer
Anthropic (required)
Feature
Value
API URL
https://generativelanguage.googleapis.com/v1beta/openai/chat/completions
Models
gemini-2.5-flash, gemini-2.5-pro, gemini-2.0-flash
Use Case
Fast responses, long context (1M token)
Cost
Low-Medium
Env Var
GEMINI_API_KEY
Transformer
gemini (required)
4. Alibaba Qwen (DashScope)
Feature
Value
API URL
https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions
Models
qwen-plus, qwen-max, qwen3-coder-plus, qwen-turbo
Use Case
Cheap coding, simple tasks
Cost
Very Low
Env Var
QWEN_API_KEY
Feature
Value
API URL
https://api.z.ai/api/anthropic (Coding Plan) / https://api.z.ai/api/paas/v4 (API Credits)
Models
glm-5 (recommended for max users), glm-4.7 (default for Pro)
Use Case
Multilingual, Chinese, translation
Cost
Low (Pro: 3x usage)
Env Var
GLM_API_KEY
Alias
Endpoint
Model
Use Case
glm
api.anthropic
GLM-4.7
Coding Plan (Pro)
glm5
api.anthropic
GLM-5
Coding Plan (Max)
glmapi
api/paas/v4
GLM-5
API Credits (pay-per-use)
Feature
Value
API URL
https://openrouter.ai/api/v1/chat/completions
Models
All models (Claude, GPT, Gemini, Llama, DeepSeek...)
Use Case
Fallback, variety
Cost
Variable
Env Var
OPENROUTER_API_KEY
Transformer
openrouter (required)
Feature
Value
API URL
Custom implementation
Models
copilot
Use Case
Coding assistance, IntelliSense
Cost
Low (with subscription)
Env Var
GITHUB_COPIOT_API_KEY
Automatic Intent-Based Routing
Intent
Trigger Words
Provider
Model
CODING
implement, refactor, debug, fix, code, function, class, typescript, python, api, database
OpenAI
gpt-4o
REASONING
architect, design, analyze, plan, why, explain, compare, evaluate, best practice
Anthropic
claude-sonnet-4
FAST
fast, quick, brief, summary, tldr, overview, scan, check
Gemini
gemini-2.5-flash
SIMPLE
list, show, what is, simple, basic, help, format, rename, mkdir
Qwen
qwen-plus
MULTILINGUAL
translate, translate, multilingual, Chinese characters
GLM
glm-5
HEAVY_REASONING
complex algorithm, optimization, performance critical, prove, mathematical
OpenAI
o1
CODING_ASSIST
help me code, fix this error, suggest improvement, refactor
GitHub Copilot
copilot
Scenario
Provider
Model
Description
default
OpenAI
gpt-4o
When no match
background
Qwen
qwen-turbo
Background tasks
think
Anthropic
claude-sonnet-4
Reasoning tasks
longContext
Gemini
gemini-2.5-flash
>60K tokens
Node.js 18+
pnpm (preferred) or npm
Option 1: Homebrew (Recommended)
brew install halilertekin/tap/claude-code-router-config
The Homebrew installation handles everything automatically:
Copies configuration files
Creates ~/.env with templates
Provides next-step instructions
pnpm add -g @halilertekin/claude-code-router-config
ccr-setup
Option 3: Manual Installation
pnpm add -g @halilertekin/claude-code-router-config
mkdir -p ~ /.claude-code-router
Step 2: Environment Variables
Option 1: Create .env file:
cp .env.example ~ /.env
# Edit ~/.env with your API keys
Option 2: Add to ~/.zshrc or ~/.bashrc:
# ═══════════════════════════════════════════════════
# Claude Code Router - API Keys
# ═══════════════════════════════════════════════════
export OPENAI_API_KEY=" sk-..."
export ANTHROPIC_API_KEY=" sk-ant-..."
export GEMINI_API_KEY=" AIza..."
export QWEN_API_KEY=" sk-..."
export GLM_API_KEY=" ..."
export OPENROUTER_API_KEY=" sk-or-..."
export GITHUB_COPIOT_API_KEY=" ghu_..."
# Router Connection
export ANTHROPIC_BASE_URL=" http://127.0.0.1:3456"
export NO_PROXY=" 127.0.0.1"
{
"LOG" : true , // Enable logging
"LOG_LEVEL" : " info" , // Log level: fatal|error|warn|info|debug|trace
"API_TIMEOUT_MS" : 300000 , // 5 minute timeout
"CUSTOM_ROUTER_PATH" : " $HOME/.claude-code-router/smart-intent-router.js" ,
"Providers" : [
{
"name" : " provider_name" , // Unique name
"api_base_url" : " https://..." , // API endpoint
"api_key" : " $ENV_VAR" , // Environment variable reference
"models" : [" model1" , " model2" ], // Supported models
"transformer" : { "use" : [] } // Required transformers
}
],
"Router" : {
"default" : " provider,model" , // Default route
"background" : " provider,model" , // Background tasks
"think" : " provider,model" , // Reasoning tasks
"longContext" : " provider,model" , // Long context
"longContextThreshold" : 60000 // Token threshold
}
}
Transformer
Usage
Anthropic
Anthropic API format
gemini
Google Gemini API format
openrouter
OpenRouter API format
deepseek
DeepSeek models
maxtoken
Max token limit setting
Request arrives
Message content is extracted (user + system messages)
Pattern matching is counted for each intent
Intent with highest score is selected
Request is routed to relevant provider
HEAVY_REASONING - Complex algorithms
CODING - Code writing/debugging
CODING_ASSIST - Coding help
REASONING - Analysis/explanation
MULTILINGUAL - Translation
FAST - Quick responses
SIMPLE - Simple tasks
Edit smart-intent-router.js to:
Add new intents
Modify patterns
Update routes
# Start router
ccr start
# Start with Claude Code
ccr code
# Check status
ccr status
# Stop router
ccr stop
# Restart router
ccr restart
# Open web UI
ccr ui
# Model selection interface
ccr model
Inside Claude Code using /model command:
/model openai,gpt-4o
/model openai,o1
/model anthropic,claude-sonnet-4-latest
/model gemini,gemini-2.5-flash
/model gemini,gemini-2.5-pro
/model qwen,qwen-plus
/model qwen,qwen3-coder-plus
/model glm,glm-5
/model openrouter,deepseek/deepseek-chat
/model copilot,copilot
# Coding → OpenAI gpt-4o
claude " Write a Python function to implement merge sort"
# Deep Analysis → Anthropic Claude
claude " Analyze the trade-offs between microservices and monolith architecture"
# Quick Summary → Gemini Flash
claude " Give me a quick summary of GraphQL vs REST"
# Simple Task → Qwen
claude " List all TypeScript files in src directory"
# Translation → GLM
claude " Translate this to Chinese: Hello, how are you?"
# Complex Algorithm → OpenAI O1
claude " Design an optimal caching algorithm for a distributed system"
# Coding Assistance → GitHub Copilot
claude " Help me debug this React component error"
# All logs
tail -f ~ /.claude-code-router/logs/* .log
# Only routing decisions
tail -f ~ /.claude-code-router/logs/* .log | grep " Router"
# Check if port is in use
lsof -i :3456
# Kill if needed
kill -9 < PID>
# Restart
ccr start
Check API keys:
echo $OPENAI_API_KEY
echo $ANTHROPIC_API_KEY
# ... others
Test API key:
curl https://api.openai.com/v1/models \
-H " Authorization: Bearer $OPENAI_API_KEY "
Check model names in config.json:
OpenAI: gpt-4o (not gpt-4-o)
Anthropic: claude-sonnet-4-latest
Gemini: gemini-2.5-flash
Check custom router loaded:
cat ~ /.claude-code-router/config.json | grep CUSTOM_ROUTER
Check router file exists:
ls -la ~ /.claude-code-router/smart-intent-router.js
Check for syntax errors:
node -c ~ /.claude-code-router/smart-intent-router.js
Go to https://platform.openai.com/api-keys
Click "Create new secret key"
Copy key (starts with sk-...)
Go to https://console.anthropic.com/settings/keys
Click "Create Key"
Copy key (starts with sk-ant-...)
Go to https://aistudio.google.com/apikey
Click "Create API Key"
Copy key (starts with AIza...)
Go to https://dashscope.console.aliyun.com/apiKey
Create Aliyun account (international)
Get API key
Go to https://open.bigmodel.cn/usercenter/apikeys
Create account
Get API key
Go to https://openrouter.ai/keys
Sign in with GitHub/Google
Click "Create Key"
Copy key (starts with sk-or-...)
Go to https://github.com/settings/tokens
Generate new token
Select copilot scope
Copy token (starts with ghu_...)
~/.claude-code-router/
├── config.json # Main configuration
├── smart-intent-router.js # Custom routing logic
├── README.md # Quick documentation
├── FULL_DOCUMENTATION.md # This file
└── logs/ # Log files
└── *.log
Router always runs on localhost:3456
ANTHROPIC_BASE_URL enables Claude Code to connect to router
NO_PROXY prevents system proxy from blocking router
Environment variables can be used in config.json with $VAR_NAME format