From c6969fdd90fe1b7f1c2cc83aecd1f719ed801b1d Mon Sep 17 00:00:00 2001 From: "jinhui.li" Date: Wed, 23 Jul 2025 12:20:52 +0800 Subject: [PATCH] release v1.0.26 --- CLAUDE.md | 45 ++++++++++++++++++++++++++++++++++++++------- README.md | 33 +++++++++++++++++++++++++++++++++ README_zh.md | 32 ++++++++++++++++++++++++++++++++ config.example.json | 32 ++++++++++++++++++++++++++++++++ package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- 6 files changed, 142 insertions(+), 14 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 50bfac0..e39b627 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1,12 +1,43 @@ # CLAUDE.md -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.You need use English to write text. +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. -## Key Development Commands -- Build: `npm run build` -- Start: `npm start` +## Commands + +- **Build the project**: + ```bash + npm run build + ``` +- **Start the router server**: + ```bash + ccr start + ``` +- **Stop the router server**: + ```bash + ccr stop + ``` +- **Check the server status**: + ```bash + ccr status + ``` +- **Run Claude Code through the router**: + ```bash + ccr code "" + ``` +- **Release a new version**: + ```bash + npm run release + ``` ## Architecture -- Uses `express` for routing (see `src/server.ts`) -- Bundles with `esbuild` for CLI distribution -- Plugins are loaded from `$HOME/.claude-code-router/plugins` \ No newline at end of file + +This project is a TypeScript-based router for Claude Code requests. It allows routing requests to different large language models (LLMs) from various providers based on custom rules. + +- **Entry Point**: The main command-line interface logic is in `src/cli.ts`. It handles parsing commands like `start`, `stop`, and `code`. +- **Server**: The `ccr start` command launches a server that listens for requests from Claude Code. The server logic is initiated from `src/index.ts`. +- **Configuration**: The router is configured via a JSON file located at `~/.claude-code-router/config.json`. This file defines API providers, routing rules, and custom transformers. An example can be found in `config.example.json`. +- **Routing**: The core routing logic determines which LLM provider and model to use for a given request. It supports default routes for different scenarios (`default`, `background`, `think`, `longContext`, `webSearch`) and can be extended with a custom JavaScript router file. The router logic is likely in `src/utils/router.ts`. +- **Providers and Transformers**: The application supports multiple LLM providers. Transformers adapt the request and response formats for different provider APIs. +- **Claude Code Integration**: When a user runs `ccr code`, the command is forwarded to the running router service. The service then processes the request, applies routing rules, and sends it to the configured LLM. If the service isn't running, `ccr code` will attempt to start it automatically. +- **Dependencies**: The project is built with `esbuild`. It has a key local dependency `@musistudio/llms`, which probably contains the core logic for interacting with different LLM APIs. +- `@musistudio/llms` is implemented based on `fastify` and exposes `fastify`'s hook and middleware interfaces, allowing direct use of `server.addHook`. \ No newline at end of file diff --git a/README.md b/README.md index d508e77..a45631c 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,38 @@ Here is a comprehensive example: "transformer": { "use": ["deepseek"] } + }, + { + "name": "modelscope", + "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions", + "api_key": "", + "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } + }, + { + "name": "dashscope", + "api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", + "api_key": "", + "models": ["qwen3-coder-plus"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } } ], "Router": { @@ -380,5 +412,6 @@ A huge thank you to all our sponsors for their generous support! - @*琢 - @*成 - @Z*o +- @*琨 (If your name is masked, please contact me via my homepage email to update it with your GitHub username.) diff --git a/README_zh.md b/README_zh.md index 3c152e4..9b92851 100644 --- a/README_zh.md +++ b/README_zh.md @@ -98,6 +98,38 @@ npm install -g @musistudio/claude-code-router "transformer": { "use": ["deepseek"] } + }, + { + "name": "modelscope", + "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions", + "api_key": "", + "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } + }, + { + "name": "dashscope", + "api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", + "api_key": "", + "models": ["qwen3-coder-plus"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } } ], "Router": { diff --git a/config.example.json b/config.example.json index c5ad568..1e853c6 100644 --- a/config.example.json +++ b/config.example.json @@ -65,6 +65,38 @@ ] ] } + }, + { + "name": "modelscope", + "api_base_url": "https://api-inference.modelscope.cn/v1/chat/completions", + "api_key": "", + "models": ["Qwen/Qwen3-Coder-480B-A35B-Instruct"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } + }, + { + "name": "dashscope", + "api_base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", + "api_key": "", + "models": ["qwen3-coder-plus"], + "transformer": { + "use": [ + [ + "maxtoken", + { + "max_tokens": 8192 + } + ] + ] + } } ], "Router": { diff --git a/package.json b/package.json index 722c29a..0f64b6e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@musistudio/claude-code-router", - "version": "1.0.25", + "version": "1.0.26", "description": "Use Claude Code without an Anthropics account and route it to another LLM provider", "bin": { "ccr": "./dist/cli.js" @@ -19,7 +19,7 @@ "author": "musistudio", "license": "MIT", "dependencies": { - "@musistudio/llms": "^1.0.11", + "@musistudio/llms": "^1.0.12", "dotenv": "^16.4.7", "tiktoken": "^1.0.21", "uuid": "^11.1.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7a06ab8..476be12 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@musistudio/llms': - specifier: ^1.0.11 - version: 1.0.11(ws@8.18.3)(zod@3.25.67) + specifier: ^1.0.12 + version: 1.0.12(ws@8.18.3)(zod@3.25.67) dotenv: specifier: ^16.4.7 version: 16.6.1 @@ -223,8 +223,8 @@ packages: '@modelcontextprotocol/sdk': optional: true - '@musistudio/llms@1.0.11': - resolution: {integrity: sha512-qydLNzZDeURK8fsYJFspM04x/4mlqmKAN2Ie7MLvWuYjYT+fOtDm5BaEzQKhNLOqA5pcB2bCU0L0VFRnoeOpBg==} + '@musistudio/llms@1.0.12': + resolution: {integrity: sha512-5sRIrt8UgXDLqim1xZrnMxugUW2m6zopXMQ+wF5Px20hH06aLO0zdT3Gyq78IKJZ+Xupkj+h1FooCAtWl+6bLw==} '@nodelib/fs.scandir@2.1.5': resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==} @@ -824,7 +824,7 @@ snapshots: - supports-color - utf-8-validate - '@musistudio/llms@1.0.11(ws@8.18.3)(zod@3.25.67)': + '@musistudio/llms@1.0.12(ws@8.18.3)(zod@3.25.67)': dependencies: '@anthropic-ai/sdk': 0.54.0 '@fastify/cors': 11.0.1