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 ADDED
@@ -0,0 +1,27 @@
1
+ # Claude Code Router - Environment Variables
2
+ # Copy this to .env and fill with your actual API keys
3
+
4
+ # OpenAI (GPT-4o, O1, Codex)
5
+ OPENAI_API_KEY=sk-...
6
+
7
+ # Anthropic Claude
8
+ ANTHROPIC_API_KEY=sk-ant-...
9
+
10
+ # Google Gemini
11
+ GEMINI_API_KEY=AIza...
12
+
13
+ # Alibaba Qwen (DashScope)
14
+ QWEN_API_KEY=sk-...
15
+
16
+ # Zhipu GLM (Z.ai)
17
+ GLM_API_KEY=...
18
+
19
+ # OpenRouter (fallback)
20
+ OPENROUTER_API_KEY=sk-or-...
21
+
22
+ # GitHub Copilot (optional)
23
+ GITHUB_COPIOT_API_KEY=ghu_...
24
+
25
+ # Router Connection
26
+ ANTHROPIC_BASE_URL=http://127.0.0.1:3456
27
+ NO_PROXY=127.0.0.1
package/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Halil Ertekin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ ## Attribution
26
+
27
+ This package provides configuration for @musistudio/claude-code-router.
28
+ Original project: https://github.com/musistudio/claude-code-router
29
+
30
+ The configuration files and intent-based routing logic in this package are designed to work with the original Claude Code Router created by musistudio.
package/README.md ADDED
@@ -0,0 +1,148 @@
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
+ - **7 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/halilertekin/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:
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
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
+ ## Testing
119
+
120
+ ```bash
121
+ # Test different routing scenarios
122
+ claude "Write a Python sorting function" # → OpenAI
123
+ claude "Explain microservices architecture" # → Anthropic
124
+ claude "Quick summary of REST APIs" # → Gemini
125
+ claude "List files in current directory" # → Qwen
126
+ claude "Translate to Chinese: Hello" # → GLM
127
+ claude "Help me debug this React component" # → GitHub Copilot
128
+ ```
129
+
130
+ ## Documentation
131
+
132
+ - [Complete Documentation (EN)](docs/FULL_DOCUMENTATION_EN.md)
133
+ - [Setup Prompt (EN)](docs/SETUP_PROMPT_EN.md)
134
+ - [Setup Prompt (TR)](docs/SETUP_PROMPT.md)
135
+
136
+ ## Attribution
137
+
138
+ This package provides configuration for [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router), an excellent tool that enables Claude Code functionality with multiple AI providers.
139
+
140
+ 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.
141
+
142
+ ## License
143
+
144
+ MIT © [Halil Ertekin](https://github.com/halilertekin)
145
+
146
+ ---
147
+
148
+ **Note**: This is a configuration package. To use it, you need to install the original [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router) package.
@@ -0,0 +1,67 @@
1
+ {
2
+ "_comment": "Claude Code Router Configuration - For use with @musistudio/claude-code-router",
3
+ "_attribution": "Original project: https://github.com/musistudio/claude-code-router",
4
+ "_author": "Configuration by Halil Ertekin",
5
+ "LOG": true,
6
+ "LOG_LEVEL": "info",
7
+ "API_TIMEOUT_MS": 300000,
8
+ "CUSTOM_ROUTER_PATH": "$HOME/.claude-code-router/intent-router.js",
9
+
10
+ "Providers": [
11
+ {
12
+ "name": "openai",
13
+ "api_base_url": "https://api.openai.com/v1/chat/completions",
14
+ "api_key": "$OPENAI_API_KEY",
15
+ "models": ["gpt-4o", "gpt-4-turbo", "gpt-4o-mini", "o1", "o1-mini"],
16
+ "transformer": { "use": [] }
17
+ },
18
+ {
19
+ "name": "anthropic",
20
+ "api_base_url": "https://api.anthropic.com/v1/messages",
21
+ "api_key": "$ANTHROPIC_API_KEY",
22
+ "models": ["claude-sonnet-4-latest", "claude-3-5-sonnet-latest"],
23
+ "transformer": { "use": ["Anthropic"] }
24
+ },
25
+ {
26
+ "name": "gemini",
27
+ "api_base_url": "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions",
28
+ "api_key": "$GEMINI_API_KEY",
29
+ "models": ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.0-flash"],
30
+ "transformer": { "use": ["gemini"] }
31
+ },
32
+ {
33
+ "name": "qwen",
34
+ "api_base_url": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",
35
+ "api_key": "$QWEN_API_KEY",
36
+ "models": ["qwen-plus", "qwen-max", "qwen3-coder-plus", "qwen-turbo"],
37
+ "transformer": { "use": [] }
38
+ },
39
+ {
40
+ "name": "glm",
41
+ "api_base_url": "https://api.z.ai/api/paas/v4/chat/completions",
42
+ "api_key": "$GLM_API_KEY",
43
+ "models": ["glm-4.6", "glm-4.5", "glm-4-plus"],
44
+ "transformer": { "use": [] }
45
+ },
46
+ {
47
+ "name": "openrouter",
48
+ "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
49
+ "api_key": "$OPENROUTER_API_KEY",
50
+ "models": [
51
+ "anthropic/claude-sonnet-4",
52
+ "deepseek/deepseek-chat",
53
+ "google/gemini-2.5-flash",
54
+ "meta-llama/llama-3.3-70b-instruct"
55
+ ],
56
+ "transformer": { "use": ["openrouter"] }
57
+ }
58
+ ],
59
+
60
+ "Router": {
61
+ "default": "openai,gpt-4o",
62
+ "background": "qwen,qwen-turbo",
63
+ "think": "anthropic,claude-sonnet-4-latest",
64
+ "longContext": "gemini,gemini-2.5-flash",
65
+ "longContextThreshold": 60000
66
+ }
67
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Multi-Provider Intent Router
3
+ * Routes requests based on task type to optimal provider
4
+ *
5
+ * This router is designed for use with @musistudio/claude-code-router
6
+ * Original project: https://github.com/musistudio/claude-code-router
7
+ *
8
+ * Configuration by Halil Ertekin
9
+ */
10
+
11
+ const INTENTS = {
12
+ // Coding tasks → OpenAI (GPT-4o, O1, Codex)
13
+ CODING: {
14
+ patterns: [
15
+ /\b(implement|refactor|debug|fix|write|code|function|class|method|bug|error|compile|syntax)\b/i,
16
+ /\b(typescript|javascript|python|rust|go|java|react|vue|angular|swift|kotlin)\b/i,
17
+ /\b(api|endpoint|database|query|migration|schema|test|unit test)\b/i,
18
+ /\b(codex|o1|reasoning)\b/i
19
+ ],
20
+ route: "openai,gpt-4o"
21
+ },
22
+
23
+ // Deep reasoning → Anthropic Claude
24
+ REASONING: {
25
+ patterns: [
26
+ /\b(architect|design|analyze|plan|strategy|structure|system|trade-?off)\b/i,
27
+ /\b(why|explain|reason|understand|compare|evaluate|consider|review)\b/i,
28
+ /\b(decision|approach|best practice|pattern|principle|philosophy)\b/i
29
+ ],
30
+ route: "anthropic,claude-sonnet-4-latest"
31
+ },
32
+
33
+ // Fast responses → Gemini Flash
34
+ FAST: {
35
+ patterns: [
36
+ /\b(fast|quick|brief|short|summary|tldr|overview|hızlı)\b/i,
37
+ /\b(scan|check|verify|validate)\b/i
38
+ ],
39
+ route: "gemini,gemini-2.5-flash"
40
+ },
41
+
42
+ // Simple/cheap tasks → Qwen
43
+ SIMPLE: {
44
+ patterns: [
45
+ /\b(list|show|what is|simple|basic|help|how to|format)\b/i,
46
+ /\b(rename|move|delete|create file|mkdir|copy)\b/i,
47
+ /\b(ucuz|basit|kolay)\b/i
48
+ ],
49
+ route: "qwen,qwen-plus"
50
+ },
51
+
52
+ // Multilingual → GLM
53
+ MULTILINGUAL: {
54
+ patterns: [
55
+ /\b(translate|çevir|tercüme|chinese|türkçe|multilingual)\b/i,
56
+ /[\u4e00-\u9fff]/, // Chinese characters
57
+ /[\u0600-\u06FF]/, // Arabic
58
+ ],
59
+ route: "glm,glm-4.6"
60
+ },
61
+
62
+ // Heavy coding/reasoning → O1
63
+ HEAVY_REASONING: {
64
+ patterns: [
65
+ /\b(complex algorithm|optimization|performance critical|system design)\b/i,
66
+ /\b(prove|mathematical|theorem|formal verification)\b/i
67
+ ],
68
+ route: "openai,o1"
69
+ }
70
+ };
71
+
72
+ function extractContent(req) {
73
+ const messages = req.body?.messages || [];
74
+ return messages
75
+ .filter(m => m.role === "user" || m.role === "system")
76
+ .map(m => typeof m.content === "string" ? m.content : JSON.stringify(m.content))
77
+ .join(" ")
78
+ .slice(0, 3000);
79
+ }
80
+
81
+ function detectIntent(content) {
82
+ const scores = {};
83
+ for (const [intent, config] of Object.entries(INTENTS)) {
84
+ scores[intent] = config.patterns.reduce((score, pattern) => {
85
+ const matches = (content.match(pattern) || []).length;
86
+ return score + matches;
87
+ }, 0);
88
+ }
89
+ const sorted = Object.entries(scores)
90
+ .filter(([_, score]) => score > 0)
91
+ .sort((a, b) => b[1] - a[1]);
92
+ return sorted.length > 0 ? sorted[0][0] : null;
93
+ }
94
+
95
+ module.exports = async function router(req, config) {
96
+ const content = extractContent(req);
97
+ const intent = detectIntent(content);
98
+
99
+ if (intent && INTENTS[intent]) {
100
+ const route = INTENTS[intent].route;
101
+ console.log(`[Router] ${intent} → ${route}`);
102
+ return route;
103
+ }
104
+
105
+ // Fallback
106
+ console.log("[Router] No match → openai,gpt-4o");
107
+ return null;
108
+ };