@halilertekin/claude-code-router-config 1.1.1

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.
@@ -0,0 +1,526 @@
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
+ ### Option 1: Homebrew (Recommended)
169
+
170
+ ```bash
171
+ brew install halilertekin/tap/claude-code-router-config
172
+ ```
173
+
174
+ The Homebrew installation handles everything automatically:
175
+ - Installs @musistudio/claude-code-router
176
+ - Copies configuration files
177
+ - Creates ~/.env with templates
178
+ - Provides next-step instructions
179
+
180
+ ### Option 2: NPM Package
181
+
182
+ ```bash
183
+ pnpm add -g @halilertekin/claude-code-router-config
184
+ ccr-setup
185
+ ```
186
+
187
+ ### Option 3: Manual Installation
188
+
189
+ #### Step 1: Install Package
190
+
191
+ ```bash
192
+ pnpm add -g @musistudio/claude-code-router
193
+ mkdir -p ~/.claude-code-router
194
+ ```
195
+
196
+ #### Step 2: Environment Variables
197
+
198
+ Option 1: Create `.env` file:
199
+
200
+ ```bash
201
+ cp .env.example ~/.env
202
+ # Edit ~/.env with your API keys
203
+ ```
204
+
205
+ Option 2: Add to `~/.zshrc` or `~/.bashrc`:
206
+
207
+ ```bash
208
+ # ═══════════════════════════════════════════════════
209
+ # Claude Code Router - API Keys
210
+ # ═══════════════════════════════════════════════════
211
+ export OPENAI_API_KEY="sk-..."
212
+ export ANTHROPIC_API_KEY="sk-ant-..."
213
+ export GEMINI_API_KEY="AIza..."
214
+ export QWEN_API_KEY="sk-..."
215
+ export GLM_API_KEY="..."
216
+ export OPENROUTER_API_KEY="sk-or-..."
217
+ export GITHUB_COPIOT_API_KEY="ghu_..."
218
+
219
+ # Router Connection
220
+ export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
221
+ export NO_PROXY="127.0.0.1"
222
+ ```
223
+
224
+ ### Step 3: Reload Shell
225
+
226
+ ```bash
227
+ source ~/.zshrc
228
+ ```
229
+
230
+ ### Step 4: Start
231
+
232
+ ```bash
233
+ ccr code
234
+ ```
235
+
236
+ ---
237
+
238
+ ## Configuration Details
239
+
240
+ ### config.json Structure
241
+
242
+ ```json
243
+ {
244
+ "LOG": true, // Enable logging
245
+ "LOG_LEVEL": "info", // Log level: fatal|error|warn|info|debug|trace
246
+ "API_TIMEOUT_MS": 300000, // 5 minute timeout
247
+ "CUSTOM_ROUTER_PATH": "$HOME/.claude-code-router/intent-router.js",
248
+
249
+ "Providers": [
250
+ {
251
+ "name": "provider_name", // Unique name
252
+ "api_base_url": "https://...", // API endpoint
253
+ "api_key": "$ENV_VAR", // Environment variable reference
254
+ "models": ["model1", "model2"], // Supported models
255
+ "transformer": { "use": [] } // Required transformers
256
+ }
257
+ ],
258
+
259
+ "Router": {
260
+ "default": "provider,model", // Default route
261
+ "background": "provider,model", // Background tasks
262
+ "think": "provider,model", // Reasoning tasks
263
+ "longContext": "provider,model", // Long context
264
+ "longContextThreshold": 60000 // Token threshold
265
+ }
266
+ }
267
+ ```
268
+
269
+ ### Transformers
270
+
271
+ | Transformer | Usage |
272
+ |-------------|-------|
273
+ | `Anthropic` | Anthropic API format |
274
+ | `gemini` | Google Gemini API format |
275
+ | `openrouter` | OpenRouter API format |
276
+ | `deepseek` | DeepSeek models |
277
+ | `maxtoken` | Max token limit setting |
278
+
279
+ ---
280
+
281
+ ## Intent Router Logic
282
+
283
+ ### Working Principle
284
+
285
+ 1. Request arrives
286
+ 2. Message content is extracted (user + system messages)
287
+ 3. Pattern matching is counted for each intent
288
+ 4. Intent with highest score is selected
289
+ 5. Request is routed to relevant provider
290
+
291
+ ### Pattern Priority
292
+
293
+ 1. **HEAVY_REASONING** - Complex algorithms
294
+ 2. **CODING** - Code writing/debugging
295
+ 3. **CODING_ASSIST** - Coding help
296
+ 4. **REASONING** - Analysis/explanation
297
+ 5. **MULTILINGUAL** - Translation
298
+ 6. **FAST** - Quick responses
299
+ 7. **SIMPLE** - Simple tasks
300
+
301
+ ### Customization
302
+
303
+ Edit `intent-router.js` to:
304
+ - Add new intents
305
+ - Modify patterns
306
+ - Update routes
307
+
308
+ ---
309
+
310
+ ## Usage Guide
311
+
312
+ ### Basic Commands
313
+
314
+ ```bash
315
+ # Start router
316
+ ccr start
317
+
318
+ # Start with Claude Code
319
+ ccr code
320
+
321
+ # Check status
322
+ ccr status
323
+
324
+ # Stop router
325
+ ccr stop
326
+
327
+ # Restart router
328
+ ccr restart
329
+
330
+ # Open web UI
331
+ ccr ui
332
+
333
+ # Model selection interface
334
+ ccr model
335
+ ```
336
+
337
+ ### Runtime Model Switching
338
+
339
+ Inside Claude Code using `/model` command:
340
+
341
+ ```
342
+ /model openai,gpt-4o
343
+ /model openai,o1
344
+ /model anthropic,claude-sonnet-4-latest
345
+ /model gemini,gemini-2.5-flash
346
+ /model gemini,gemini-2.5-pro
347
+ /model qwen,qwen-plus
348
+ /model qwen,qwen3-coder-plus
349
+ /model glm,glm-4.6
350
+ /model openrouter,deepseek/deepseek-chat
351
+ /model copilot,copilot
352
+ ```
353
+
354
+ ### Example Usage Scenarios
355
+
356
+ ```bash
357
+ # Coding → OpenAI gpt-4o
358
+ claude "Write a Python function to implement merge sort"
359
+
360
+ # Deep Analysis → Anthropic Claude
361
+ claude "Analyze the trade-offs between microservices and monolith architecture"
362
+
363
+ # Quick Summary → Gemini Flash
364
+ claude "Give me a quick summary of GraphQL vs REST"
365
+
366
+ # Simple Task → Qwen
367
+ claude "List all TypeScript files in src directory"
368
+
369
+ # Translation → GLM
370
+ claude "Translate this to Chinese: Hello, how are you?"
371
+
372
+ # Complex Algorithm → OpenAI O1
373
+ claude "Design an optimal caching algorithm for a distributed system"
374
+
375
+ # Coding Assistance → GitHub Copilot
376
+ claude "Help me debug this React component error"
377
+ ```
378
+
379
+ ### Monitor Logs
380
+
381
+ ```bash
382
+ # All logs
383
+ tail -f ~/.claude-code-router/logs/*.log
384
+
385
+ # Only routing decisions
386
+ tail -f ~/.claude-code-router/logs/*.log | grep "Router"
387
+ ```
388
+
389
+ ---
390
+
391
+ ## Troubleshooting
392
+
393
+ ### Router Not Starting
394
+
395
+ ```bash
396
+ # Check if port is in use
397
+ lsof -i :3456
398
+
399
+ # Kill if needed
400
+ kill -9 <PID>
401
+
402
+ # Restart
403
+ ccr start
404
+ ```
405
+
406
+ ### API Errors
407
+
408
+ 1. Check API keys:
409
+ ```bash
410
+ echo $OPENAI_API_KEY
411
+ echo $ANTHROPIC_API_KEY
412
+ # ... others
413
+ ```
414
+
415
+ 2. Test API key:
416
+ ```bash
417
+ curl https://api.openai.com/v1/models \
418
+ -H "Authorization: Bearer $OPENAI_API_KEY"
419
+ ```
420
+
421
+ ### Model Not Found Error
422
+
423
+ Check model names in `config.json`:
424
+ - OpenAI: `gpt-4o` (not `gpt-4-o`)
425
+ - Anthropic: `claude-sonnet-4-latest`
426
+ - Gemini: `gemini-2.5-flash`
427
+
428
+ ### Routing Not Working
429
+
430
+ 1. Check custom router loaded:
431
+ ```bash
432
+ cat ~/.claude-code-router/config.json | grep CUSTOM_ROUTER
433
+ ```
434
+
435
+ 2. Check router file exists:
436
+ ```bash
437
+ ls -la ~/.claude-code-router/intent-router.js
438
+ ```
439
+
440
+ 3. Check for syntax errors:
441
+ ```bash
442
+ node -c ~/.claude-code-router/intent-router.js
443
+ ```
444
+
445
+ ---
446
+
447
+ ## API Key Setup Guide
448
+
449
+ ### OpenAI
450
+ 1. Go to https://platform.openai.com/api-keys
451
+ 2. Click "Create new secret key"
452
+ 3. Copy key (starts with `sk-...`)
453
+
454
+ ### Anthropic
455
+ 1. Go to https://console.anthropic.com/settings/keys
456
+ 2. Click "Create Key"
457
+ 3. Copy key (starts with `sk-ant-...`)
458
+
459
+ ### Google Gemini
460
+ 1. Go to https://aistudio.google.com/apikey
461
+ 2. Click "Create API Key"
462
+ 3. Copy key (starts with `AIza...`)
463
+
464
+ ### Alibaba Qwen (DashScope)
465
+ 1. Go to https://dashscope.console.aliyun.com/apiKey
466
+ 2. Create Aliyun account (international)
467
+ 3. Get API key
468
+
469
+ ### Zhipu GLM (Z.ai)
470
+ 1. Go to https://open.bigmodel.cn/usercenter/apikeys
471
+ 2. Create account
472
+ 3. Get API key
473
+
474
+ ### OpenRouter
475
+ 1. Go to https://openrouter.ai/keys
476
+ 2. Sign in with GitHub/Google
477
+ 3. Click "Create Key"
478
+ 4. Copy key (starts with `sk-or-...`)
479
+
480
+ ### GitHub Copilot
481
+ 1. Go to https://github.com/settings/tokens
482
+ 2. Generate new token
483
+ 3. Select `copilot` scope
484
+ 4. Copy token (starts with `ghu_...`)
485
+
486
+ ---
487
+
488
+ ## File Structure
489
+
490
+ ```
491
+ ~/.claude-code-router/
492
+ ├── config.json # Main configuration
493
+ ├── intent-router.js # Custom routing logic
494
+ ├── README.md # Quick documentation
495
+ ├── FULL_DOCUMENTATION.md # This file
496
+ └── logs/ # Log files
497
+ └── *.log
498
+ ```
499
+
500
+ ---
501
+
502
+ ## Notes
503
+
504
+ - Router always runs on `localhost:3456`
505
+ - `ANTHROPIC_BASE_URL` enables Claude Code to connect to router
506
+ - `NO_PROXY` prevents system proxy from blocking router
507
+ - Environment variables can be used in config.json with `$VAR_NAME` format
508
+
509
+ ---
510
+
511
+ ## Attribution
512
+
513
+ 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.
514
+
515
+ 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.
516
+
517
+ ## Resources
518
+
519
+ - [GitHub - musistudio/claude-code-router](https://github.com/musistudio/claude-code-router)
520
+ - [npm - @musistudio/claude-code-router](https://www.npmjs.com/package/@musistudio/claude-code-router)
521
+ - [OpenAI API Docs](https://platform.openai.com/docs)
522
+ - [Anthropic API Docs](https://docs.anthropic.com)
523
+ - [Gemini API Docs](https://ai.google.dev/gemini-api/docs)
524
+ - [DashScope Docs](https://www.alibabacloud.com/help/en/model-studio)
525
+ - [Z.ai Docs](https://docs.z.ai)
526
+ - [GitHub Copilot API](https://docs.github.com/en/copilot)