@killingjacky/claude-code-router 2.1.1 → 2.2.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.
Files changed (60) hide show
  1. package/README.md +66 -19
  2. package/dist/cli.js +273 -277
  3. package/dist/main/cli.js +8896 -0
  4. package/dist/main/fusion-tool-fallback-mcp.js +5 -0
  5. package/dist/main/fusion-vision-mcp.js +10 -0
  6. package/dist/main/gateway-bootstrap.js +2 -0
  7. package/dist/main/local-agent-auth-provider-hook.js +294 -0
  8. package/dist/main/media-tools-proxy-mcp.js +6 -0
  9. package/dist/main/request-log-worker.js +951 -0
  10. package/dist/main/route-script-worker.js +61 -0
  11. package/dist/main/toolhub-mcp.js +48 -0
  12. package/dist/main/upstream-header-sanitizer.js +1 -0
  13. package/dist/models.json +657155 -0
  14. package/dist/renderer/assets/assets/anthropic-CJYB5ODC.png +0 -0
  15. package/dist/renderer/assets/assets/bailian-6RH6ASGG.ico +0 -0
  16. package/dist/renderer/assets/assets/claude-code-WX35JWK4.png +0 -0
  17. package/dist/renderer/assets/assets/claudeapi-A6VUG2I3.png +0 -0
  18. package/dist/renderer/assets/assets/code0-XF6QJ6WD.png +0 -0
  19. package/dist/renderer/assets/assets/codex-3X2KBXKY.png +0 -0
  20. package/dist/renderer/assets/assets/deepseek-ZIDCDTQF.ico +0 -0
  21. package/dist/renderer/assets/assets/fenno-XFKUO3XQ.jpg +0 -0
  22. package/dist/renderer/assets/assets/gemini-7QB7T63T.svg +1 -0
  23. package/dist/renderer/assets/assets/grok-RUIG6CO6.ico +0 -0
  24. package/dist/renderer/assets/assets/infistar-ai-QGWTTUZK.jpg +0 -0
  25. package/dist/renderer/assets/assets/kilo-WKXQUJ25.svg +13 -0
  26. package/dist/renderer/assets/assets/logo-IPLFWCDN.png +0 -0
  27. package/dist/renderer/assets/assets/mascot-transition-DUBPNIIV.svg +100 -0
  28. package/dist/renderer/assets/assets/minimax-5TL6POE3.ico +0 -0
  29. package/dist/renderer/assets/assets/mistral-2RFSC6K3.webp +0 -0
  30. package/dist/renderer/assets/assets/moonshot-FNEXMLNW.ico +0 -0
  31. package/dist/renderer/assets/assets/nvidia-CCRWBFBH.svg +1 -0
  32. package/dist/renderer/assets/assets/openai-2EIP7LI2.png +0 -0
  33. package/dist/renderer/assets/assets/opencode-CEWXDOQI.ico +0 -0
  34. package/dist/renderer/assets/assets/openrouter-CZIFREDB.ico +0 -0
  35. package/dist/renderer/assets/assets/pi-O6OOC4YY.svg +21 -0
  36. package/dist/renderer/assets/assets/qiniu-ai-A5VJAOJ6.png +0 -0
  37. package/dist/renderer/assets/assets/runapi-UAX35AOL.jpg +0 -0
  38. package/dist/renderer/assets/assets/siliconflow-QCZUQAH2.png +0 -0
  39. package/dist/renderer/assets/assets/teamorouter-3LCEETRZ.png +0 -0
  40. package/dist/renderer/assets/assets/tray-cyan-C3U4WBE7.png +0 -0
  41. package/dist/renderer/assets/assets/tray-orange-VUJTRHBB.png +0 -0
  42. package/dist/renderer/assets/assets/tray-violet-EGMLZ2GB.png +0 -0
  43. package/dist/renderer/assets/assets/unity2-QCJYG2D6.jpg +0 -0
  44. package/dist/renderer/assets/assets/workbuddy-LBUELROU.png +0 -0
  45. package/dist/renderer/assets/assets/xiaomi-mimo-LQ6RRXCR.png +0 -0
  46. package/dist/renderer/assets/assets/zai-global-coding-OMCES3LL.svg +219 -0
  47. package/dist/renderer/assets/assets/zai-global-general-OMCES3LL.svg +219 -0
  48. package/dist/renderer/assets/assets/zcode-Z7V7YY2Q.png +0 -0
  49. package/dist/renderer/assets/assets/zhipu-cn-coding-7BBWPUTC.png +0 -0
  50. package/dist/renderer/assets/assets/zhipu-cn-general-7BBWPUTC.png +0 -0
  51. package/dist/renderer/assets/browser.js +408 -0
  52. package/dist/renderer/assets/log-body.worker.js +3 -0
  53. package/dist/renderer/assets/main.css +2 -0
  54. package/dist/renderer/assets/main.js +103 -0
  55. package/dist/renderer/assets/tray.js +8 -0
  56. package/dist/renderer/assets/web-client-bridge.js +1 -0
  57. package/dist/renderer/pages/browser/index.html +13 -0
  58. package/dist/renderer/pages/home/index.html +18 -0
  59. package/dist/renderer/pages/tray/index.html +17 -0
  60. package/package.json +5 -2
