@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.
- package/.env.example +27 -0
- package/LICENSE +30 -0
- package/README.md +320 -0
- package/cli/analytics.js +509 -0
- package/cli/benchmark.js +342 -0
- package/cli/commands.js +300 -0
- package/config/config.json +67 -0
- package/config/intent-router.js +108 -0
- package/config/smart-intent-router.js +543 -0
- package/docs/AGENTSKILLS_INTEGRATION.md +500 -0
- package/docs/AGENTSKILLS_SETUP.md +743 -0
- package/docs/AGENTSKILLS_SETUP_TR.md +736 -0
- package/docs/FULL_DOCUMENTATION.md +510 -0
- package/docs/FULL_DOCUMENTATION_EN.md +526 -0
- package/docs/HOMEBREW_SETUP.md +252 -0
- package/docs/README_EN.md +146 -0
- package/docs/SETUP_PROMPT.md +299 -0
- package/docs/SETUP_PROMPT_EN.md +317 -0
- package/docs/v1.1.0-FEATURES.md +752 -0
- package/install.js +160 -0
- package/install.sh +73 -0
- package/logging/enhanced-logger.js +410 -0
- package/logging/health-monitor.js +472 -0
- package/logging/middleware.js +384 -0
- package/package.json +91 -0
- package/plugins/plugin-manager.js +607 -0
- package/templates/README.md +161 -0
- package/templates/balanced.json +111 -0
- package/templates/cost-optimized.json +96 -0
- package/templates/development.json +104 -0
- package/templates/performance-optimized.json +88 -0
- package/templates/quality-focused.json +105 -0
- package/web-dashboard/public/css/dashboard.css +575 -0
- package/web-dashboard/public/index.html +308 -0
- package/web-dashboard/public/js/dashboard.js +512 -0
- package/web-dashboard/server.js +352 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# Homebrew Setup Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document explains how to set up and use the custom Homebrew tap for installing `claude-code-router-config`. The custom tap allows easy installation of the multi-provider AI routing configuration with intent-based routing support.
|
|
6
|
+
|
|
7
|
+
## Custom Tap Details
|
|
8
|
+
|
|
9
|
+
**Tap Repository**: https://github.com/halilertekin/homebrew-tap
|
|
10
|
+
**Formula**: `claude-code-router-config`
|
|
11
|
+
**Main Repository**: https://github.com/halilertekin/CC-RouterMultiProvider
|
|
12
|
+
|
|
13
|
+
## Installation Instructions
|
|
14
|
+
|
|
15
|
+
### Prerequisites
|
|
16
|
+
|
|
17
|
+
- macOS with [Homebrew](https://brew.sh/) installed
|
|
18
|
+
- An Anthropic API key (for Claude models)
|
|
19
|
+
- Optional API keys for other providers (OpenAI, Gemini, Qwen, GLM, OpenRouter, GitHub Copilot)
|
|
20
|
+
|
|
21
|
+
### Step 1: Add the Custom Tap
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# Add the custom tap to your Homebrew installation
|
|
25
|
+
brew tap halilertekin/homebrew-tap
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Step 2: Install the Package
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Install claude-code-router-config
|
|
32
|
+
brew install claude-code-router-config
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Step 3: Configure API Keys
|
|
36
|
+
|
|
37
|
+
The installer automatically creates configuration files and an `.env.example` file. You need to:
|
|
38
|
+
|
|
39
|
+
1. **Edit your environment variables:**
|
|
40
|
+
```bash
|
|
41
|
+
nano ~/.env
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
2. **Add your API keys:**
|
|
45
|
+
```bash
|
|
46
|
+
# Required for Claude models
|
|
47
|
+
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
|
|
48
|
+
|
|
49
|
+
# Optional - Add other providers
|
|
50
|
+
export OPENAI_API_KEY="your_openai_api_key_here"
|
|
51
|
+
export GEMINI_API_KEY="your_gemini_api_key_here"
|
|
52
|
+
export QWEN_API_KEY="your_qwen_api_key_here"
|
|
53
|
+
export GLM_API_KEY="your_glm_api_key_here"
|
|
54
|
+
export OPENROUTER_API_KEY="your_openrouter_api_key_here"
|
|
55
|
+
export GITHUB_TOKEN="your_github_token_here"
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
3. **Add to shell configuration:**
|
|
59
|
+
```bash
|
|
60
|
+
# Add to ~/.zshrc or ~/.bashrc
|
|
61
|
+
export $(cat ~/.env | xargs)
|
|
62
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
63
|
+
export NO_PROXY="127.0.0.1"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
4. **Reload your shell:**
|
|
67
|
+
```bash
|
|
68
|
+
source ~/.zshrc
|
|
69
|
+
# or
|
|
70
|
+
source ~/.bashrc
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Step 4: Start the Router
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
# Start the Claude Code Router
|
|
77
|
+
ccr code
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## What Gets Installed
|
|
81
|
+
|
|
82
|
+
The Homebrew formula installs the following components:
|
|
83
|
+
|
|
84
|
+
### 1. Core Package
|
|
85
|
+
- **@musistudio/claude-code-router**: The main routing application (via pnpm)
|
|
86
|
+
|
|
87
|
+
### 2. Configuration Files
|
|
88
|
+
- **`~/.claude-code-router/config.json`**: Multi-provider configuration with 7 AI providers
|
|
89
|
+
- **`~/.claude-code-router/intent-router.js`**: Intelligent intent-based routing logic
|
|
90
|
+
|
|
91
|
+
### 3. Environment Template
|
|
92
|
+
- **`~/.env`**: Environment variables file (created from `.env.example`)
|
|
93
|
+
|
|
94
|
+
## Supported AI Providers
|
|
95
|
+
|
|
96
|
+
The configuration supports 7 AI providers:
|
|
97
|
+
|
|
98
|
+
1. **OpenAI**: GPT-4o, GPT-4 Turbo, O1, O1-mini
|
|
99
|
+
2. **Anthropic**: Claude Sonnet 4, Claude 3.5 Sonnet
|
|
100
|
+
3. **Gemini**: Gemini 2.5 Flash, Gemini 2.5 Pro
|
|
101
|
+
4. **Qwen**: Qwen Plus, Qwen Max
|
|
102
|
+
5. **GLM**: GLM-4.6, GLM-4.5
|
|
103
|
+
6. **OpenRouter**: Multiple models via OpenRouter
|
|
104
|
+
7. **GitHub Copilot**: Code assistance
|
|
105
|
+
|
|
106
|
+
## Intent-Based Routing
|
|
107
|
+
|
|
108
|
+
The router automatically routes requests to the most appropriate provider based on the task type:
|
|
109
|
+
|
|
110
|
+
- **Coding tasks** → OpenAI (GPT-4o/O1)
|
|
111
|
+
- **Deep reasoning** → Anthropic Claude
|
|
112
|
+
- **Fast responses** → Gemini Flash
|
|
113
|
+
- **Simple tasks** → Qwen
|
|
114
|
+
- **Multilingual** → GLM
|
|
115
|
+
- **Heavy reasoning** → OpenAI O1
|
|
116
|
+
- **Coding assistance** → GitHub Copilot
|
|
117
|
+
|
|
118
|
+
## Troubleshooting
|
|
119
|
+
|
|
120
|
+
### Common Issues
|
|
121
|
+
|
|
122
|
+
1. **Permission Denied Errors**
|
|
123
|
+
```bash
|
|
124
|
+
# Fix permissions on config directory
|
|
125
|
+
sudo chown -R $USER:$USER ~/.claude-code-router
|
|
126
|
+
chmod 755 ~/.claude-code-router
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
2. **pnpm Not Found**
|
|
130
|
+
```bash
|
|
131
|
+
# Install pnpm
|
|
132
|
+
brew install pnpm
|
|
133
|
+
|
|
134
|
+
# Or the formula automatically falls back to npm
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
3. **Environment Variables Not Loading**
|
|
138
|
+
```bash
|
|
139
|
+
# Verify .env file exists
|
|
140
|
+
ls -la ~/.env
|
|
141
|
+
|
|
142
|
+
# Manually source environment
|
|
143
|
+
export $(cat ~/.env | xargs)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
4. **Router Fails to Start**
|
|
147
|
+
```bash
|
|
148
|
+
# Check configuration files
|
|
149
|
+
ls -la ~/.claude-code-router/
|
|
150
|
+
|
|
151
|
+
# Verify config syntax
|
|
152
|
+
node -c ~/.claude-code-router/intent-router.js
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
5. **API Key Issues**
|
|
156
|
+
```bash
|
|
157
|
+
# Test API key
|
|
158
|
+
curl -X POST https://api.anthropic.com/v1/messages \
|
|
159
|
+
-H "x-api-key: $ANTHROPIC_API_KEY" \
|
|
160
|
+
-H "content-type: application/json" \
|
|
161
|
+
-d '{"model": "claude-3-sonnet-20240229", "max_tokens": 10, "messages": [{"role": "user", "content": "test"}]}'
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Getting Help
|
|
165
|
+
|
|
166
|
+
1. **Check logs**: The router provides detailed logging information
|
|
167
|
+
2. **Verify configuration**: Ensure all JSON files are valid
|
|
168
|
+
3. **Test providers individually**: Use direct API calls to test each provider
|
|
169
|
+
4. **Check network connectivity**: Ensure you can reach the provider APIs
|
|
170
|
+
|
|
171
|
+
## Updating the Installation
|
|
172
|
+
|
|
173
|
+
To update to the latest version:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Update the tap
|
|
177
|
+
brew update
|
|
178
|
+
|
|
179
|
+
# Upgrade the package
|
|
180
|
+
brew upgrade claude-code-router-config
|
|
181
|
+
|
|
182
|
+
# Or reinstall for clean setup
|
|
183
|
+
brew reinstall claude-code-router-config
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Uninstallation
|
|
187
|
+
|
|
188
|
+
To completely remove the installation:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Uninstall the package
|
|
192
|
+
brew uninstall claude-code-router-config
|
|
193
|
+
|
|
194
|
+
# Remove configuration files (optional)
|
|
195
|
+
rm -rf ~/.claude-code-router
|
|
196
|
+
|
|
197
|
+
# Remove environment variables from ~/.zshrc or ~/.bashrc
|
|
198
|
+
# Remove the tap (optional)
|
|
199
|
+
brew untap halilertekin/homebrew-tap
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Advanced Configuration
|
|
203
|
+
|
|
204
|
+
### Custom Intent Patterns
|
|
205
|
+
|
|
206
|
+
Edit `~/.claude-code-router/intent-router.js` to add custom routing patterns:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
// Add custom intent
|
|
210
|
+
CUSTOM_TASK: {
|
|
211
|
+
patterns: [/\b(custom|special|specific)\b/i],
|
|
212
|
+
route: "openai,gpt-4o"
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Provider Priority
|
|
217
|
+
|
|
218
|
+
Modify the routing order in `~/.claude-code-router/config.json`:
|
|
219
|
+
|
|
220
|
+
```json
|
|
221
|
+
"Router": {
|
|
222
|
+
"default": "anthropic,claude-sonnet-4-latest",
|
|
223
|
+
"background": "qwen,qwen-turbo",
|
|
224
|
+
"think": "openai,o1"
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Performance Tips
|
|
229
|
+
|
|
230
|
+
1. **Use appropriate models**: Choose the right model for each task
|
|
231
|
+
2. **Set timeouts**: Configure appropriate API timeouts
|
|
232
|
+
3. **Monitor usage**: Track token usage and costs
|
|
233
|
+
4. **Cache results**: Use caching for repeated requests
|
|
234
|
+
|
|
235
|
+
## Security Considerations
|
|
236
|
+
|
|
237
|
+
1. **Protect API keys**: Never commit API keys to version control
|
|
238
|
+
2. **Use environment variables**: Keep sensitive data in `.env`
|
|
239
|
+
3. **Regular key rotation**: Rotate API keys periodically
|
|
240
|
+
4. **Audit logs**: Monitor router logs for unusual activity
|
|
241
|
+
|
|
242
|
+
## Support
|
|
243
|
+
|
|
244
|
+
- **Main Repository**: https://github.com/halilertekin/CC-RouterMultiProvider
|
|
245
|
+
- **Issues**: Report issues via GitHub
|
|
246
|
+
- **Documentation**: See `docs/` directory for comprehensive guides
|
|
247
|
+
|
|
248
|
+
## Attribution
|
|
249
|
+
|
|
250
|
+
This configuration package is for use with [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router).
|
|
251
|
+
Original project: https://github.com/musistudio/claude-code-router
|
|
252
|
+
Configuration by Halil Ertekin
|
|
@@ -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
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# Claude Code Router - Kurulum Prompt'u
|
|
2
|
+
|
|
3
|
+
Bu prompt'u başka bir makinede Claude Code Router kurmak için kullanabilirsin.
|
|
4
|
+
Kopyala ve Claude Code'a yapıştır.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## KURULUM PROMPT'U
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
Sen bir DevOps + LLM altyapı uzmanısın.
|
|
12
|
+
|
|
13
|
+
Görev: Claude Code Router'ı kur ve intent-based routing ile yapılandır.
|
|
14
|
+
|
|
15
|
+
Gereksinimler:
|
|
16
|
+
- pnpm kullan (npm değil)
|
|
17
|
+
- Model versiyonlarını sabitlemek yerine en güncel/önerilen modelleri kullan
|
|
18
|
+
- macOS/Linux ortamı
|
|
19
|
+
|
|
20
|
+
Kurulacak Provider'lar:
|
|
21
|
+
1. OpenAI (gpt-4o, o1) - Coding, debugging
|
|
22
|
+
2. Anthropic Claude - Deep reasoning, analysis
|
|
23
|
+
3. Google Gemini - Hızlı cevaplar, uzun context
|
|
24
|
+
4. Alibaba Qwen (DashScope) - Ucuz, basit işler
|
|
25
|
+
5. Zhipu GLM (Z.ai) - Çok dilli, çeviri
|
|
26
|
+
6. OpenRouter - Fallback
|
|
27
|
+
|
|
28
|
+
Intent-Based Routing Kuralları:
|
|
29
|
+
- Kod yazma/debug → OpenAI (gpt-4o)
|
|
30
|
+
- Mimari/analiz/neden → Anthropic Claude
|
|
31
|
+
- Hızlı/özet/tldr → Gemini Flash
|
|
32
|
+
- Basit/liste/yardım → Qwen (ucuz)
|
|
33
|
+
- Çeviri/çok dilli → GLM
|
|
34
|
+
- Karmaşık algoritma → OpenAI (o1)
|
|
35
|
+
- Eşleşme yok → OpenAI (fallback)
|
|
36
|
+
|
|
37
|
+
Yapılacaklar:
|
|
38
|
+
1. pnpm ile @musistudio/claude-code-router kur
|
|
39
|
+
2. ~/.claude-code-router/config.json oluştur (tüm provider'lar)
|
|
40
|
+
3. ~/.claude-code-router/intent-router.js oluştur (routing logic)
|
|
41
|
+
4. ~/.zshrc için gerekli env var'ları göster
|
|
42
|
+
|
|
43
|
+
API Endpoint'leri:
|
|
44
|
+
- OpenAI: https://api.openai.com/v1/chat/completions
|
|
45
|
+
- Anthropic: https://api.anthropic.com/v1/messages (transformer: Anthropic)
|
|
46
|
+
- Gemini: https://generativelanguage.googleapis.com/v1beta/openai/chat/completions (transformer: gemini)
|
|
47
|
+
- Qwen: https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions
|
|
48
|
+
- GLM: https://api.z.ai/api/paas/v4/chat/completions
|
|
49
|
+
- OpenRouter: https://openrouter.ai/api/v1/chat/completions (transformer: openrouter)
|
|
50
|
+
|
|
51
|
+
Router Ayarları:
|
|
52
|
+
- default: openai,gpt-4o
|
|
53
|
+
- background: qwen,qwen-turbo
|
|
54
|
+
- think: anthropic,claude-sonnet-4-latest
|
|
55
|
+
- longContext: gemini,gemini-2.5-flash
|
|
56
|
+
- longContextThreshold: 60000
|
|
57
|
+
|
|
58
|
+
Çıktı:
|
|
59
|
+
1. Kurulum komutları
|
|
60
|
+
2. config.json içeriği
|
|
61
|
+
3. intent-router.js içeriği
|
|
62
|
+
4. .zshrc eklemeleri
|
|
63
|
+
5. Başlatma ve test komutları
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## HIZLI KURULUM (Manuel)
|
|
69
|
+
|
|
70
|
+
Eğer prompt kullanmak istemiyorsan, aşağıdaki adımları manuel uygula:
|
|
71
|
+
|
|
72
|
+
### 1. Kurulum
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pnpm add -g @musistudio/claude-code-router
|
|
76
|
+
mkdir -p ~/.claude-code-router
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 2. config.json
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
cat > ~/.claude-code-router/config.json << 'EOF'
|
|
83
|
+
{
|
|
84
|
+
"LOG": true,
|
|
85
|
+
"LOG_LEVEL": "info",
|
|
86
|
+
"API_TIMEOUT_MS": 300000,
|
|
87
|
+
"CUSTOM_ROUTER_PATH": "$HOME/.claude-code-router/intent-router.js",
|
|
88
|
+
|
|
89
|
+
"Providers": [
|
|
90
|
+
{
|
|
91
|
+
"name": "openai",
|
|
92
|
+
"api_base_url": "https://api.openai.com/v1/chat/completions",
|
|
93
|
+
"api_key": "$OPENAI_API_KEY",
|
|
94
|
+
"models": ["gpt-4o", "gpt-4-turbo", "gpt-4o-mini", "o1", "o1-mini"],
|
|
95
|
+
"transformer": { "use": [] }
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "anthropic",
|
|
99
|
+
"api_base_url": "https://api.anthropic.com/v1/messages",
|
|
100
|
+
"api_key": "$ANTHROPIC_API_KEY",
|
|
101
|
+
"models": ["claude-sonnet-4-latest", "claude-3-5-sonnet-latest"],
|
|
102
|
+
"transformer": { "use": ["Anthropic"] }
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "gemini",
|
|
106
|
+
"api_base_url": "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions",
|
|
107
|
+
"api_key": "$GEMINI_API_KEY",
|
|
108
|
+
"models": ["gemini-2.5-flash", "gemini-2.5-pro", "gemini-2.0-flash"],
|
|
109
|
+
"transformer": { "use": ["gemini"] }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "qwen",
|
|
113
|
+
"api_base_url": "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions",
|
|
114
|
+
"api_key": "$QWEN_API_KEY",
|
|
115
|
+
"models": ["qwen-plus", "qwen-max", "qwen3-coder-plus", "qwen-turbo"],
|
|
116
|
+
"transformer": { "use": [] }
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "glm",
|
|
120
|
+
"api_base_url": "https://api.z.ai/api/paas/v4/chat/completions",
|
|
121
|
+
"api_key": "$GLM_API_KEY",
|
|
122
|
+
"models": ["glm-4.6", "glm-4.5", "glm-4-plus"],
|
|
123
|
+
"transformer": { "use": [] }
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
"name": "openrouter",
|
|
127
|
+
"api_base_url": "https://openrouter.ai/api/v1/chat/completions",
|
|
128
|
+
"api_key": "$OPENROUTER_API_KEY",
|
|
129
|
+
"models": [
|
|
130
|
+
"anthropic/claude-sonnet-4",
|
|
131
|
+
"deepseek/deepseek-chat",
|
|
132
|
+
"google/gemini-2.5-flash",
|
|
133
|
+
"meta-llama/llama-3.3-70b-instruct"
|
|
134
|
+
],
|
|
135
|
+
"transformer": { "use": ["openrouter"] }
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
|
|
139
|
+
"Router": {
|
|
140
|
+
"default": "openai,gpt-4o",
|
|
141
|
+
"background": "qwen,qwen-turbo",
|
|
142
|
+
"think": "anthropic,claude-sonnet-4-latest",
|
|
143
|
+
"longContext": "gemini,gemini-2.5-flash",
|
|
144
|
+
"longContextThreshold": 60000
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
EOF
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 3. intent-router.js
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
cat > ~/.claude-code-router/intent-router.js << 'EOF'
|
|
154
|
+
const INTENTS = {
|
|
155
|
+
CODING: {
|
|
156
|
+
patterns: [
|
|
157
|
+
/\b(implement|refactor|debug|fix|write|code|function|class|method|bug|error|compile|syntax)\b/i,
|
|
158
|
+
/\b(typescript|javascript|python|rust|go|java|react|vue|angular|swift|kotlin)\b/i,
|
|
159
|
+
/\b(api|endpoint|database|query|migration|schema|test|unit test)\b/i,
|
|
160
|
+
/\b(codex|o1|reasoning)\b/i
|
|
161
|
+
],
|
|
162
|
+
route: "openai,gpt-4o"
|
|
163
|
+
},
|
|
164
|
+
REASONING: {
|
|
165
|
+
patterns: [
|
|
166
|
+
/\b(architect|design|analyze|plan|strategy|structure|system|trade-?off)\b/i,
|
|
167
|
+
/\b(why|explain|reason|understand|compare|evaluate|consider|review)\b/i,
|
|
168
|
+
/\b(decision|approach|best practice|pattern|principle|philosophy)\b/i
|
|
169
|
+
],
|
|
170
|
+
route: "anthropic,claude-sonnet-4-latest"
|
|
171
|
+
},
|
|
172
|
+
FAST: {
|
|
173
|
+
patterns: [
|
|
174
|
+
/\b(fast|quick|brief|short|summary|tldr|overview|hızlı)\b/i,
|
|
175
|
+
/\b(scan|check|verify|validate)\b/i
|
|
176
|
+
],
|
|
177
|
+
route: "gemini,gemini-2.5-flash"
|
|
178
|
+
},
|
|
179
|
+
SIMPLE: {
|
|
180
|
+
patterns: [
|
|
181
|
+
/\b(list|show|what is|simple|basic|help|how to|format)\b/i,
|
|
182
|
+
/\b(rename|move|delete|create file|mkdir|copy)\b/i,
|
|
183
|
+
/\b(ucuz|basit|kolay)\b/i
|
|
184
|
+
],
|
|
185
|
+
route: "qwen,qwen-plus"
|
|
186
|
+
},
|
|
187
|
+
MULTILINGUAL: {
|
|
188
|
+
patterns: [
|
|
189
|
+
/\b(translate|çevir|tercüme|chinese|türkçe|multilingual)\b/i,
|
|
190
|
+
/[\u4e00-\u9fff]/,
|
|
191
|
+
/[\u0600-\u06FF]/,
|
|
192
|
+
],
|
|
193
|
+
route: "glm,glm-4.6"
|
|
194
|
+
},
|
|
195
|
+
HEAVY_REASONING: {
|
|
196
|
+
patterns: [
|
|
197
|
+
/\b(complex algorithm|optimization|performance critical|system design)\b/i,
|
|
198
|
+
/\b(prove|mathematical|theorem|formal verification)\b/i
|
|
199
|
+
],
|
|
200
|
+
route: "openai,o1"
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function extractContent(req) {
|
|
205
|
+
const messages = req.body?.messages || [];
|
|
206
|
+
return messages
|
|
207
|
+
.filter(m => m.role === "user" || m.role === "system")
|
|
208
|
+
.map(m => typeof m.content === "string" ? m.content : JSON.stringify(m.content))
|
|
209
|
+
.join(" ")
|
|
210
|
+
.slice(0, 3000);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function detectIntent(content) {
|
|
214
|
+
const scores = {};
|
|
215
|
+
for (const [intent, config] of Object.entries(INTENTS)) {
|
|
216
|
+
scores[intent] = config.patterns.reduce((score, pattern) => {
|
|
217
|
+
const matches = (content.match(pattern) || []).length;
|
|
218
|
+
return score + matches;
|
|
219
|
+
}, 0);
|
|
220
|
+
}
|
|
221
|
+
const sorted = Object.entries(scores)
|
|
222
|
+
.filter(([_, score]) => score > 0)
|
|
223
|
+
.sort((a, b) => b[1] - a[1]);
|
|
224
|
+
return sorted.length > 0 ? sorted[0][0] : null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
module.exports = async function router(req, config) {
|
|
228
|
+
const content = extractContent(req);
|
|
229
|
+
const intent = detectIntent(content);
|
|
230
|
+
if (intent && INTENTS[intent]) {
|
|
231
|
+
const route = INTENTS[intent].route;
|
|
232
|
+
console.log(`[Router] ${intent} → ${route}`);
|
|
233
|
+
return route;
|
|
234
|
+
}
|
|
235
|
+
console.log("[Router] No match → openai,gpt-4o");
|
|
236
|
+
return null;
|
|
237
|
+
};
|
|
238
|
+
EOF
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### 4. .zshrc Eklemeleri
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
cat >> ~/.zshrc << 'EOF'
|
|
245
|
+
|
|
246
|
+
# ═══════════════════════════════════════════════════
|
|
247
|
+
# Claude Code Router - API Keys
|
|
248
|
+
# ═══════════════════════════════════════════════════
|
|
249
|
+
export OPENAI_API_KEY="sk-..."
|
|
250
|
+
export ANTHROPIC_API_KEY="sk-ant-..."
|
|
251
|
+
export GEMINI_API_KEY="AIza..."
|
|
252
|
+
export QWEN_API_KEY="sk-..."
|
|
253
|
+
export GLM_API_KEY="..."
|
|
254
|
+
export OPENROUTER_API_KEY="sk-or-..."
|
|
255
|
+
|
|
256
|
+
# Router Connection
|
|
257
|
+
export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
|
|
258
|
+
export NO_PROXY="127.0.0.1"
|
|
259
|
+
EOF
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### 5. Başlat
|
|
263
|
+
|
|
264
|
+
```bash
|
|
265
|
+
source ~/.zshrc
|
|
266
|
+
ccr code
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## TEK SATIRLIK KURULUM
|
|
272
|
+
|
|
273
|
+
Tüm dosyaları tek seferde oluşturmak için:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
# 1. Kur
|
|
277
|
+
pnpm add -g @musistudio/claude-code-router && mkdir -p ~/.claude-code-router
|
|
278
|
+
|
|
279
|
+
# 2. Config'leri indir (bu repo'dan)
|
|
280
|
+
curl -sL https://raw.githubusercontent.com/YOUR_REPO/main/config.json > ~/.claude-code-router/config.json
|
|
281
|
+
curl -sL https://raw.githubusercontent.com/YOUR_REPO/main/intent-router.js > ~/.claude-code-router/intent-router.js
|
|
282
|
+
|
|
283
|
+
# 3. API key'leri .zshrc'ye ekle (manuel)
|
|
284
|
+
# 4. Başlat
|
|
285
|
+
source ~/.zshrc && ccr code
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## API KEY ALMA LİNKLERİ
|
|
291
|
+
|
|
292
|
+
| Provider | Link |
|
|
293
|
+
|----------|------|
|
|
294
|
+
| OpenAI | https://platform.openai.com/api-keys |
|
|
295
|
+
| Anthropic | https://console.anthropic.com/settings/keys |
|
|
296
|
+
| Gemini | https://aistudio.google.com/apikey |
|
|
297
|
+
| Qwen | https://dashscope.console.aliyun.com/apiKey |
|
|
298
|
+
| GLM | https://open.bigmodel.cn/usercenter/apikeys |
|
|
299
|
+
| OpenRouter | https://openrouter.ai/keys |
|