Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
```bash
ccr code "<your prompt>"
```
- **Open the web UI**:
```bash
ccr ui
```
- **Restart the router server**:
```bash
ccr restart
```
- **Release a new version**:
```bash
npm run release
Expand All @@ -33,12 +41,17 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

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`.
- **Entry Point**: The main command-line interface logic is in `src/cli.ts`. It handles parsing commands like `start`, `stop`, `code`, and `ui`.
- **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`.
- **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 `ui/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 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.
- **Dependencies**: The project is built with `esbuild`. It has a key local dependency `@musistudio/llms`, which 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`.
- 无论如何你都不能自动提交git
- **Web UI**: The project includes a web-based configuration UI built with React, TypeScript, and Tailwind CSS. The UI is served from the `/ui` endpoint.
- **Authentication**: The server supports API key authentication via the `APIKEY` configuration option.
- **Logging**: The application uses `pino` for logging with file rotation. Logs are stored in `~/.claude-code-router/logs/`.
- **Process Management**: The server manages its own process lifecycle with PID file tracking in `~/.claude-code-router/.claude-code-router.pid`.

无论如何你都不能自动提交git
63 changes: 62 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
![](blog/images/claude-code.png)

## ✨ 功能

ui
- **模型路由**: 根据您的需求将请求路由到不同的模型(例如,后台任务、思考、长上下文)。
- **多提供商支持**: 支持 OpenRouter、DeepSeek、Ollama、Gemini、Volcengine 和 SiliconFlow 等各种模型提供商。
- **请求/响应转换**: 使用转换器为不同的提供商自定义请求和响应。
Expand All @@ -21,6 +21,67 @@

## 🚀 快速入门

### 从源代码本地构建和运行

如果您想从源代码进行开发或测试,可以按照以下步骤操作:

1. **克隆仓库**:
```bash
git clone https://github.com/musistudio/claude-code-router.git
cd claude-code-router
```
2. **安装依赖**:
```bash
npm install
```
3. **构建项目**:
```bash
npm run build
```
4. **运行开发版本**:
```bash
# 启动服务
node dist/cli.js start
# 运行 Claude Code 命令
node dist/cli.js code "你的提示"
# 运行 UI
node dist/cli.js ui
# 测试提供商连接
node dist/cli.js test # 测试所有提供商
node dist/cli.js test <provider_name> # 测试特定提供商
```

**注意**:在开发过程中,修改代码后需要重新 `npm run build`,然后使用 `ccr restart` 重启服务以应用更改。

### 使用 npm link 进行本地调试

当你从源码开发并希望在全局以 `ccr` 命令直接调用当前工作副本时,可使用 `npm link`:

```bash
# 在项目根目录执行,创建全局链接
npm link

# 验证已链接的全局命令
ccr --version

# 启动/重启/UI(使用当前源码构建的版本)
ccr start
ccr restart
ccr ui
```

取消链接并恢复到发布版:

```bash
# 取消全局链接
npm unlink -g @musistudio/claude-code-router

# 安装 NPM 发布版本
npm i -g @musistudio/claude-code-router
```

提示:若遇到权限问题,请在有管理员/sudo 权限的终端执行;源码更新后需 `npm run build` 再使用。

### 1. 安装

首先,请确保您已安装 [Claude Code](https://docs.anthropic.com/en/docs/claude-code/quickstart):
Expand Down
Binary file modified blog/images/ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading