claude-code-router-config 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +27 -0
- package/LICENSE +30 -0
- package/README.md +148 -0
- package/config/config.json +67 -0
- package/config/intent-router.js +108 -0
- package/docs/FULL_DOCUMENTATION.md +489 -0
- package/docs/FULL_DOCUMENTATION_EN.md +505 -0
- package/docs/README_EN.md +146 -0
- package/docs/SETUP_PROMPT.md +299 -0
- package/docs/SETUP_PROMPT_EN.md +317 -0
- package/install.js +160 -0
- package/install.sh +73 -0
- package/package.json +59 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
# Claude Code Router - Complete Documentation
|
|
2
|
+
|
|
3
|
+
> **Version**: 1.0.73
|
|
4
|
+
> **Date**: 2025-12-20
|
|
5
|
+
> **Purpose**: Multi-provider AI routing through Claude Code with intent-based selection
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
1. [Overview](#overview)
|
|
12
|
+
2. [Architecture](#architecture)
|
|
13
|
+
3. [Supported Providers](#supported-providers)
|
|
14
|
+
4. [Routing Strategy](#routing-strategy)
|
|
15
|
+
5. [Installation](#installation)
|
|
16
|
+
6. [Configuration Details](#configuration-details)
|
|
17
|
+
7. [Intent Router Logic](#intent-router-logic)
|
|
18
|
+
8. [Usage Guide](#usage-guide)
|
|
19
|
+
9. [Troubleshooting](#troubleshooting)
|
|
20
|
+
10. [API Key Setup Guide](#api-key-setup-guide)
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
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:
|
|
27
|
+
|
|
28
|
+
- **Cost Optimization**: Simple tasks route to cheaper models
|
|
29
|
+
- **Performance Optimization**: Quick responses use fast models
|
|
30
|
+
- **Capability Optimization**: Each task uses the most suitable model
|
|
31
|
+
- **Single Interface**: Access all models through Claude Code
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Architecture
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
┌─────────────────┐
|
|
39
|
+
│ Claude Code │
|
|
40
|
+
│ (CLI/UI) │
|
|
41
|
+
└────────┬────────┘
|
|
42
|
+
│ localhost:3456
|
|
43
|
+
▼
|
|
44
|
+
┌─────────────────┐
|
|
45
|
+
│ Claude Code │
|
|
46
|
+
│ Router │
|
|
47
|
+
│ (Proxy Server) │
|
|
48
|
+
└────────┬────────┘
|
|
49
|
+
│
|
|
50
|
+
┌────┴────┐
|
|
51
|
+
▼ ▼
|
|
52
|
+
┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────────┐ ┌───────────┐
|
|
53
|
+
│OpenAI │ │Anthro │ │Gemini │ │ Qwen │ │ GLM │ │OpenRouter │ │ Copilot │
|
|
54
|
+
└───────┘ └───────┘ └───────┘ └───────┘ └───────┘ └───────────┘ └───────────┘
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Flow
|
|
58
|
+
|
|
59
|
+
1. User sends request to Claude Code
|
|
60
|
+
2. Request goes to `localhost:3456` (router)
|
|
61
|
+
3. Router analyzes intent using `intent-router.js`
|
|
62
|
+
4. Request is routed to appropriate provider
|
|
63
|
+
5. Response is returned to user
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Supported Providers
|
|
68
|
+
|
|
69
|
+
### 1. OpenAI
|
|
70
|
+
| Feature | Value |
|
|
71
|
+
|---------|-------|
|
|
72
|
+
| **API URL** | `https://api.openai.com/v1/chat/completions` |
|
|
73
|
+
| **Models** | gpt-4o, gpt-4-turbo, gpt-4o-mini, o1, o1-mini |
|
|
74
|
+
| **Use Case** | Coding, debugging, refactoring |
|
|
75
|
+
| **Cost** | Medium-High |
|
|
76
|
+
| **Env Var** | `OPENAI_API_KEY` |
|
|
77
|
+
|
|
78
|
+
### 2. Anthropic (Claude)
|
|
79
|
+
| Feature | Value |
|
|
80
|
+
|---------|-------|
|
|
81
|
+
| **API URL** | `https://api.anthropic.com/v1/messages` |
|
|
82
|
+
| **Models** | claude-sonnet-4-latest, claude-3-5-sonnet-latest |
|
|
83
|
+
| **Use Case** | Deep reasoning, architecture, analysis |
|
|
84
|
+
| **Cost** | High |
|
|
85
|
+
| **Env Var** | `ANTHROPIC_API_KEY` |
|
|
86
|
+
| **Transformer** | `Anthropic` (required) |
|
|
87
|
+
|
|
88
|
+
### 3. Google Gemini
|
|
89
|
+
| Feature | Value |
|
|
90
|
+
|---------|-------|
|
|
91
|
+
| **API URL** | `https://generativelanguage.googleapis.com/v1beta/openai/chat/completions` |
|
|
92
|
+
| **Models** | gemini-2.5-flash, gemini-2.5-pro, gemini-2.0-flash |
|
|
93
|
+
| **Use Case** | Fast responses, long context (1M token) |
|
|
94
|
+
| **Cost** | Low-Medium |
|
|
95
|
+
| **Env Var** | `GEMINI_API_KEY` |
|
|
96
|
+
| **Transformer** | `gemini` (required) |
|
|
97
|
+
|
|
98
|
+
### 4. Alibaba Qwen (DashScope)
|
|
99
|
+
| Feature | Value |
|
|
100
|
+
|---------|-------|
|
|
101
|
+
| **API URL** | `https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions` |
|
|
102
|
+
| **Models** | qwen-plus, qwen-max, qwen3-coder-plus, qwen-turbo |
|
|
103
|
+
| **Use Case** | Cheap coding, simple tasks |
|
|
104
|
+
| **Cost** | Very Low |
|
|
105
|
+
| **Env Var** | `QWEN_API_KEY` |
|
|
106
|
+
|
|
107
|
+
### 5. Zhipu GLM (Z.ai)
|
|
108
|
+
| Feature | Value |
|
|
109
|
+
|---------|-------|
|
|
110
|
+
| **API URL** | `https://api.z.ai/api/paas/v4/chat/completions` |
|
|
111
|
+
| **Models** | glm-4.6, glm-4.5, glm-4-plus |
|
|
112
|
+
| **Use Case** | Multilingual, Chinese, translation |
|
|
113
|
+
| **Cost** | Low |
|
|
114
|
+
| **Env Var** | `GLM_API_KEY` |
|
|
115
|
+
|
|
116
|
+
### 6. OpenRouter
|
|
117
|
+
| Feature | Value |
|
|
118
|
+
|---------|-------|
|
|
119
|
+
| **API URL** | `https://openrouter.ai/api/v1/chat/completions` |
|
|
120
|
+
| **Models** | All models (Claude, GPT, Gemini, Llama, DeepSeek...) |
|
|
121
|
+
| **Use Case** | Fallback, variety |
|
|
122
|
+
| **Cost** | Variable |
|
|
123
|
+
| **Env Var** | `OPENROUTER_API_KEY` |
|
|
124
|
+
| **Transformer** | `openrouter` (required) |
|
|
125
|
+
|
|
126
|
+
### 7. GitHub Copilot
|
|
127
|
+
| Feature | Value |
|
|
128
|
+
|---------|-------|
|
|
129
|
+
| **API URL** | Custom implementation |
|
|
130
|
+
| **Models** | copilot |
|
|
131
|
+
| **Use Case** | Coding assistance, IntelliSense |
|
|
132
|
+
| **Cost** | Low (with subscription) |
|
|
133
|
+
| **Env Var** | `GITHUB_COPIOT_API_KEY` |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Routing Strategy
|
|
138
|
+
|
|
139
|
+
### Automatic Intent-Based Routing
|
|
140
|
+
|
|
141
|
+
| Intent | Trigger Words | Provider | Model |
|
|
142
|
+
|--------|----------------|----------|-------|
|
|
143
|
+
| **CODING** | implement, refactor, debug, fix, code, function, class, typescript, python, api, database | OpenAI | gpt-4o |
|
|
144
|
+
| **REASONING** | architect, design, analyze, plan, why, explain, compare, evaluate, best practice | Anthropic | claude-sonnet-4 |
|
|
145
|
+
| **FAST** | fast, quick, brief, summary, tldr, overview, scan, check | Gemini | gemini-2.5-flash |
|
|
146
|
+
| **SIMPLE** | list, show, what is, simple, basic, help, format, rename, mkdir | Qwen | qwen-plus |
|
|
147
|
+
| **MULTILINGUAL** | translate, translate, multilingual, Chinese characters | GLM | glm-4.6 |
|
|
148
|
+
| **HEAVY_REASONING** | complex algorithm, optimization, performance critical, prove, mathematical | OpenAI | o1 |
|
|
149
|
+
| **CODING_ASSIST** | help me code, fix this error, suggest improvement, refactor | GitHub Copilot | copilot |
|
|
150
|
+
|
|
151
|
+
### Built-in Router Settings
|
|
152
|
+
|
|
153
|
+
| Scenario | Provider | Model | Description |
|
|
154
|
+
|----------|----------|-------|-------------|
|
|
155
|
+
| **default** | OpenAI | gpt-4o | When no match |
|
|
156
|
+
| **background** | Qwen | qwen-turbo | Background tasks |
|
|
157
|
+
| **think** | Anthropic | claude-sonnet-4 | Reasoning tasks |
|
|
158
|
+
| **longContext** | Gemini | gemini-2.5-flash | >60K tokens |
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Installation
|
|
163
|
+
|
|
164
|
+
### Requirements
|
|
165
|
+
- Node.js 18+
|
|
166
|
+
- pnpm (preferred) or npm
|
|
167
|
+
|
|
168
|
+
### Step 1: Install Package
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
pnpm add -g @musistudio/claude-code-router
|
|
172
|
+
mkdir -p ~/.claude-code-router
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Step 2: Environment Variables
|
|
176
|
+
|
|
177
|
+
Option 1: Create `.env` file:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
cp .env.example ~/.env
|
|
181
|
+
# Edit ~/.env with your API keys
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Option 2: Add to `~/.zshrc` or `~/.bashrc`:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
# ═══════════════════════════════════════════════════
|
|
188
|
+
# Claude Code Router - API Keys
|
|
189
|
+
# ═══════════════════════════════════════════════════
|
|
190
|
+
export OPENAI_API_KEY="sk-..."
|
|
191
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
192
|
+
export GEMINI_API_KEY="AIza..."
|
|
193
|
+
export QWEN_API_KEY="sk-..."
|
|
194
|
+
export GLM_API_KEY="..."
|
|
195
|
+
export OPENROUTER_API_KEY="sk-or-..."
|
|
196
|
+
export GITHUB_COPIOT_API_KEY="ghu_..."
|
|
197
|
+
|
|
198
|
+
# Router Connection
|
|
199
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
200
|
+
export NO_PROXY="127.0.0.1"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Step 3: Reload Shell
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
source ~/.zshrc
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Step 4: Start
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
ccr code
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Configuration Details
|
|
218
|
+
|
|
219
|
+
### config.json Structure
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"LOG": true, // Enable logging
|
|
224
|
+
"LOG_LEVEL": "info", // Log level: fatal|error|warn|info|debug|trace
|
|
225
|
+
"API_TIMEOUT_MS": 300000, // 5 minute timeout
|
|
226
|
+
"CUSTOM_ROUTER_PATH": "$HOME/.claude-code-router/intent-router.js",
|
|
227
|
+
|
|
228
|
+
"Providers": [
|
|
229
|
+
{
|
|
230
|
+
"name": "provider_name", // Unique name
|
|
231
|
+
"api_base_url": "https://...", // API endpoint
|
|
232
|
+
"api_key": "$ENV_VAR", // Environment variable reference
|
|
233
|
+
"models": ["model1", "model2"], // Supported models
|
|
234
|
+
"transformer": { "use": [] } // Required transformers
|
|
235
|
+
}
|
|
236
|
+
],
|
|
237
|
+
|
|
238
|
+
"Router": {
|
|
239
|
+
"default": "provider,model", // Default route
|
|
240
|
+
"background": "provider,model", // Background tasks
|
|
241
|
+
"think": "provider,model", // Reasoning tasks
|
|
242
|
+
"longContext": "provider,model", // Long context
|
|
243
|
+
"longContextThreshold": 60000 // Token threshold
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Transformers
|
|
249
|
+
|
|
250
|
+
| Transformer | Usage |
|
|
251
|
+
|-------------|-------|
|
|
252
|
+
| `Anthropic` | Anthropic API format |
|
|
253
|
+
| `gemini` | Google Gemini API format |
|
|
254
|
+
| `openrouter` | OpenRouter API format |
|
|
255
|
+
| `deepseek` | DeepSeek models |
|
|
256
|
+
| `maxtoken` | Max token limit setting |
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
## Intent Router Logic
|
|
261
|
+
|
|
262
|
+
### Working Principle
|
|
263
|
+
|
|
264
|
+
1. Request arrives
|
|
265
|
+
2. Message content is extracted (user + system messages)
|
|
266
|
+
3. Pattern matching is counted for each intent
|
|
267
|
+
4. Intent with highest score is selected
|
|
268
|
+
5. Request is routed to relevant provider
|
|
269
|
+
|
|
270
|
+
### Pattern Priority
|
|
271
|
+
|
|
272
|
+
1. **HEAVY_REASONING** - Complex algorithms
|
|
273
|
+
2. **CODING** - Code writing/debugging
|
|
274
|
+
3. **CODING_ASSIST** - Coding help
|
|
275
|
+
4. **REASONING** - Analysis/explanation
|
|
276
|
+
5. **MULTILINGUAL** - Translation
|
|
277
|
+
6. **FAST** - Quick responses
|
|
278
|
+
7. **SIMPLE** - Simple tasks
|
|
279
|
+
|
|
280
|
+
### Customization
|
|
281
|
+
|
|
282
|
+
Edit `intent-router.js` to:
|
|
283
|
+
- Add new intents
|
|
284
|
+
- Modify patterns
|
|
285
|
+
- Update routes
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Usage Guide
|
|
290
|
+
|
|
291
|
+
### Basic Commands
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Start router
|
|
295
|
+
ccr start
|
|
296
|
+
|
|
297
|
+
# Start with Claude Code
|
|
298
|
+
ccr code
|
|
299
|
+
|
|
300
|
+
# Check status
|
|
301
|
+
ccr status
|
|
302
|
+
|
|
303
|
+
# Stop router
|
|
304
|
+
ccr stop
|
|
305
|
+
|
|
306
|
+
# Restart router
|
|
307
|
+
ccr restart
|
|
308
|
+
|
|
309
|
+
# Open web UI
|
|
310
|
+
ccr ui
|
|
311
|
+
|
|
312
|
+
# Model selection interface
|
|
313
|
+
ccr model
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Runtime Model Switching
|
|
317
|
+
|
|
318
|
+
Inside Claude Code using `/model` command:
|
|
319
|
+
|
|
320
|
+
```
|
|
321
|
+
/model openai,gpt-4o
|
|
322
|
+
/model openai,o1
|
|
323
|
+
/model anthropic,claude-sonnet-4-latest
|
|
324
|
+
/model gemini,gemini-2.5-flash
|
|
325
|
+
/model gemini,gemini-2.5-pro
|
|
326
|
+
/model qwen,qwen-plus
|
|
327
|
+
/model qwen,qwen3-coder-plus
|
|
328
|
+
/model glm,glm-4.6
|
|
329
|
+
/model openrouter,deepseek/deepseek-chat
|
|
330
|
+
/model copilot,copilot
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Example Usage Scenarios
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
# Coding → OpenAI gpt-4o
|
|
337
|
+
claude "Write a Python function to implement merge sort"
|
|
338
|
+
|
|
339
|
+
# Deep Analysis → Anthropic Claude
|
|
340
|
+
claude "Analyze the trade-offs between microservices and monolith architecture"
|
|
341
|
+
|
|
342
|
+
# Quick Summary → Gemini Flash
|
|
343
|
+
claude "Give me a quick summary of GraphQL vs REST"
|
|
344
|
+
|
|
345
|
+
# Simple Task → Qwen
|
|
346
|
+
claude "List all TypeScript files in src directory"
|
|
347
|
+
|
|
348
|
+
# Translation → GLM
|
|
349
|
+
claude "Translate this to Chinese: Hello, how are you?"
|
|
350
|
+
|
|
351
|
+
# Complex Algorithm → OpenAI O1
|
|
352
|
+
claude "Design an optimal caching algorithm for a distributed system"
|
|
353
|
+
|
|
354
|
+
# Coding Assistance → GitHub Copilot
|
|
355
|
+
claude "Help me debug this React component error"
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Monitor Logs
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
# All logs
|
|
362
|
+
tail -f ~/.claude-code-router/logs/*.log
|
|
363
|
+
|
|
364
|
+
# Only routing decisions
|
|
365
|
+
tail -f ~/.claude-code-router/logs/*.log | grep "Router"
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## Troubleshooting
|
|
371
|
+
|
|
372
|
+
### Router Not Starting
|
|
373
|
+
|
|
374
|
+
```bash
|
|
375
|
+
# Check if port is in use
|
|
376
|
+
lsof -i :3456
|
|
377
|
+
|
|
378
|
+
# Kill if needed
|
|
379
|
+
kill -9 <PID>
|
|
380
|
+
|
|
381
|
+
# Restart
|
|
382
|
+
ccr start
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### API Errors
|
|
386
|
+
|
|
387
|
+
1. Check API keys:
|
|
388
|
+
```bash
|
|
389
|
+
echo $OPENAI_API_KEY
|
|
390
|
+
echo $ANTHROPIC_API_KEY
|
|
391
|
+
# ... others
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
2. Test API key:
|
|
395
|
+
```bash
|
|
396
|
+
curl https://api.openai.com/v1/models \
|
|
397
|
+
-H "Authorization: Bearer $OPENAI_API_KEY"
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Model Not Found Error
|
|
401
|
+
|
|
402
|
+
Check model names in `config.json`:
|
|
403
|
+
- OpenAI: `gpt-4o` (not `gpt-4-o`)
|
|
404
|
+
- Anthropic: `claude-sonnet-4-latest`
|
|
405
|
+
- Gemini: `gemini-2.5-flash`
|
|
406
|
+
|
|
407
|
+
### Routing Not Working
|
|
408
|
+
|
|
409
|
+
1. Check custom router loaded:
|
|
410
|
+
```bash
|
|
411
|
+
cat ~/.claude-code-router/config.json | grep CUSTOM_ROUTER
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
2. Check router file exists:
|
|
415
|
+
```bash
|
|
416
|
+
ls -la ~/.claude-code-router/intent-router.js
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
3. Check for syntax errors:
|
|
420
|
+
```bash
|
|
421
|
+
node -c ~/.claude-code-router/intent-router.js
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
---
|
|
425
|
+
|
|
426
|
+
## API Key Setup Guide
|
|
427
|
+
|
|
428
|
+
### OpenAI
|
|
429
|
+
1. Go to https://platform.openai.com/api-keys
|
|
430
|
+
2. Click "Create new secret key"
|
|
431
|
+
3. Copy key (starts with `sk-...`)
|
|
432
|
+
|
|
433
|
+
### Anthropic
|
|
434
|
+
1. Go to https://console.anthropic.com/settings/keys
|
|
435
|
+
2. Click "Create Key"
|
|
436
|
+
3. Copy key (starts with `sk-ant-...`)
|
|
437
|
+
|
|
438
|
+
### Google Gemini
|
|
439
|
+
1. Go to https://aistudio.google.com/apikey
|
|
440
|
+
2. Click "Create API Key"
|
|
441
|
+
3. Copy key (starts with `AIza...`)
|
|
442
|
+
|
|
443
|
+
### Alibaba Qwen (DashScope)
|
|
444
|
+
1. Go to https://dashscope.console.aliyun.com/apiKey
|
|
445
|
+
2. Create Aliyun account (international)
|
|
446
|
+
3. Get API key
|
|
447
|
+
|
|
448
|
+
### Zhipu GLM (Z.ai)
|
|
449
|
+
1. Go to https://open.bigmodel.cn/usercenter/apikeys
|
|
450
|
+
2. Create account
|
|
451
|
+
3. Get API key
|
|
452
|
+
|
|
453
|
+
### OpenRouter
|
|
454
|
+
1. Go to https://openrouter.ai/keys
|
|
455
|
+
2. Sign in with GitHub/Google
|
|
456
|
+
3. Click "Create Key"
|
|
457
|
+
4. Copy key (starts with `sk-or-...`)
|
|
458
|
+
|
|
459
|
+
### GitHub Copilot
|
|
460
|
+
1. Go to https://github.com/settings/tokens
|
|
461
|
+
2. Generate new token
|
|
462
|
+
3. Select `copilot` scope
|
|
463
|
+
4. Copy token (starts with `ghu_...`)
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## File Structure
|
|
468
|
+
|
|
469
|
+
```
|
|
470
|
+
~/.claude-code-router/
|
|
471
|
+
├── config.json # Main configuration
|
|
472
|
+
├── intent-router.js # Custom routing logic
|
|
473
|
+
├── README.md # Quick documentation
|
|
474
|
+
├── FULL_DOCUMENTATION.md # This file
|
|
475
|
+
└── logs/ # Log files
|
|
476
|
+
└── *.log
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
---
|
|
480
|
+
|
|
481
|
+
## Notes
|
|
482
|
+
|
|
483
|
+
- Router always runs on `localhost:3456`
|
|
484
|
+
- `ANTHROPIC_BASE_URL` enables Claude Code to connect to router
|
|
485
|
+
- `NO_PROXY` prevents system proxy from blocking router
|
|
486
|
+
- Environment variables can be used in config.json with `$VAR_NAME` format
|
|
487
|
+
|
|
488
|
+
---
|
|
489
|
+
|
|
490
|
+
## Attribution
|
|
491
|
+
|
|
492
|
+
This configuration package is designed for use with [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router), an excellent tool that enables Claude Code functionality with multiple AI providers.
|
|
493
|
+
|
|
494
|
+
The original Claude Code Router project is developed and maintained by musistudio. This package contains pre-configured routing logic and provider configurations to help users get started quickly.
|
|
495
|
+
|
|
496
|
+
## Resources
|
|
497
|
+
|
|
498
|
+
- [GitHub - musistudio/claude-code-router](https://github.com/musistudio/claude-code-router)
|
|
499
|
+
- [npm - @musistudio/claude-code-router](https://www.npmjs.com/package/@musistudio/claude-code-router)
|
|
500
|
+
- [OpenAI API Docs](https://platform.openai.com/docs)
|
|
501
|
+
- [Anthropic API Docs](https://docs.anthropic.com)
|
|
502
|
+
- [Gemini API Docs](https://ai.google.dev/gemini-api/docs)
|
|
503
|
+
- [DashScope Docs](https://www.alibabacloud.com/help/en/model-studio)
|
|
504
|
+
- [Z.ai Docs](https://docs.z.ai)
|
|
505
|
+
- [GitHub Copilot API](https://docs.github.com/en/copilot)
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Claude Code Router - Multi-Provider Setup
|
|
2
|
+
|
|
3
|
+
Use Claude Code as a single interface to access multiple AI providers with intent-based routing for optimal performance and cost.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **6+ Provider Support**: OpenAI, Anthropic, Gemini, Qwen, GLM, OpenRouter, GitHub Copilot
|
|
8
|
+
- **Intent-Based Routing**: Automatically selects the best model based on your request
|
|
9
|
+
- **Cost Optimization**: Simple tasks go to cheaper models
|
|
10
|
+
- **Performance Optimization**: Fast responses use optimized models
|
|
11
|
+
|
|
12
|
+
## Routing Strategy
|
|
13
|
+
|
|
14
|
+
| Request Type | Provider | Model |
|
|
15
|
+
|--------------|----------|-------|
|
|
16
|
+
| Code writing, debugging | OpenAI | gpt-4o |
|
|
17
|
+
| Deep analysis, architecture | Anthropic | claude-sonnet-4 |
|
|
18
|
+
| Quick responses, summaries | Gemini | gemini-2.5-flash |
|
|
19
|
+
| Simple tasks | Qwen | qwen-plus |
|
|
20
|
+
| Translation, multilingual | GLM | glm-4.6 |
|
|
21
|
+
| Complex algorithms | OpenAI | o1 |
|
|
22
|
+
| Coding assistance | GitHub Copilot | copilot |
|
|
23
|
+
|
|
24
|
+
## Quick Setup
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/YOUR_USERNAME/claude-code-router-config.git
|
|
28
|
+
cd claude-code-router-config
|
|
29
|
+
chmod +x install.sh
|
|
30
|
+
./install.sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Manual Setup
|
|
34
|
+
|
|
35
|
+
### 1. Install Package
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm add -g @musistudio/claude-code-router
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### 2. Copy Configuration Files
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
mkdir -p ~/.claude-code-router
|
|
45
|
+
cp config/config.json ~/.claude-code-router/
|
|
46
|
+
cp config/intent-router.js ~/.claude-code-router/
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 3. Set Up Environment Variables
|
|
50
|
+
|
|
51
|
+
Create `.env` file in your home directory:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
cp .env.example ~/.env
|
|
55
|
+
# Edit ~/.env with your API keys
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or add to `~/.zshrc` / `~/.bashrc`:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Claude Code Router - API Keys
|
|
62
|
+
export OPENAI_API_KEY="sk-..."
|
|
63
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
64
|
+
export GEMINI_API_KEY="AIza..."
|
|
65
|
+
export QWEN_API_KEY="sk-..."
|
|
66
|
+
export GLM_API_KEY="..."
|
|
67
|
+
export OPENROUTER_API_KEY="sk-or-..."
|
|
68
|
+
export GITHUB_COPIOT_API_KEY="ghu_..."
|
|
69
|
+
|
|
70
|
+
# Router Connection
|
|
71
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
72
|
+
export NO_PROXY="127.0.0.1"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 4. Start Router
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
source ~/.zshrc # Reload environment
|
|
79
|
+
ccr code
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Usage
|
|
83
|
+
|
|
84
|
+
### Basic Commands
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
ccr start # Start router
|
|
88
|
+
ccr code # Start with Claude Code
|
|
89
|
+
ccr status # Check status
|
|
90
|
+
ccr stop # Stop router
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Switch Models (Runtime)
|
|
94
|
+
|
|
95
|
+
Inside Claude Code:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
/model openai,gpt-4o
|
|
99
|
+
/model anthropic,claude-sonnet-4-latest
|
|
100
|
+
/model gemini,gemini-2.5-flash
|
|
101
|
+
/model qwen,qwen-plus
|
|
102
|
+
/model glm,glm-4.6
|
|
103
|
+
/model copilot,copilot
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## API Key Setup
|
|
107
|
+
|
|
108
|
+
| Provider | Link | Notes |
|
|
109
|
+
|----------|------|-------|
|
|
110
|
+
| OpenAI | https://platform.openai.com/api-keys | gpt-4o, o1 models |
|
|
111
|
+
| Anthropic | https://console.anthropic.com/settings/keys | Claude models |
|
|
112
|
+
| Gemini | https://aistudio.google.com/apikey | Google AI models |
|
|
113
|
+
| Qwen | https://dashscope.console.aliyun.com/apiKey | Alibaba Cloud |
|
|
114
|
+
| GLM | https://open.bigmodel.cn/usercenter/apikeys | Zhipu AI |
|
|
115
|
+
| OpenRouter | https://openrouter.ai/keys | Multiple models |
|
|
116
|
+
| GitHub Copilot | https://github.com/settings/tokens | `copilot` scope |
|
|
117
|
+
|
|
118
|
+
## File Structure
|
|
119
|
+
|
|
120
|
+
```
|
|
121
|
+
~/.claude-code-router/
|
|
122
|
+
├── config.json # Provider configuration
|
|
123
|
+
├── intent-router.js # Routing logic
|
|
124
|
+
└── logs/ # Log files
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Testing
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# Test different routing scenarios
|
|
131
|
+
claude "Write a Python sorting function" # → OpenAI
|
|
132
|
+
claude "Explain microservices architecture" # → Anthropic
|
|
133
|
+
claude "Quick summary of REST APIs" # → Gemini
|
|
134
|
+
claude "List files in current directory" # → Qwen
|
|
135
|
+
claude "Translate to Chinese: Hello" # → GLM
|
|
136
|
+
claude "Help me debug this React component" # → GitHub Copilot
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Documentation
|
|
140
|
+
|
|
141
|
+
- [Complete Documentation](docs/FULL_DOCUMENTATION_EN.md)
|
|
142
|
+
- [Setup Prompt](docs/SETUP_PROMPT_EN.md)
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
|
|
146
|
+
MIT
|