@musistudio/claude-code-router 1.0.73 → 3.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.
Files changed (49) hide show
  1. package/README.md +320 -653
  2. package/README_zh.md +320 -601
  3. package/dist/main/cli.js +5242 -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/toolhub-mcp.js +47 -0
  7. package/dist/marketplace/plugins/claude-design-plugin.cjs +8216 -0
  8. package/dist/marketplace/plugins/cursor-proxy-plugin.cjs +7080 -0
  9. package/dist/models.json +490722 -0
  10. package/dist/renderer/assets/assets/anthropic-CJYB5ODC.png +0 -0
  11. package/dist/renderer/assets/assets/bailian-6RH6ASGG.ico +0 -0
  12. package/dist/renderer/assets/assets/claude-code-WX35JWK4.png +0 -0
  13. package/dist/renderer/assets/assets/codex-3X2KBXKY.png +0 -0
  14. package/dist/renderer/assets/assets/deepseek-ZIDCDTQF.ico +0 -0
  15. package/dist/renderer/assets/assets/gemini-7QB7T63T.svg +1 -0
  16. package/dist/renderer/assets/assets/logo-IPLFWCDN.png +0 -0
  17. package/dist/renderer/assets/assets/mascot-transition-DUBPNIIV.svg +100 -0
  18. package/dist/renderer/assets/assets/mistral-2RFSC6K3.webp +0 -0
  19. package/dist/renderer/assets/assets/moonshot-FNEXMLNW.ico +0 -0
  20. package/dist/renderer/assets/assets/openai-2EIP7LI2.png +0 -0
  21. package/dist/renderer/assets/assets/openrouter-CZIFREDB.ico +0 -0
  22. package/dist/renderer/assets/assets/runapi-UAX35AOL.jpg +0 -0
  23. package/dist/renderer/assets/assets/siliconflow-QCZUQAH2.png +0 -0
  24. package/dist/renderer/assets/assets/teamorouter-3LCEETRZ.png +0 -0
  25. package/dist/renderer/assets/assets/tray-cyan-C3U4WBE7.png +0 -0
  26. package/dist/renderer/assets/assets/tray-orange-VUJTRHBB.png +0 -0
  27. package/dist/renderer/assets/assets/tray-violet-EGMLZ2GB.png +0 -0
  28. package/dist/renderer/assets/assets/zai-global-coding-OMCES3LL.svg +219 -0
  29. package/dist/renderer/assets/assets/zai-global-general-OMCES3LL.svg +219 -0
  30. package/dist/renderer/assets/assets/zcode-Z7V7YY2Q.png +0 -0
  31. package/dist/renderer/assets/assets/zhipu-cn-coding-7BBWPUTC.png +0 -0
  32. package/dist/renderer/assets/assets/zhipu-cn-general-7BBWPUTC.png +0 -0
  33. package/dist/renderer/assets/browser.js +312 -0
  34. package/dist/renderer/assets/main.css +2 -0
  35. package/dist/renderer/assets/main.js +158 -0
  36. package/dist/renderer/assets/tray.js +8 -0
  37. package/dist/renderer/assets/web-client-bridge.js +1 -0
  38. package/dist/renderer/pages/browser/index.html +13 -0
  39. package/dist/renderer/pages/home/index.html +18 -0
  40. package/dist/renderer/pages/tray/index.html +17 -0
  41. package/package.json +36 -38
  42. package/.dockerignore +0 -2
  43. package/Dockerfile +0 -7
  44. package/custom-router.example.js +0 -3
  45. package/dist/cli.js +0 -88650
  46. package/dist/index.html +0 -439
  47. package/dist/tiktoken_bg.wasm +0 -0
  48. package/docker-compose.yml +0 -10
  49. package/tsconfig.json +0 -20
package/README.md CHANGED
@@ -1,662 +1,329 @@
1
- ![](blog/images/claude-code-router-img.png)
1
+ <h1 align="center">Claude Code Router Desktop</h1>
2
2
 
