@halilertekin/claude-code-router-config 1.2.2 → 1.3.3

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/NPM_README.md ADDED
@@ -0,0 +1,165 @@
1
+ # Claude Code Router Config
2
+
3
+ [![npm version](https://badge.fury.io/js/@halilertekin%2Fclaude-code-router-config.svg)](https://badge.fury.io/js/@halilertekin%2Fclaude-code-router-config)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Multi-provider configuration for Claude Code Router with intelligent intent-based routing.
7
+
8
+ ## Quick Install
9
+
10
+ ```bash
11
+ npm install -g claude-code-router-config
12
+ ccr-setup
13
+ ```
14
+
15
+ ## Features
16
+
17
+ - **šŸ¤– 7 AI Providers**: OpenAI, Anthropic, Gemini, Qwen, GLM, OpenRouter, GitHub Copilot
18
+ - **šŸŽÆ Smart Routing**: Automatically selects the best model based on your request
19
+ - **šŸ’° Cost Optimized**: Simple tasks use cheaper models
20
+ - **⚔ Performance**: Fast responses use optimized models
21
+ - **šŸ› ļø Easy Setup**: One-command installation
22
+ - **šŸ“ Environment Support**: `.env` file support
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install -g @halilertekin/claude-code-router-config
28
+ ccr-setup
29
+ ```
30
+
31
+ ### Option 2: Homebrew
32
+
33
+ ```bash
34
+ brew install claude-code-router-config
35
+ ```
36
+
37
+ ### Option 3: Manual
38
+
39
+ ```bash
40
+ git clone https://github.com/YOUR_USERNAME/claude-code-router-config.git
41
+ cd claude-code-router-config
42
+ chmod +x install.sh
43
+ ./install.sh
44
+ ```
45
+
46
+ ## Setup
47
+
48
+ After installation:
49
+
50
+ 1. **Edit API keys** in `~/.env`:
51
+ ```bash
52
+ nano ~/.env
53
+ ```
54
+
55
+ 2. **Add to shell** (`~/.zshrc` or `~/.bashrc`):
56
+ ```bash
57
+ # Load .env variables
58
+ export $(cat ~/.env | xargs)
59
+
60
+ # Router connection
61
+ export ANTHROPIC_BASE_URL="http://127.0.0.1:3456"
62
+ export NO_PROXY="127.0.0.1"
63
+ ```
64
+
65
+ 3. **Reload shell**:
66
+ ```bash
67
+ source ~/.zshrc
68
+ ```
69
+
70
+ 4. **Start router**:
71
+ ```bash
72
+ ccr code
73
+ ```
74
+
75
+ ## API Keys
76
+
77
+ Get your API keys:
78
+
79
+ | Provider | Link |
80
+ |----------|------|
81
+ | OpenAI | https://platform.openai.com/api-keys |
82
+ | Anthropic | https://console.anthropic.com/settings/keys |
83
+ | Gemini | https://aistudio.google.com/apikey |
84
+ | Qwen | https://dashscope.console.aliyun.com/apiKey |
85
+ | GLM | https://open.bigmodel.cn/usercenter/apikeys |
86
+ | OpenRouter | https://openrouter.ai/keys |
87
+ | GitHub Copilot | https://github.com/settings/tokens |
88
+
89
+ ## Usage
90
+
91
+ ### Basic Commands
92
+
93
+ ```bash
94
+ ccr start # Start router
95
+ ccr code # Start with Claude Code
96
+ ccr status # Check status
97
+ ccr stop # Stop router
98
+ ```
99
+
100
+ ### Switch Models (Runtime)
101
+
102
+ Inside Claude Code:
103
+
104
+ ```
105
+ /model openai,gpt-4o
106
+ /model anthropic,claude-sonnet-4-latest
107
+ /model gemini,gemini-2.5-flash
108
+ /model qwen,qwen-plus
109
+ /model glm,glm-4.6
110
+ /model copilot,copilot
111
+ ```
112
+
113
+ ### Smart Routing Examples
114
+
115
+ ```bash
116
+ # Coding → OpenAI
117
+ claude "Write a Python sorting function"
118
+
119
+ # Analysis → Anthropic
120
+ claude "Explain microservices architecture"
121
+
122
+ # Quick summary → Gemini
123
+ claude "Quick summary of REST APIs"
124
+
125
+ # Simple task → Qwen
126
+ claude "List files in directory"
127
+
128
+ # Translation → GLM
129
+ claude "Translate to Chinese: Hello"
130
+
131
+ # Coding help → GitHub Copilot
132
+ claude "Help me debug this React component"
133
+ ```
134
+
135
+ ## Configuration Files
136
+
137
+ The installer creates:
138
+
139
+ ```
140
+ ~/.claude-code-router/
141
+ ā”œā”€ā”€ config.json # Provider configuration
142
+ ā”œā”€ā”€ intent-router.js # Smart routing logic
143
+ └── logs/ # Log files
144
+
145
+ ~/.env # API keys (created from .env.example)
146
+ ```
147
+
148
+ ## Documentation
149
+
150
+ - [Complete Documentation](https://github.com/halilertekin/claude-code-router-config/docs/FULL_DOCUMENTATION_EN.md)
151
+ - [GitHub Repository](https://github.com/halilertekin/claude-code-router-config)
152
+
153
+ ## Attribution
154
+
155
+ This package provides configuration for [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router), the original tool that enables Claude Code functionality with multiple AI providers.
156
+
157
+ The original Claude Code Router project is developed and maintained by musistudio. This package contains pre-configured routing logic and provider configurations.
158
+
159
+ ## License
160
+
161
+ MIT Ā© [Halil Ertekin](https://github.com/halilertekin)
162
+
163
+ ---
164
+
165
+ **Note**: This is a configuration package. Requires the original [@musistudio/claude-code-router](https://github.com/musistudio/claude-code-router) to function.
package/cli/commands.js CHANGED
@@ -219,71 +219,157 @@ function backupConfig() {
219
219
  }
220
220
  }
221
221
 
222
+ // Helper to find original ccr binary
223
+ function getOriginalCcrPath() {
224
+ try {
225
+ // Try to find it in dependencies
226
+ return require.resolve('@musistudio/claude-code-router/dist/cli.js');
227
+ } catch (e) {
228
+ return null;
229
+ }
230
+ }
231
+
232
+ // Proxy command to original router
233
+ function proxyToOriginal(args) {
234
+ const originalPath = getOriginalCcrPath();
235
+ if (!originalPath) {
236
+ console.error(chalk.red('āŒ Original @musistudio/claude-code-router not found.'));
237
+ return;
238
+ }
239
+
240
+ const child = spawn('node', [originalPath, ...args], {
241
+ stdio: 'inherit',
242
+ env: process.env
243
+ });
244
+
245
+ child.on('exit', (code) => {
246
+ if (code !== 0) {
247
+ process.exit(code || 1);
248
+ }
249
+ });
250
+ }
251
+
222
252
  // CLI command handler
223
253
  async function main() {
224
254
  const [command, ...args] = process.argv.slice(2);
225
-
226
- switch (command) {
227
- case 'test':
228
- const provider = args[0];
229
- const model = args[1];
230
- if (provider) {
231
- await testProvider(provider, model);
232
- } else {
233
- console.error(chalk.red('āŒ Please specify a provider: ccr test <provider> [model]'));
234
- }
235
- break;
236
-
237
- case 'benchmark':
238
- const options = {
239
- allProviders: args.includes('--all'),
240
- compareSpeed: args.includes('--compare-speed')
241
- };
242
- await benchmarkProviders(options);
243
- break;
244
-
245
- case 'status':
246
- const statusOptions = {
247
- detailed: args.includes('--detailed'),
248
- showCosts: args.includes('--show-costs')
249
- };
250
- await showDetailedStatus(statusOptions);
251
- break;
252
-
253
- case 'config':
254
- const configCommand = args[0];
255
- switch (configCommand) {
256
- case 'validate':
257
- validateConfig();
258
- break;
259
- case 'backup':
260
- backupConfig();
261
- break;
262
- default:
263
- console.log(chalk.yellow('Available config commands:'));
264
- console.log(' validate - Check configuration validity');
265
- console.log(' backup - Backup current configuration');
266
- }
267
- break;
268
-
269
- default:
270
- console.log(chalk.blue('Claude Code Router - Advanced CLI'));
271
- console.log(chalk.gray('─'.repeat(40)));
272
- console.log(chalk.yellow('Available commands:'));
273
- console.log('');
274
- console.log('Testing & Benchmarking:');
275
- console.log(' ccr test <provider> [model] - Test provider connection');
276
- console.log(' ccr benchmark [--all] [--compare-speed] - Benchmark providers');
277
- console.log(' ccr status [--detailed] [--show-costs] - Show router status');
278
- console.log('');
279
- console.log('Configuration Management:');
280
- console.log(' ccr config validate - Validate configuration');
281
- console.log(' ccr config backup - Backup configuration');
282
- console.log('');
283
- console.log('Examples:');
284
- console.log(' ccr test openai gpt-4o');
285
- console.log(' ccr benchmark --all --compare-speed');
286
- console.log(' ccr status --detailed --show-costs');
255
+ const advancedCommands = ['test', 'benchmark', 'analytics', 'status', 'config', 'health', 'update', 'help', 'version', '-v', '--version', '--help', '-h'];
256
+
257
+ // Check if it's an advanced command, help/version flag, or no command at all
258
+ const isAdvancedOrHelp = advancedCommands.includes(command) || !command;
259
+
260
+ if (isAdvancedOrHelp) {
261
+ switch (command) {
262
+ case 'update':
263
+ console.log(chalk.blue('šŸ”„ Checking for updates and updating...'));
264
+ const updateProcess = spawn('pnpm', ['add', '-g', '@halilertekin/claude-code-router-config@latest'], {
265
+ stdio: 'inherit',
266
+ env: process.env
267
+ });
268
+ updateProcess.on('exit', (code) => {
269
+ if (code === 0) {
270
+ console.log(chalk.green('āœ… Successfully updated to the latest version!'));
271
+ } else {
272
+ console.error(chalk.red(`āŒ Update failed with code ${code}. Please try running manually: pnpm add -g @halilertekin/claude-code-router-config@latest`));
273
+ }
274
+ });
275
+ break;
276
+
277
+ case 'version':
278
+ case '-v':
279
+ case '--version':
280
+ const packageJson = require('../package.json');
281
+ console.log(chalk.blue(`v${packageJson.version}`));
282
+ break;
283
+
284
+ case 'test':
285
+ const provider = args[0];
286
+ const model = args[1];
287
+ if (provider) {
288
+ await testProvider(provider, model);
289
+ } else {
290
+ console.error(chalk.red('āŒ Please specify a provider: ccr test <provider> [model]'));
291
+ }
292
+ break;
293
+
294
+ case 'benchmark':
295
+ const options = {
296
+ allProviders: args.includes('--all'),
297
+ compareSpeed: args.includes('--compare-speed')
298
+ };
299
+ await benchmarkProviders(options);
300
+ break;
301
+
302
+ case 'status':
303
+ if (args.includes('--detailed')) {
304
+ const statusOptions = {
305
+ detailed: true,
306
+ showCosts: args.includes('--show-costs')
307
+ };
308
+ await showDetailedStatus(statusOptions);
309
+ } else {
310
+ // Pass basic status to original router
311
+ proxyToOriginal(['status', ...args]);
312
+ }
313
+ break;
314
+
315
+ case 'analytics':
316
+ // Forward to analytics script
317
+ const analyticsPath = path.join(__dirname, 'analytics.js');
318
+ spawn('node', [analyticsPath, ...args], { stdio: 'inherit' });
319
+ break;
320
+
321
+ case 'health':
322
+ const healthPath = path.join(__dirname, '../logging/health-monitor.js');
323
+ spawn('node', [healthPath, ...args], { stdio: 'inherit' });
324
+ break;
325
+
326
+ case 'config':
327
+ const configCommand = args[0];
328
+ switch (configCommand) {
329
+ case 'validate':
330
+ validateConfig();
331
+ break;
332
+ case 'backup':
333
+ backupConfig();
334
+ break;
335
+ default:
336
+ console.log(chalk.yellow('Available config commands:'));
337
+ console.log(' validate - Check configuration validity');
338
+ console.log(' backup - Backup current configuration');
339
+ }
340
+ break;
341
+
342
+ default:
343
+ // Handles 'help', '--help', '-h' and empty command
344
+ console.log(chalk.blue('Claude Code Router - Advanced CLI (v1.3.3)'));
345
+ console.log(chalk.gray('─'.repeat(45)));
346
+
347
+ console.log(chalk.yellow('šŸš€ Advanced CLI Tools:'));
348
+ console.log(' test <provider> [model] - Test provider connection');
349
+ console.log(' benchmark [--all] [--compare-speed] - Benchmark providers');
350
+ console.log(' analytics [period] - View usage statistics');
351
+ console.log(' status --detailed [--show-costs] - Show detailed router status');
352
+ console.log(' config validate - Validate configuration');
353
+ console.log(' config backup - Backup configuration');
354
+ console.log(' health [--all-providers] - Check provider health');
355
+ console.log(' update - Update to the latest version');
356
+
357
+ console.log(chalk.yellow('\nšŸ“¦ Core Router Commands (Proxy):'));
358
+ console.log(' start - Start router server (Backend only)');
359
+ console.log(' stop - Stop router server');
360
+ console.log(' restart - Restart router server');
361
+ console.log(' status - Show server status');
362
+ console.log(' code - Start Router + Claude Code (Recommended)');
363
+ console.log(' model - Switch models at runtime');
364
+ console.log(' activate - Export env variables');
365
+
366
+ console.log(chalk.yellow('\nšŸ’” Tip:'));
367
+ console.log(' To start everything at once, run: ' + chalk.cyan('ccr code'));
368
+ console.log(' To only start the background server, run: ' + chalk.cyan('ccr start'));
369
+ }
370
+ } else {
371
+ // Forward unknown commands to the original router
372
+ proxyToOriginal([command, ...args]);
287
373
  }
288
374
  }
289
375
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@halilertekin/claude-code-router-config",
3
- "version": "1.2.2",
3
+ "version": "1.3.3",
4
4
  "description": "Multi-provider configuration for Claude Code Router with intent-based routing, advanced CLI tools, analytics, and smart routing. Setup OpenAI, Anthropic, Gemini, Qwen, GLM, OpenRouter, and GitHub Copilot with intelligent routing.",
5
5
  "main": "install.js",
6
6
  "bin": {
@@ -28,10 +28,13 @@
28
28
  "plugins/",
29
29
  "web-dashboard/",
30
30
  "install.sh",
31
+ "install.js",
32
+ "postinstall.js",
31
33
  ".env.example",
32
34
  "docs/",
33
35
  "LICENSE",
34
- "README.md"
36
+ "README.md",
37
+ "NPM_README.md"
35
38
  ],
36
39
  "keywords": [
37
40
  "claude",
@@ -83,7 +86,8 @@
83
86
  "fs-extra": "^11.1.1",
84
87
  "dotenv": "^16.3.1",
85
88
  "express": "^4.18.2",
86
- "cors": "^2.8.5"
89
+ "cors": "^2.8.5",
90
+ "@musistudio/claude-code-router": "^1.0.73"
87
91
  },
88
92
  "devDependencies": {
89
93
  "jest": "^29.7.0"
package/postinstall.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+
3
+ const chalk = require('chalk');
4
+
5
+ console.log(chalk.cyan(`
6
+ ╔════════════════════════════════════════════╗
7
+ ā•‘ Claude Code Router Config - Installed! ā•‘
8
+ ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
9
+
10
+ To complete setup:
11
+ 1. Add your API keys to ~/.env
12
+ 2. Run: ccr-setup
13
+ `));