package/README.md CHANGED
@@ -195,12 +195,13 @@ Here is a comprehensive example:
195
195
  }
196
196
  ],
197
197
  "Router": {
198
- "default": "deepseek,deepseek-chat",
199
- "background": "ollama,qwen2.5-coder:latest",
200
- "think": "deepseek,deepseek-reasoner",
201
- "longContext": "openrouter,google/gemini-2.5-pro-preview",
202
- "longContextThreshold": 60000,
203
- "webSearch": "gemini,gemini-2.5-flash"
198
+ "primary": "deepseek,deepseek-chat",
199
+ "aliases": {
200
+ "haiku": "ollama,qwen2.5-coder:latest"
201
+ },
202
+ "capabilities": {
203
+ "webSearch": "gemini,gemini-2.5-flash"
204
+ }
204
205
  }
205
206
  }
206
207
  ```
@@ -243,7 +244,7 @@ ccr model
243
244
  This command provides an interactive interface to:
244
245
 
245
246
  - View current configuration:
246
- - See all configured models (default, background, think, longContext, webSearch, image)
247
+ - See all configured primary, alias, and capability models
247
248
  - Switch models: Quickly change which model is used for each router type
248
249
  - Add new models: Add models to existing providers
249
250
  - Create new providers: Set up complete provider configurations including:
@@ -314,6 +315,7 @@ The `activate` command sets the following environment variables:
314
315
 
315
316
  - `ANTHROPIC_AUTH_TOKEN`: API key from your configuration
316
317
  - `ANTHROPIC_BASE_URL`: The local router endpoint (default: `http://127.0.0.1:3456`)
318
+ - `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY`: Enables Claude Code's `/model` picker to list every configured CCR provider/model pair
317
319
  - `NO_PROXY`: Set to `127.0.0.1` to prevent proxy interference
318
320
  - `DISABLE_TELEMETRY`: Disables telemetry
319
321
  - `DISABLE_COST_WARNINGS`: Disables cost warnings
@@ -321,6 +323,8 @@ The `activate` command sets the following environment variables:
321
323
 
322
324
  > **Note**: Make sure the Claude Code Router service is running (`ccr start`) before using the activated environment variables. The environment variables are only valid for the current shell session. To make them persistent, you can add `eval "$(ccr activate)"` to your shell configuration file (e.g., `~/.zshrc` or `~/.bashrc`).
323
325
 
326
+ After activation, run `/model` in Claude Code to select a configured model directly. Each entry is shown as `provider, model`; CCR routes it to that exact configured provider and model.
327
+
324
328
  #### Providers
325
329
 
326
330
  The `Providers` array is where you define the different model providers you want to use. Each provider object requires:
@@ -329,8 +333,18 @@ The `Providers` array is where you define the different model providers you want
329
333
  - `api_base_url`: The full API endpoint for chat completions.
330
334
  - `api_key`: Your API key for the provider.
331
335
  - `models`: A list of model names available from this provider.
336
+ - `models_1m` (optional): A list of models that support a 1-million-token context window. Each entry must also be present in `models`; Claude Code then shows it as an additional `[1M]` option. Entries that are not in `models` are ignored for gateway discovery.
332
337
  - `transformer` (optional): Specifies transformers to process requests and responses.
333
338
 
339
+ For example, this configuration shows `gpt-5.4` in Claude Code both normally and as `gpt-5.4 [1M]`, while `gpt-5.4-mini` is shown only normally:
340
+
341
+ ```json
342
+ {
343
+ "models": ["gpt-5.4", "gpt-5.4-mini"],
344
+ "models_1m": ["gpt-5.4"]
345
+ }
346
+ ```
347
+
334
348
  #### Transformers