3
- [![](https://img.shields.io/badge/%F0%9F%87%A8%F0%9F%87%B3-%E4%B8%AD%E6%96%87%E7%89%88-ff0000?style=flat)](README_zh.md)
4
- [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white)](https://discord.gg/rdftVMaUcS)
5
- [![](https://img.shields.io/github/license/musistudio/claude-code-router)](https://github.com/musistudio/claude-code-router/blob/main/LICENSE)
6
-
7
- <hr>
8
-
9
- ![](blog/images/sponsors/glm-en.jpg)
10
- > This project is sponsored by Z.ai, supporting us with their GLM CODING PLAN.
11
- > GLM CODING PLAN is a subscription service designed for AI coding, starting at just $3/month. It provides access to their flagship GLM-4.6 model across 10+ popular AI coding tools (Claude Code, Cline, Roo Code, etc.), offering developers top-tier, fast, and stable coding experiences.
12
- > Get 10% OFF GLM CODING PLAN:https://z.ai/subscribe?ic=8JVLJQFSKB
13
-
14
- > A powerful tool to route Claude Code requests to different models and customize any request.
15
-
16
- > [GLM-4.6 Supports Reasoning and Interleaved Thinking](blog/en/glm-4.6-supports-reasoning.md)
17
-
18
- ![](blog/images/claude-code.png)
19
-
20
- ## Features
21
-
22
- - **Model Routing**: Route requests to different models based on your needs (e.g., background tasks, thinking, long context).
23
- - **Multi-Provider Support**: Supports various model providers like OpenRouter, DeepSeek, Ollama, Gemini, Volcengine, and SiliconFlow.
24
- - **Request/Response Transformation**: Customize requests and responses for different providers using transformers.
25
- - **Dynamic Model Switching**: Switch models on-the-fly within Claude Code using the `/model` command.
26
- - **CLI Model Management**: Manage models and providers directly from the terminal with `ccr model`.
27
- - **GitHub Actions Integration**: Trigger Claude Code tasks in your GitHub workflows.
28
- - **Plugin System**: Extend functionality with custom transformers.
29
-
30
- ## 🚀 Getting Started
31
-
32
- ### 1. Installation
33
-
34
- First, ensure you have [Claude Code](https://docs.anthropic.com/en/docs/claude-code/quickstart) installed:
35
-
36
- ```shell
37
- npm install -g @anthropic-ai/claude-code
38
- ```
39
-
40
- Then, install Claude Code Router:
41
-
42
- ```shell
43
- npm install -g @musistudio/claude-code-router
44
- ```
45
-
46
- ### 2. Configuration
47
-
48
- Create and configure your `~/.claude-code-router/config.json` file. For more details, you can refer to `config.example.json`.
49
-
50
- The `config.json` file has several key sections:
51
-
52
- - **`PROXY_URL`** (optional): You can set a proxy for API requests, for example: `"PROXY_URL": "http://127.0.0.1:7890"`.
53
- - **`LOG`** (optional): You can enable logging by setting it to `true`. When set to `false`, no log files will be created. Default is `true`.
54
- - **`LOG_LEVEL`** (optional): Set the logging level. Available options are: `"fatal"`, `"error"`, `"warn"`, `"info"`, `"debug"`, `"trace"`. Default is `"debug"`.
55
- - **Logging Systems**: The Claude Code Router uses two separate logging systems:
56
- - **Server-level logs**: HTTP requests, API calls, and server events are logged using pino in the `~/.claude-code-router/logs/` directory with filenames like `ccr-*.log`
57
- - **Application-level logs**: Routing decisions and business logic events are logged in `~/.claude-code-router/claude-code-router.log`
58
- - **`APIKEY`** (optional): You can set a secret key to authenticate requests. When set, clients must provide this key in the `Authorization` header (e.g., `Bearer your-secret-key`) or the `x-api-key` header. Example: `"APIKEY": "your-secret-key"`.
59
- - **`HOST`** (optional): You can set the host address for the server. If `APIKEY` is not set, the host will be forced to `127.0.0.1` for security reasons to prevent unauthorized access. Example: `"HOST": "0.0.0.0"`.
60
- - **`NON_INTERACTIVE_MODE`** (optional): When set to `true`, enables compatibility with non-interactive environments like GitHub Actions, Docker containers, or other CI/CD systems. This sets appropriate environment variables (`CI=true`, `FORCE_COLOR=0`, etc.) and configures stdin handling to prevent the process from hanging in automated environments. Example: `"NON_INTERACTIVE_MODE": true`.
61
-
62
- - **`Providers`**: Used to configure different model providers.
63
- - **`Router`**: Used to set up routing rules. `default` specifies the default model, which will be used for all requests if no other route is configured.
64
- - **`API_TIMEOUT_MS`**: Specifies the timeout for API calls in milliseconds.
65
-
66
- #### Environment Variable Interpolation
67
-
68
- Claude Code Router supports environment variable interpolation for secure API key management. You can reference environment variables in your `config.json` using either `$VAR_NAME` or `${VAR_NAME}` syntax:
69
-
70
- ```json
71
- {
72
- "OPENAI_API_KEY": "$OPENAI_API_KEY",
73
- "GEMINI_API_KEY": "${GEMINI_API_KEY}",
74
- "Providers": [
75
- {
76
- "name": "openai",
77
- "api_base_url": "https://api.openai.com/v1/chat/completions",
78
- "api_key": "$OPENAI_API_KEY",
79
- "models": ["gpt-5", "gpt-5-mini"]
80
- }
81
- ]
82
- }
83
- ```
84
-
85
- This allows you to keep sensitive API keys in environment variables instead of hardcoding them in configuration files. The interpolation works recursively through nested objects and arrays.
86
-
87
- Here is a comprehensive example:
88
-
89
- ```json
90
- {
91
- "APIKEY": "your-secret-key",
92
- "PROXY_URL": "http://127.0.0.1:7890",
93
- "LOG": true,
94
- "API_TIMEOUT_MS": 600000,
95
- "NON_INTERACTIVE_MODE": false,
96
- "Providers": [
97
- {
98
- "name": "openrouter",
99
- "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
100
- "api_key": "sk-xxx",
101
- "models": [
102
- "google/gemini-2.5-pro-preview",
103
- "anthropic/claude-sonnet-4",
104
- "anthropic/claude-3.5-sonnet",
105
- "anthropic/claude-3.7-sonnet:thinking"
106
- ],
107
- "transformer": {
108
- "use": ["openrouter"]
109
- }
110
- },
111
- {
112
- "name": "deepseek",
113
- "api_base_url": "https://api.deepseek.com/chat/completions",
114
- "api_key": "sk-xxx",
115
- "models": ["deepseek-chat", "deepseek-reasoner"],
116
- "transformer": {
117
- "use": ["deepseek"],
118
- "deepseek-chat": {
119
- "use": ["tooluse"]
120
- }
121
- }
122
- },
123
- {
124
- "name": "ollama",
125
- "api_base_url": "http://localhost:11434/v1/chat/completions",
126
- "api_key": "ollama",
127
- "models": ["qwen2.5-coder:latest"]
128
- },
129
- {
130
- "name": "gemini",
131
- "api_base_url": "https://generativelanguage.googleapis.com/v1beta/models/",
132
- "api_key": "sk-xxx",
133
- "models": ["gemini-2.5-flash", "gemini-2.5-pro"],
134
- "transformer": {
135
- "use": ["gemini"]
136
- }
137
- },
138
- {
139
- "name": "volcengine",
140
- "api_base_url": "https://ark.cn-beijing.volces.com/api/v3/chat/completions",
141
- "api_key": "sk-xxx",
142
- "models": ["deepseek-v3-250324", "deepseek-r1-250528"],
143
- "transformer": {
144
- "use": ["deepseek"]
145
- }
146
- },
147
- {
148
- "name": "modelscope",
149
- "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions",
150
- "api_key": "",
151
- "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct", "Qwen/Qwen3-235B-A22B-Thinking-2507"],
152
- "transformer": {
153
- "use": [
154
- [
155
- "maxtoken",
156
- {
157
- "max_tokens": 65536
158
- }
159
- ],
160
- "enhancetool"
161
- ],
162
- "Qwen/Qwen3-235B-A22B-Thinking-2507": {
163
- "use": ["reasoning"]
164
- }
165
- }
166
- },
167
- {
168
- "name": "dashscope",
169
- "api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions",
170
- "api_key": "",
171
- "models": ["qwen3-coder-plus"],
172
- "transformer": {
173
- "use": [
174
- [
175
- "maxtoken",
176
- {
177
- "max_tokens": 65536
178
- }
179
- ],
180
- "enhancetool"
181
- ]
182
- }
183
- },
184
- {
185
- "name": "aihubmix",
186
- "api_base_url": "https://aihubmix.com/v1/chat/completions",
187
- "api_key": "sk-",
188
- "models": [
189
- "Z/glm-4.5",
190
- "claude-opus-4-20250514",
191
- "gemini-2.5-pro"
192
- ]
193
- }
194
- ],
195
- "Router": {
196
- "default": "deepseek,deepseek-chat",
197
- "background": "ollama,qwen2.5-coder:latest",
198
- "think": "deepseek,deepseek-reasoner",
199
- "longContext": "openrouter,google/gemini-2.5-pro-preview",
200
- "longContextThreshold": 60000,
201
- "webSearch": "gemini,gemini-2.5-flash"
202
- }
203
- }
204
- ```
205
-
206
- ### 3. Running Claude Code with the Router
207
-
208
- Start Claude Code using the router:
209
-
210
- ```shell
211
- ccr code
212
- ```
213
-
214
- > **Note**: After modifying the configuration file, you need to restart the service for the changes to take effect:
215
- >
216
- > ```shell
217
- > ccr restart
218
- > ```
219
-
220
- ### 4. UI Mode
221
-
222
- For a more intuitive experience, you can use the UI mode to manage your configuration:
223
-
224
- ```shell
225
- ccr ui
226
- ```
227
-
228
- This will open a web-based interface where you can easily view and edit your `config.json` file.
229
-
230
- ![UI](/blog/images/ui.png)
231
-
232
- ### 5. CLI Model Management
233
-
234
- For users who prefer terminal-based workflows, you can use the interactive CLI model selector:
235
-
236
- ```shell
237
- ccr model
238
- ```
239
- ![](blog/images/models.gif)
240
-
241
- This command provides an interactive interface to:
242
-
243
- - View current configuration:
244
- - See all configured models (default, background, think, longContext, webSearch, image)
245
- - Switch models: Quickly change which model is used for each router type
246
- - Add new models: Add models to existing providers
247
- - Create new providers: Set up complete provider configurations including:
248
- - Provider name and API endpoint
249
- - API key
250
- - Available models
251
- - Transformer configuration with support for:
252
- - Multiple transformers (openrouter, deepseek, gemini, etc.)
253
- - Transformer options (e.g., maxtoken with custom limits)
254
- - Provider-specific routing (e.g., OpenRouter provider preferences)
255
-
256
- The CLI tool validates all inputs and provides helpful prompts to guide you through the configuration process, making it easy to manage complex setups without editing JSON files manually.
257
-
258
- ### 6. Activate Command (Environment Variables Setup)
259
-
260
- The `activate` command allows you to set up environment variables globally in your shell, enabling you to use the `claude` command directly or integrate Claude Code Router with applications built using the Agent SDK.
261
-
262
- To activate the environment variables, run:
263
-
264
- ```shell
265
- eval "$(ccr activate)"
266
- ```
267
-
268
- This command outputs the necessary environment variables in shell-friendly format, which are then set in your current shell session. After activation, you can:
269
-
270
- - **Use `claude` command directly**: Run `claude` commands without needing to use `ccr code`. The `claude` command will automatically route requests through Claude Code Router.
271
- - **Integrate with Agent SDK applications**: Applications built with the Anthropic Agent SDK will automatically use the configured router and models.
272
-
273
- The `activate` command sets the following environment variables:
274
-
275
- - `ANTHROPIC_AUTH_TOKEN`: API key from your configuration
276
- - `ANTHROPIC_BASE_URL`: The local router endpoint (default: `http://127.0.0.1:3456`)
277
- - `NO_PROXY`: Set to `127.0.0.1` to prevent proxy interference
278
- - `DISABLE_TELEMETRY`: Disables telemetry
279
- - `DISABLE_COST_WARNINGS`: Disables cost warnings
280
- - `API_TIMEOUT_MS`: API timeout from your configuration
281
-
282
- > **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`).
283
-
284
- #### Providers
285
-
286
- The `Providers` array is where you define the different model providers you want to use. Each provider object requires:
287
-
288
- - `name`: A unique name for the provider.
289
- - `api_base_url`: The full API endpoint for chat completions.
290
- - `api_key`: Your API key for the provider.
291
- - `models`: A list of model names available from this provider.
292
- - `transformer` (optional): Specifies transformers to process requests and responses.
293
-
294
- #### Transformers
295
-
296
- Transformers allow you to modify the request and response payloads to ensure compatibility with different provider APIs.
297
-
298
- - **Global Transformer**: Apply a transformer to all models from a provider. In this example, the `openrouter` transformer is applied to all models under the `openrouter` provider.
299
- ```json
300
- {
301
- "name": "openrouter",
302
- "api_base_url": "https://openrouter.ai/api/v1/chat/completions",
303
- "api_key": "sk-xxx",
304
- "models": [
305
- "google/gemini-2.5-pro-preview",
306
- "anthropic/claude-sonnet-4",
307
- "anthropic/claude-3.5-sonnet"
308
- ],
309
- "transformer": { "use": ["openrouter"] }
310
- }
311
- ```
312
- - **Model-Specific Transformer**: Apply a transformer to a specific model. In this example, the `deepseek` transformer is applied to all models, and an additional `tooluse` transformer is applied only to the `deepseek-chat` model.
313
-
314
- ```json
315
- {
316
- "name": "deepseek",
317
- "api_base_url": "https://api.deepseek.com/chat/completions",
318
- "api_key": "sk-xxx",
319
- "models": ["deepseek-chat", "deepseek-reasoner"],
320
- "transformer": {
321
- "use": ["deepseek"],
322
- "deepseek-chat": { "use": ["tooluse"] }
323
- }
324
- }
325
- ```
326
-
327
- - **Passing Options to a Transformer**: Some transformers, like `maxtoken`, accept options. To pass options, use a nested array where the first element is the transformer name and the second is an options object.
328
- ```json
329
- {
330
- "name": "siliconflow",
331
- "api_base_url": "https://api.siliconflow.cn/v1/chat/completions",
332
- "api_key": "sk-xxx",
333
- "models": ["moonshotai/Kimi-K2-Instruct"],
334
- "transformer": {
335
- "use": [
336
- [
337
- "maxtoken",
338
- {
339
- "max_tokens": 16384
340
- }
341
- ]
342
- ]
343
- }
344
- }
345
- ```
346
-
347
- **Available Built-in Transformers:**
348
-
349
- - `Anthropic`:If you use only the `Anthropic` transformer, it will preserve the original request and response parameters(you can use it to connect directly to an Anthropic endpoint).
350
- - `deepseek`: Adapts requests/responses for DeepSeek API.
351
- - `gemini`: Adapts requests/responses for Gemini API.
352
- - `openrouter`: Adapts requests/responses for OpenRouter API. It can also accept a `provider` routing parameter to specify which underlying providers OpenRouter should use. For more details, refer to the [OpenRouter documentation](https://openrouter.ai/docs/features/provider-routing). See an example below:
353
- ```json
354
- "transformer": {
355
- "use": ["openrouter"],
356
- "moonshotai/kimi-k2": {
357
- "use": [
358
- [
359
- "openrouter",
360
- {
361
- "provider": {
362
- "only": ["moonshotai/fp8"]
363
- }
364
- }
365
- ]
366
- ]
367
- }
368
- }
369
- ```
370
- - `groq`: Adapts requests/responses for groq API.
371
- - `maxtoken`: Sets a specific `max_tokens` value.
372
- - `tooluse`: Optimizes tool usage for certain models via `tool_choice`.
373
- - `gemini-cli` (experimental): Unofficial support for Gemini via Gemini CLI [gemini-cli.js](https://gist.github.com/musistudio/1c13a65f35916a7ab690649d3df8d1cd).
374
- - `reasoning`: Used to process the `reasoning_content` field.
375
- - `sampling`: Used to process sampling information fields such as `temperature`, `top_p`, `top_k`, and `repetition_penalty`.
376
- - `enhancetool`: Adds a layer of error tolerance to the tool call parameters returned by the LLM (this will cause the tool call information to no longer be streamed).
377
- - `cleancache`: Clears the `cache_control` field from requests.
378
- - `vertex-gemini`: Handles the Gemini API using Vertex authentication.
379
- - `chutes-glm` Unofficial support for GLM 4.5 model via Chutes [chutes-glm-transformer.js](https://gist.github.com/vitobotta/2be3f33722e05e8d4f9d2b0138b8c863).
380
- - `qwen-cli` (experimental): Unofficial support for qwen3-coder-plus model via Qwen CLI [qwen-cli.js](https://gist.github.com/musistudio/f5a67841ced39912fd99e42200d5ca8b).
381
- - `rovo-cli` (experimental): Unofficial support for gpt-5 via Atlassian Rovo Dev CLI [rovo-cli.js](https://gist.github.com/SaseQ/c2a20a38b11276537ec5332d1f7a5e53).
382
-
383
- **Custom Transformers:**
384
-
385
- You can also create your own transformers and load them via the `transformers` field in `config.json`.
386
-
387
- ```json
388
- {
389
- "transformers": [
390
- {
391
- "path": "/User/xxx/.claude-code-router/plugins/gemini-cli.js",
392
- "options": {
393
- "project": "xxx"
394
- }
395
- }
396
- ]
397
- }
398
- ```
399
-
400
- #### Router
401
-
402
- The `Router` object defines which model to use for different scenarios:
403
-
404
- - `default`: The default model for general tasks.
405
- - `background`: A model for background tasks. This can be a smaller, local model to save costs.
406
- - `think`: A model for reasoning-heavy tasks, like Plan Mode.
407
- - `longContext`: A model for handling long contexts (e.g., > 60K tokens).
408
- - `longContextThreshold` (optional): The token count threshold for triggering the long context model. Defaults to 60000 if not specified.
409
- - `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.
410
- - `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`.
411
-
412
- - You can also switch models dynamically in Claude Code with the `/model` command:
413
- `/model provider_name,model_name`
414
- Example: `/model openrouter,anthropic/claude-3.5-sonnet`
415
-
416
- #### Custom Router
417
-
418
- For more advanced routing logic, you can specify a custom router script via the `CUSTOM_ROUTER_PATH` in your `config.json`. This allows you to implement complex routing rules beyond the default scenarios.
419
-
420
- In your `config.json`:
421
-
422
- ```json
423
- {
424
- "CUSTOM_ROUTER_PATH": "/User/xxx/.claude-code-router/custom-router.js"
425
- }
426
- ```
427
-
428
- The custom router file must be a JavaScript module that exports an `async` function. This function receives the request object and the config object as arguments and should return the provider and model name as a string (e.g., `"provider_name,model_name"`), or `null` to fall back to the default router.
429
-
430
- Here is an example of a `custom-router.js` based on `custom-router.example.js`:
431
-
432
- ```javascript
433
- // /User/xxx/.claude-code-router/custom-router.js
434
-
435
- /**
436
- * A custom router function to determine which model to use based on the request.
437
- *
438
- * @param {object} req - The request object from Claude Code, containing the request body.
439
- * @param {object} config - The application's config object.
440
- * @returns {Promise<string|null>} - A promise that resolves to the "provider,model_name" string, or null to use the default router.
441
- */
442
- module.exports = async function router(req, config) {
443
- const userMessage = req.body.messages.find((m) => m.role === "user")?.content;
444
-
445
- if (userMessage && userMessage.includes("explain this code")) {
446
- // Use a powerful model for code explanation
447
- return "openrouter,anthropic/claude-3.5-sonnet";
448
- }
449
-
450
- // Fallback to the default router configuration
451
- return null;
452
- };
453
- ```
454
-
455
- ##### Subagent Routing
456
-
457
- 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.
458
-
459
- **Example:**
460
-
461
- ```
462
- <CCR-SUBAGENT-MODEL>openrouter,anthropic/claude-3.5-sonnet</CCR-SUBAGENT-MODEL>
463
- Please help me analyze this code snippet for potential optimizations...
464
- ```
465
-
466
- ## Status Line (Beta)
467
- 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.
468
- ![statusline-config.png](/blog/images/statusline-config.png)
469
-
470
- The effect is as follows:
471
- ![statusline](/blog/images/statusline.png)
472
-
473
- ## 🤖 GitHub Actions
474
-
475
- Integrate Claude Code Router into your CI/CD pipeline. After setting up [Claude Code Actions](https://docs.anthropic.com/en/docs/claude-code/github-actions), modify your `.github/workflows/claude.yaml` to use the router:
476
-
477
- ```yaml
478
- name: Claude Code
479
-
480
- on:
481
- issue_comment:
482
- types: [created]
483
- # ... other triggers
484
-
485
- jobs:
486
- claude:
487
- if: |
488
- (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
489
- # ... other conditions
490
- runs-on: ubuntu-latest
491
- permissions:
492
- contents: read
493
- pull-requests: read
494
- issues: read
495
- id-token: write
496
- steps:
497
- - name: Checkout repository
498
- uses: actions/checkout@v4
499
- with:
500
- fetch-depth: 1
501
-
502
- - name: Prepare Environment
503
- run: |
504
- curl -fsSL https://bun.sh/install | bash
505
- mkdir -p $HOME/.claude-code-router
506
- cat << 'EOF' > $HOME/.claude-code-router/config.json
507
- {
508
- "log": true,
509
- "NON_INTERACTIVE_MODE": true,
510
- "OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}",
511
- "OPENAI_BASE_URL": "https://api.deepseek.com",
512
- "OPENAI_MODEL": "deepseek-chat"
513
- }
514
- EOF
515
- shell: bash
516
-
517
- - name: Start Claude Code Router
518
- run: |
519
- nohup ~/.bun/bin/bunx @musistudio/claude-code-router@1.0.8 start &
520
- shell: bash
521
-
522
- - name: Run Claude Code
523
- id: claude
524
- uses: anthropics/claude-code-action@beta
525
- env:
526
- ANTHROPIC_BASE_URL: http://localhost:3456
527
- with:
528
- anthropic_api_key: "any-string-is-ok"
529
- ```
530
-
531
- > **Note**: When running in GitHub Actions or other automation environments, make sure to set `"NON_INTERACTIVE_MODE": true` in your configuration to prevent the process from hanging due to stdin handling issues.
532
-
533
- This setup allows for interesting automations, like running tasks during off-peak hours to reduce API costs.
534
-
535
- ## 📝 Further Reading
536
-
537
- - [Project Motivation and How It Works](blog/en/project-motivation-and-how-it-works.md)
538
- - [Maybe We Can Do More with the Router](blog/en/maybe-we-can-do-more-with-the-route.md)
539
- - [GLM-4.6 Supports Reasoning and Interleaved Thinking](blog/en/glm-4.6-supports-reasoning.md)
540
-
541
- ## ❤️ Support & Sponsoring
542
-
543
- If you find this project helpful, please consider sponsoring its development. Your support is greatly appreciated!
544
-
545
- [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/F1F31GN2GM)
546
-
547
- [Paypal](https://paypal.me/musistudio1999)
3
+ <p align="center">
4
+ <a href="README_zh.md"><img alt="Chinese README" src="https://img.shields.io/badge/%F0%9F%87%A8%F0%9F%87%B3-%E4%B8%AD%E6%96%87%E7%89%88-ff0000?style=flat" /></a>
5
+ <a href="https://discord.gg/rdftVMaUcS"><img alt="Discord" src="https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white" /></a>
6
+ <a href="https://x.com/musistudio2026"><img alt="X" src="https://img.shields.io/badge/X-@musistudio2026-000000?logo=x&logoColor=white" /></a>
7
+ <a href="https://github.com/musistudio/claude-code-router/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/musistudio/claude-code-router" /></a>
8
+ <a href="https://ccrdesk.top/"><img alt="Documentation" src="https://img.shields.io/badge/Docs-ccrdesk.top-0ea5e9?style=flat" /></a>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <img src="blog/images/claude-code-router.png" width="720" alt="Claude Code Router Desktop screenshot" />
13
+ </p>
14
+
15
+ Claude Code Router Desktop is a local gateway and desktop control panel for routing agent requests from Claude Code, Codex, ZCode, and compatible clients to the model provider you actually want to use.
16
+
17
+ ## Why Use CCR
18
+
19
+ - Use one local endpoint for multiple agent tools instead of configuring every client separately.
20
+ - Route requests with default routing, conditional rules, fallback targets, and request rewrites instead of editing client configuration by hand.
21
+ - Mix providers without changing your workflow. CCR supports OpenAI-compatible APIs, Anthropic Messages, Gemini Generate Content, OpenRouter, DeepSeek, SiliconFlow, Moonshot, Kimi Code, Mistral, Z.AI, Bailian, and custom providers.
22
+ - Control cost and reliability with fallback routing, API key rotation, usage statistics, and request logs.
23
+
24
+ ## Features
25
+
26
+ - **Overview dashboard**: inspect system status, usage widgets, account balances, model distribution, and share cards.
27
+ - **Provider management**: add provider presets or custom endpoints, probe protocol support, test model connectivity, manage credentials, and monitor supported account balances where available.
28
+ - **Routing rules**: configure default routing, conditional and model-prefix rules, fallback handling, and request rewrites.
29
+ - **Agent Config**: configure Claude Code, Codex, and ZCode launch entries, models, scopes, and multi-instance app profiles.
30
+ - **Gateway compatibility**: translate supported client requests through the local CCR model gateway.
31
+ - **Proxy mode**: capture supported API traffic through a local proxy with optional system proxy integration and network capture.
32
+ - **Fusion models**: combine a base model with vision, web search, or MCP tools into a reusable selectable model.
33
+
34
+ ## Documentation
35
+
36
+ Read the full documentation at [ccrdesk.top](https://ccrdesk.top/).
37
+
38
+ ## Download And Install
39
+
40
+ 1. Open the [GitHub Releases page](https://github.com/musistudio/claude-code-router/releases).
41
+ 2. Download the package for your platform:
42
+ - macOS Apple Silicon: `Claude-Code-Router_<version>-mac-Apple-Silicon-arm64.dmg` or `.zip`
43
+ - macOS Intel: `Claude-Code-Router_<version>-mac-Intel-x64.dmg` or `.zip`
44
+ - Windows: `Claude Code Router_<version>.exe`
45
+ - Linux: `Claude Code Router_<version>.AppImage`
46
+ 3. Install and launch **Claude Code Router**.
47
+ 4. On first launch, CCR creates its local configuration database:
48
+ - macOS/Linux: `~/.claude-code-router/config.sqlite`
49
+ - Windows: `%APPDATA%\Claude Code Router\config.sqlite`
50
+
51
+ CCR stores runtime configuration in SQLite. A legacy `config.json` is read only once for migration when no SQLite config exists.
52
+
53
+ After the service is started from the **Server** page, CCR listens on `http://localhost:8080` by default. The **Server** page controls the gateway `Host`, `Port`, proxy mode, system proxy, network capture, and CA certificate status.
54
+
55
+ ## Quick Start
56
+
57
+ CCR can be configured entirely from the desktop UI. Use this setup order for a clean first run.
58
+
59
+ ### 1. Add a provider
60
+
61
+ Open **Providers**, click **Add Provider**, then choose a built-in preset or **Other / custom API endpoint**. Fill in the provider name, base URL, protocol, API key, and model list. Run protocol probing and model connectivity checks when available, then save the provider.
62
+
63
+ ### 2. Configure routing
64
+
65
+ Open **Routing** to add conditional rules, configure request rewrites, and set fallback behavior.
66
+
67
+ Use **Add Routing Rule** for request conditions, model-prefix routing, or rule-level fallback targets.
68
+
69
+ ### 3. Start the gateway
70
+
71
+ Open **Server** and click **Start**. After the page shows Running, CCR listens on `http://localhost:8080`. Enable **Auto start** if you want CCR to start the local gateway whenever the desktop app opens.
72
+
73
+ ### 4. Connect your agent tool
74
+
75
+ Open **Agent Config** and choose the client you want to use. Configure Claude Code, Codex, or ZCode, select the target model and effect scope, then apply the config. For app entries, use the **Open Agent** action to open the target app through CCR.
76
+
77
+ ### 5. Monitor and adjust
78
+
79
+ Use **Settings → Logs & Observability** to enable request logs and agent observability. Use **Logs** to confirm `request model`, `resolved provider`, `resolved model`, status, tokens, latency, and errors; use the tray window for quick token and account status.
80
+
81
+ ## Acknowledgements
82
+
83
+ Codex support is powered by [musistudio/codexl](https://github.com/musistudio/codexl).
84
+
85
+ ## Support & Sponsoring
86
+
87
+ <div align="center">
88
+
89
+ <p>If you find this project helpful, please consider sponsoring its development. Your support is greatly appreciated.</p>
548
90
 
549
91
  <table>
550
92
  <tr>
551
- <td><img src="/blog/images/alipay.jpg" width="200" alt="Alipay" /></td>
552
- <td><img src="/blog/images/wechat.jpg" width="200" alt="WeChat Pay" /></td>
93
+ <td align="center" width="220">
94
+ <a href="https://ko-fi.com/F1F31GN2GM">
95
+ <img src="https://ko-fi.com/img/githubbutton_sm.svg" alt="Support on Ko-fi" />
96
+ </a>
97
+ <br />
98
+ <sub>One-time support via Ko-fi</sub>
99
+ </td>
100
+ <td align="center" width="220">
101
+ <a href="https://paypal.me/musistudio1999">
102
+ <img src="https://img.shields.io/badge/PayPal-Sponsor-003087?logo=paypal&logoColor=white" alt="Sponsor with PayPal" />
103
+ </a>
104
+ <br />
105
+ <sub>International sponsorship</sub>
106
+ </td>
553
107
  </tr>
554
108
  </table>
555
109
 
110
+ <table>
111
+ <tr>
112
+ <td align="center" width="220">
113
+ <strong>Alipay</strong>
114
+ <br />
115
+ <img src="/blog/images/alipay.jpg" width="160" alt="Alipay QR code" />
116
+ </td>
117
+ <td align="center" width="220">
118
+ <strong>WeChat Pay</strong>
119
+ <br />
120
+ <img src="/blog/images/wechat.jpg" width="160" alt="WeChat Pay QR code" />
121
+ </td>
122
+ </tr>
123
+ </table>
124
+
125
+ </div>
126
+
556
127
  ### Our Sponsors
557
128
 
558
- A huge thank you to all our sponsors for their generous support!
559
-
560
-
561
- - [AIHubmix](https://aihubmix.com/)
562
- - [BurnCloud](https://ai.burncloud.com)
563
- - [302.AI](https://share.302.ai/ZGVF9w)
564
- - [Z智谱](https://www.bigmodel.cn/claude-code?ic=FPF9IVAGFJ)
565
- - @Simon Leischnig
566
- - [@duanshuaimin](https://github.com/duanshuaimin)
567
- - [@vrgitadmin](https://github.com/vrgitadmin)
568
- - @\*o
569
- - [@ceilwoo](https://github.com/ceilwoo)
570
- - @\*说
571
- - @\*更
572
- - @K\*g
573
- - @R\*R
574
- - [@bobleer](https://github.com/bobleer)
575
- - @\*苗
576
- - @\*划
577
- - [@Clarence-pan](https://github.com/Clarence-pan)
578
- - [@carter003](https://github.com/carter003)
579
- - @S\*r
580
- - @\*晖
581
- - @\*敏
582
- - @Z\*z
583
- - @\*然
584
- - [@cluic](https://github.com/cluic)
585
- - @\*苗
586
- - [@PromptExpert](https://github.com/PromptExpert)
587
- - @\*应
588
- - [@yusnake](https://github.com/yusnake)
589
- - @\*飞
590
- - @董\*
591
- - @\*汀
592
- - @\*涯
593
- - @\*:-)
594
- - @\*\*磊
595
- - @\*琢
596
- - @\*成
597
- - @Z\*o
598
- - @\*琨
599
- - [@congzhangzh](https://github.com/congzhangzh)
600
- - @\*\_
601
- - @Z\*m
602
- - @*鑫
603
- - @c\*y
604
- - @\*昕
605
- - [@witsice](https://github.com/witsice)
606
- - @b\*g
607
- - @\*亿
608
- - @\*辉
609
- - @JACK
610
- - @\*光
611
- - @W\*l
612
- - [@kesku](https://github.com/kesku)
613
- - [@biguncle](https://github.com/biguncle)
614
- - @二吉吉
615
- - @a\*g
616
- - @\*林
617
- - @\*咸
618
- - @\*明
619
- - @S\*y
620
- - @f\*o
621
- - @\*智
622
- - @F\*t
623
- - @r\*c
624
- - [@qierkang](http://github.com/qierkang)
625
- - @\*军
626
- - [@snrise-z](http://github.com/snrise-z)
627
- - @\*王
628
- - [@greatheart1000](http://github.com/greatheart1000)
629
- - @\*王
630
- - @zcutlip
631
- - [@Peng-YM](http://github.com/Peng-YM)
632
- - @\*更
633
- - @\*.
634
- - @F\*t
635
- - @\*政
636
- - @\*铭
637
- - @\*叶
638
- - @七\*o
639
- - @\*青
640
- - @\*\*晨
641
- - @\*远
642
- - @\*霄
643
- - @\*\*吉
644
- - @\*\*飞
645
- - @\*\*驰
646
- - @x\*g
647
- - @\*\*东
648
- - @\*落
649
- - @哆\*k
650
- - @\*涛
651
- - [@苗大](https://github.com/WitMiao)
652
- - @\*呢
653
- - @\d*u
654
- - @crizcraig
655
- - s\*s
656
- - \*火
657
- - \*勤
658
- - \*\*锟
659
- - \*涛
660
-
661
-
662
- (If your name is masked, please contact me via my homepage email to update it with your GitHub username.)
129
+ <div align="center">
130
+
131
+ <p>A huge thank you to all our sponsors for their generous support.</p>
132
+
133
+ <table width="100%">
134
+ <tr>
135
+ <td align="center" width="330">
136
+ <a href="https://www.bigmodel.cn/claude-code?ic=FPF9IVAGFJ">
137
+ <img src="/docs/public/provider-icons/zhipu-cn-general.png" width="42" height="42" alt="Zhipu icon" />
138
+ <br />
139
+ <strong>Z智谱</strong>
140
+ </a>
141
+ </td>
142
+ <td align="center" width="330">
143
+ <a href="https://aihubmix.com/">
144
+ <img src="https://www.google.com/s2/favicons?domain=aihubmix.com&amp;sz=128" width="42" height="42" alt="AIHubmix icon" />
145
+ <br />
146
+ <strong>AIHubmix</strong>
147
+ </a>
148
+ </td>
149
+ <td align="center" width="330">
150
+ <a href="https://ai.burncloud.com">
151
+ <img src="https://www.burncloud.com/favicon.png" width="42" height="42" alt="BurnCloud icon" />
152
+ <br />
153
+ <strong>BurnCloud</strong>
154
+ </a>
155
+ </td>
156
+ <td align="center" width="330">
157
+ <a href="https://share.302.ai/ZGVF9w">
158
+ <img src="https://www.google.com/s2/favicons?domain=302.ai&amp;sz=128" width="42" height="42" alt="302.AI icon" />
159
+ <br />
160
+ <strong>302.AI</strong>
161
+ </a>
162
+ </td>
163
+ </tr>
164
+ <tr>
165
+ <td align="center" width="330">
166
+ <a href="https://runapi.co/register?aff=IX1t">
167
+ <img src="/docs/public/provider-icons/runapi.jpg" width="42" height="42" alt="RunAPI icon" />
168
+ <br />
169
+ <strong>RunAPI</strong>
170
+ </a>
171
+ </td>
172
+ <td align="center" width="330">
173
+ <a href="https://teamorouter.com/">
174
+ <img src="/docs/public/provider-icons/teamorouter.png" width="42" height="42" alt="TeamoRouter icon" />
175
+ <br />
176
+ <strong>TeamoRouter</strong>
177
+ </a>
178
+ </td>
179
+ </tr>
180
+ </table>
181
+
182
+ <h4>Community Sponsors</h4>
183
+
184
+ <table width="100%">
185
+ <tr>
186
+ <td align="center" width="220">@Simon Leischnig</td>
187
+ <td align="center" width="220"><a href="https://github.com/duanshuaimin">@duanshuaimin</a></td>
188
+ <td align="center" width="220"><a href="https://github.com/vrgitadmin">@vrgitadmin</a></td>
189
+ <td align="center" width="220">@*o</td>
190
+ <td align="center" width="220"><a href="https://github.com/ceilwoo">@ceilwoo</a></td>
191
+ <td align="center" width="220">@*说</td>
192
+ </tr>
193
+ <tr>
194
+ <td align="center" width="220">@*更</td>
195
+ <td align="center" width="220">@K*g</td>
196
+ <td align="center" width="220">@R*R</td>
197
+ <td align="center" width="220"><a href="https://github.com/bobleer">@bobleer</a></td>
198
+ <td align="center" width="220">@*苗</td>
199
+ <td align="center" width="220">@*划</td>
200
+ </tr>
201
+ <tr>
202
+ <td align="center" width="220"><a href="https://github.com/Clarence-pan">@Clarence-pan</a></td>
203
+ <td align="center" width="220"><a href="https://github.com/carter003">@carter003</a></td>
204
+ <td align="center" width="220">@S*r</td>
205
+ <td align="center" width="220">@*晖</td>
206
+ <td align="center" width="220">@*敏</td>
207
+ <td align="center" width="220">@Z*z</td>
208
+ </tr>
209
+ <tr>
210
+ <td align="center" width="220">@*然</td>
211
+ <td align="center" width="220"><a href="https://github.com/cluic">@cluic</a></td>
212
+ <td align="center" width="220">@*苗</td>
213
+ <td align="center" width="220"><a href="https://github.com/PromptExpert">@PromptExpert</a></td>
214
+ <td align="center" width="220">@*应</td>
215
+ <td align="center" width="220"><a href="https://github.com/yusnake">@yusnake</a></td>
216
+ </tr>
217
+ <tr>
218
+ <td align="center" width="220">@*飞</td>
219
+ <td align="center" width="220">@董*</td>
220
+ <td align="center" width="220">@*汀</td>
221
+ <td align="center" width="220">@*涯</td>
222
+ <td align="center" width="220">@*:-)</td>
223
+ <td align="center" width="220">@**磊</td>
224
+ </tr>
225
+ <tr>
226
+ <td align="center" width="220">@*琢</td>
227
+ <td align="center" width="220">@*成</td>
228
+ <td align="center" width="220">@Z*o</td>
229
+ <td align="center" width="220">@*琨</td>
230
+ <td align="center" width="220"><a href="https://github.com/congzhangzh">@congzhangzh</a></td>
231
+ <td align="center" width="220">@*_</td>
232
+ </tr>
233
+ <tr>
234
+ <td align="center" width="220">@Z*m</td>
235
+ <td align="center" width="220">@*鑫</td>
236
+ <td align="center" width="220">@c*y</td>
237
+ <td align="center" width="220">@*昕</td>
238
+ <td align="center" width="220"><a href="https://github.com/witsice">@witsice</a></td>
239
+ <td align="center" width="220">@b*g</td>
240
+ </tr>
241
+ <tr>
242
+ <td align="center" width="220">@*亿</td>
243
+ <td align="center" width="220">@*辉</td>
244
+ <td align="center" width="220">@JACK</td>
245
+ <td align="center" width="220">@*光</td>
246
+ <td align="center" width="220">@W*l</td>
247
+ <td align="center" width="220"><a href="https://github.com/kesku">@kesku</a></td>
248
+ </tr>
249
+ <tr>
250
+ <td align="center" width="220"><a href="https://github.com/biguncle">@biguncle</a></td>
251
+ <td align="center" width="220">@二吉吉</td>
252
+ <td align="center" width="220">@a*g</td>
253
+ <td align="center" width="220">@*林</td>
254
+ <td align="center" width="220">@*咸</td>
255
+ <td align="center" width="220">@*明</td>
256
+ </tr>
257
+ <tr>
258
+ <td align="center" width="220">@S*y</td>
259
+ <td align="center" width="220">@f*o</td>
260
+ <td align="center" width="220">@*智</td>
261
+ <td align="center" width="220">@F*t</td>
262
+ <td align="center" width="220">@r*c</td>
263
+ <td align="center" width="220"><a href="https://github.com/qierkang">@qierkang</a></td>
264
+ </tr>
265
+ <tr>
266
+ <td align="center" width="220">@*军</td>
267
+ <td align="center" width="220"><a href="https://github.com/snrise-z">@snrise-z</a></td>
268
+ <td align="center" width="220">@*王</td>
269
+ <td align="center" width="220"><a href="https://github.com/greatheart1000">@greatheart1000</a></td>
270
+ <td align="center" width="220">@*王</td>
271
+ <td align="center" width="220">@zcutlip</td>
272
+ </tr>
273
+ <tr>
274
+ <td align="center" width="220"><a href="https://github.com/Peng-YM">@Peng-YM</a></td>
275
+ <td align="center" width="220">@*更</td>
276
+ <td align="center" width="220">@*.</td>
277
+ <td align="center" width="220">@F*t</td>
278
+ <td align="center" width="220">@*政</td>
279
+ <td align="center" width="220">@*铭</td>
280
+ </tr>
281
+ <tr>
282
+ <td align="center" width="220">@*叶</td>
283
+ <td align="center" width="220">@七*o</td>
284
+ <td align="center" width="220">@*青</td>
285
+ <td align="center" width="220">@**晨</td>
286
+ <td align="center" width="220">@*远</td>
287
+ <td align="center" width="220">@*霄</td>
288
+ </tr>
289
+ <tr>
290
+ <td align="center" width="220">@**吉</td>
291
+ <td align="center" width="220">@**飞</td>
292
+ <td align="center" width="220">@**驰</td>
293
+ <td align="center" width="220">@x*g</td>
294
+ <td align="center" width="220">@**东</td>
295
+ <td align="center" width="220">@*落</td>
296
+ </tr>
297
+ <tr>
298
+ <td align="center" width="220">@哆*k</td>
299
+ <td align="center" width="220">@*涛</td>
300
+ <td align="center" width="220"><a href="https://github.com/WitMiao">@苗大</a></td>
301
+ <td align="center" width="220">@*呢</td>
302
+ <td align="center" width="220">@d*u</td>
303
+ <td align="center" width="220">@crizcraig</td>
304
+ </tr>
305
+ <tr>
306
+ <td align="center" width="220">s*s</td>
307
+ <td align="center" width="220">*火</td>
308
+ <td align="center" width="220">*勤</td>
309
+ <td align="center" width="220">**锟</td>
310
+ <td align="center" width="220">*涛</td>
311
+ <td align="center" width="220">**明</td>
312
+ </tr>
313
+ <tr>
314
+ <td align="center" width="220">*知</td>
315
+ <td align="center" width="220">*语</td>
316
+ <td align="center" width="220">*瓜</td>
317
+ <td align="center" width="220"></td>
318
+ <td align="center" width="220"></td>
319
+ <td align="center" width="220"></td>
320
+ </tr>
321
+ </table>
322
+
323
+ <sub>If your name is masked, please contact me via my homepage email to update it with your GitHub username.</sub>
324
+
325
+ </div>
326
+
327
+ ## License
328
+
329
+ This project is licensed under the [MIT License](LICENSE).