335
349
 
336
350
  Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs.
@@ -439,15 +453,15 @@ You can also create your own transformers and load them via the `transformers` f
439
453
 
440
454
  #### Router
441
455
 
442
- The `Router` object defines which model to use for different scenarios:
456
+ The `Router` object uses explicit intent and model capabilities:
443
457
 
444
- - `default`: The default model for general tasks.
445
- - `background`: A model for background tasks. This can be a smaller, local model to save costs.
446
- - `think`: A model for reasoning-heavy tasks, like Plan Mode.
447
- - `longContext`: A model for handling long contexts (e.g., > 60K tokens).
448
- - `longContextThreshold` (optional): The token count threshold for triggering the long context model. Defaults to 60000 if not specified.
449
- - `webSearch`: Used for handling web search tasks and this requires the model itself to support the feature. If you're using openrouter, you need to add the `:online` suffix after the model name.
450
- - `image` (beta): Used for handling image-related tasks (supported by CCR’s built-in agent). If the model does not support tool calling, you need to set the `config.forceUseImageAgent` property to `true`.
458
+ - `primary`: The general-purpose model. `default` remains a legacy synonym.
459
+ - `aliases`: Maps Claude Code's `haiku`, `sonnet`, and `opus` model intents to provider models. `background` remains a legacy synonym for `aliases.haiku`.
460
+ - `capabilities.webSearch`: A model for Anthropic web-search requests. `webSearch` remains a legacy synonym.
461
+ - `capabilities.vision`: A vision-capable model for current user images. `image` remains a legacy synonym and CCR's image agent handles historical-image fallback.
462
+ - `subagents`: Maps explicit `<CCR-ROUTE>profile</CCR-ROUTE>` tags in custom subagent system prompts to provider models.
463
+
464
+ CCR does not route on `thinking` or estimated context length. Claude Code owns adaptive thinking, 200K/1M context selection, and compaction.
451
465
 
452
466
  - You can also switch models dynamically in Claude Code with the `/model` command:
453
467
  `/model provider_name,model_name`
@@ -494,15 +508,48 @@ module.exports = async function router(req, config) {
494
508
 
495
509
  ##### Subagent Routing
496
510
 
497
- For routing within subagents, you must specify a particular provider and model by including `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` at the **beginning** of the subagent's prompt. This allows you to direct specific subagent tasks to designated models.
511
+ Claude Code custom agents are Markdown files in `~/.claude/agents/` (or
512
+ `.claude/agents/` in a project). Give each agent a native Claude model alias and
513
+ an explicit CCR route profile in its prompt:
514
+
515
+ ```markdown
516
+ ---
517
+ name: ccr-explore
518
+ description: Fast, read-only codebase exploration.
519
+ model: haiku
520
+ tools: Read, Glob, Grep
521
+ ---
498
522
 
499
- **Example:**
523
+ <CCR-ROUTE>explore</CCR-ROUTE>
500
524
 
525
+ Explore the codebase and report concise, evidence-backed findings. Do not modify files.
501
526
  ```
502
- <CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
503
- Please help me analyze this code snippet for potential optimizations...
527
+
528
+ Map the profile and give it its own fallback list. Profile fallbacks are
529
+ intentional: `Fallback.subagents.explore` does not implicitly inherit the
530
+ `haiku` alias fallback.
531
+
532
+ ```json
533
+ {
534
+ "Router": {
535
+ "subagents": {
536
+ "explore": "groq,llama-3.3-70b-versatile"
537
+ }
538
+ },
539
+ "Fallback": {
540
+ "subagents": {
541
+ "explore": ["openrouter,meta-llama/llama-3.3-70b-instruct"]
542
+ }
543
+ }
544
+ }
504
545
  ```
505
546
 
547
+ Use the agent with `ccr code --agent ccr-explore`, or ask Claude Code to use
548
+ the named agent. CCR removes the route tag before forwarding the request.
549
+
550
+ `<CCR-SUBAGENT-MODEL>provider,model</CCR-SUBAGENT-MODEL>` remains available as
551
+ a legacy per-prompt override; it takes precedence over a profile tag.
552
+
506
553
  ## Status Line (Beta)
507
554
  To better monitor the status of claude-code-router at runtime, version v1.0.40 includes a built-in statusline tool, which you can enable in the UI.
508
555
  ![statusline-config.png](/blog/images/statusline-config.png)