runcc 0.1.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.
- package/CLAUDE.md +149 -0
- package/PLAN.md +236 -0
- package/README.md +188 -0
- package/bun.lock +25 -0
- package/dist/index.js +2505 -0
- package/package.json +48 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## 项目概述
|
|
6
|
+
|
|
7
|
+
**cc-run** 是一个 Claude CLI 启动器,使用 TypeScript + Bun 开发。核心功能是在官方 API 和多个第三方 API endpoints 之间快速切换。这是一个单文件可执行 CLI 工具,可作为全局命令安装。
|
|
8
|
+
|
|
9
|
+
## 开发命令
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 安装依赖
|
|
13
|
+
bun install
|
|
14
|
+
|
|
15
|
+
# 开发模式(直接运行 TypeScript 源码)
|
|
16
|
+
bun run dev
|
|
17
|
+
|
|
18
|
+
# 构建输出到 dist/index.js
|
|
19
|
+
bun run build
|
|
20
|
+
|
|
21
|
+
# 构建独立二进制可执行文件
|
|
22
|
+
bun run build:bin
|
|
23
|
+
|
|
24
|
+
# 全局安装(本地测试)
|
|
25
|
+
bun install -g .
|
|
26
|
+
|
|
27
|
+
# 配置验证测试工具
|
|
28
|
+
bun test/dry-run.ts config
|
|
29
|
+
bun test/dry-run.ts glm
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**注意**: 项目无自动化测试框架、无 linting 配置、无 pre-commit hooks。
|
|
33
|
+
|
|
34
|
+
## 核心架构
|
|
35
|
+
|
|
36
|
+
项目采用三层架构设计:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
┌─────────────────────────────────────────┐
|
|
40
|
+
│ CLI Layer (commands) │
|
|
41
|
+
│ - 参数解析、用户交互、命令编排 │
|
|
42
|
+
├─────────────────────────────────────────┤
|
|
43
|
+
│ Business Logic (utils) │
|
|
44
|
+
│ - 启动器、环境变量、Claude 配置管理 │
|
|
45
|
+
├─────────────────────────────────────────┤
|
|
46
|
+
│ Data Layer (config) │
|
|
47
|
+
│ - 配置存储、类型定义、endpoints 管理 │
|
|
48
|
+
└─────────────────────────────────────────┘
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 目录结构
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
src/
|
|
55
|
+
├── index.ts # CLI 入口,Commander 配置,命令路由
|
|
56
|
+
├── commands/ # 命令实现层
|
|
57
|
+
│ ├── run.ts # 核心启动逻辑(官方/provider/配置模式)
|
|
58
|
+
│ ├── proxy.ts # 代理管理命令
|
|
59
|
+
│ ├── list.ts # 列出 endpoints(UTF-8 处理)
|
|
60
|
+
│ ├── add.ts # 添加自定义 endpoint
|
|
61
|
+
│ └── remove.ts # 删除 endpoint
|
|
62
|
+
├── config/ # 配置数据层
|
|
63
|
+
│ ├── types.ts # TypeScript 类型定义
|
|
64
|
+
│ ├── endpoints.ts # 内置 endpoints (glm/deepseek/minimax)
|
|
65
|
+
│ └── storage.ts # ~/.cc-run/config.json 读写
|
|
66
|
+
└── utils/ # 工具层
|
|
67
|
+
├── launcher.ts # spawn Claude 进程
|
|
68
|
+
├── env.ts # 环境变量构建
|
|
69
|
+
└── claude-settings.ts # ~/.claude/settings.json 读写
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 双配置文件系统
|
|
73
|
+
|
|
74
|
+
### ~/.cc-run/config.json (启动器私有配置)
|
|
75
|
+
|
|
76
|
+
存储自定义 endpoints、API tokens、最后使用的 endpoint、代理配置。
|
|
77
|
+
|
|
78
|
+
### ~/.claude/settings.json (Claude 官方配置)
|
|
79
|
+
|
|
80
|
+
存储 `proxy`、`apiUrl`、`anthropicApiKey`,由 Claude CLI 原生读取。
|
|
81
|
+
|
|
82
|
+
**关键机制**: 使用 `--claude` 标志可以将第三方 endpoint 配置写入 `~/.claude/settings.json`,使原生 `claude` 命令默认使用该 endpoint。
|
|
83
|
+
|
|
84
|
+
## 三种启动模式
|
|
85
|
+
|
|
86
|
+
### 1. 官方模式 (`cc-run`)
|
|
87
|
+
1. 备份当前 Claude 配置
|
|
88
|
+
2. 清除第三方 endpoint 配置
|
|
89
|
+
3. 根据 `clearForOfficial` 决定是否清除 proxy
|
|
90
|
+
4. 启动 Claude(不设置第三方环境变量)
|
|
91
|
+
5. 退出后恢复配置
|
|
92
|
+
|
|
93
|
+
### 2. Provider 模式 (`cc-run glm`)
|
|
94
|
+
1. 从内置或自定义 endpoints 查找配置
|
|
95
|
+
2. 获取 token(首次提示输入并保存)
|
|
96
|
+
3. 通过环境变量启动 Claude:
|
|
97
|
+
- `ANTHROPIC_BASE_URL`
|
|
98
|
+
- `ANTHROPIC_AUTH_TOKEN`
|
|
99
|
+
- `http_proxy`/`https_proxy`
|
|
100
|
+
|
|
101
|
+
### 3. 配置模式 (`cc-run glm --claude`)
|
|
102
|
+
1. 执行 provider 模式启动
|
|
103
|
+
2. 额外写入 `~/.claude/settings.json`
|
|
104
|
+
3. 使原生 `claude` 命令默认使用此 endpoint
|
|
105
|
+
|
|
106
|
+
## 内置 Endpoints
|
|
107
|
+
|
|
108
|
+
| 名称 | Endpoint URL |
|
|
109
|
+
|------|--------------|
|
|
110
|
+
| glm | https://open.bigmodel.cn/api/paas/v4/ |
|
|
111
|
+
| deepseek | https://api.deepseek.com |
|
|
112
|
+
| minimax | https://api.minimax.chat/v1 |
|
|
113
|
+
|
|
114
|
+
**扩展点**: 添加内置 endpoint 需修改 `src/config/endpoints.ts`
|
|
115
|
+
|
|
116
|
+
## 代码风格约定
|
|
117
|
+
|
|
118
|
+
- **模块系统**: ES Modules(import 必须显式包含 `.js` 扩展名)
|
|
119
|
+
- **类型系统**: 严格模式 TypeScript
|
|
120
|
+
- **注释风格**: JSDoc 风格(中文)
|
|
121
|
+
- **错误处理**: 使用 `process.exit(1)` 终止,无异常抛出
|
|
122
|
+
- **文件组织**: 按功能分层,单一职责原则
|
|
123
|
+
- **命名约定**:
|
|
124
|
+
- 文件名: kebab-case (`claude-settings.ts`)
|
|
125
|
+
- 函数: camelCase
|
|
126
|
+
- 类型: PascalCase
|
|
127
|
+
- 常量: UPPER_SNAKE_CASE
|
|
128
|
+
|
|
129
|
+
## 关键技术实现
|
|
130
|
+
|
|
131
|
+
### 环境变量隔离
|
|
132
|
+
使用 `spawn` 的 `env` 选项实现环境变量隔离,避免污染全局环境。
|
|
133
|
+
|
|
134
|
+
### 配置原子操作
|
|
135
|
+
- 官方模式使用备份-修改-恢复模式确保配置安全
|
|
136
|
+
- 文件操作使用同步 API (`readFileSync`, `writeFileSync`)
|
|
137
|
+
- 目录不存在时自动创建 (`mkdirSync` with `recursive: true`)
|
|
138
|
+
|
|
139
|
+
### UTF-8 输出处理
|
|
140
|
+
`list.ts` 使用 `TextEncoder` 确保中文正确显示(标准 console.log 在某些环境下可能乱码)
|
|
141
|
+
|
|
142
|
+
### 交互式输入
|
|
143
|
+
使用 Node.js 原生 `readline` 模块实现 token 和代理地址输入
|
|
144
|
+
|
|
145
|
+
## 依赖外部条件
|
|
146
|
+
|
|
147
|
+
1. **Claude CLI**: 系统必须已安装 `claude` 命令
|
|
148
|
+
2. **配置目录**: 自动创建 `~/.cc-run/` 和 `~/.claude/`
|
|
149
|
+
3. **Node 版本**: >= 18.0.0
|
package/PLAN.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# CC 启动器实现计划
|
|
2
|
+
|
|
3
|
+
## 项目概述
|
|
4
|
+
|
|
5
|
+
使用 TypeScript + bun 创建 CC 启动器,支持切换不同的 API endpoint。
|
|
6
|
+
|
|
7
|
+
## 命令格式
|
|
8
|
+
|
|
9
|
+
| 命令 | 功能 |
|
|
10
|
+
|------|------|
|
|
11
|
+
| `cc-run` | **总是**启动官方 claude(根据配置决定是否临时清除 proxy 和第三方 endpoint) |
|
|
12
|
+
| `cc-run --claude` | 恢复原生 `claude` 命令使用官方 endpoint(删除 ~/.claude/settings.json 中的第三方配置) |
|
|
13
|
+
| `cc-run glm` | 使用 glm endpoint |
|
|
14
|
+
| `cc-run glm --claude` | 使用 glm,并配置原生 `claude` 命令默认使用 glm |
|
|
15
|
+
| `cc-run deepseek` | 使用 deepseek endpoint |
|
|
16
|
+
| `cc-run deepseek --claude` | 使用 deepseek,并配置原生 `claude` 命令默认使用 deepseek |
|
|
17
|
+
| `cc-run minimax` | 使用 minimax endpoint |
|
|
18
|
+
| `cc-run add <name> <endpoint> <token>` | 添加自定义 endpoint |
|
|
19
|
+
| `cc-run list` | 列出所有 endpoint |
|
|
20
|
+
| `cc-run remove <name>` | 删除自定义 endpoint |
|
|
21
|
+
| `cc-run proxy on` | 开启代理(修改 ~/.claude/settings.json) |
|
|
22
|
+
| `cc-run proxy off` | 关闭代理(修改 ~/.claude/settings.json) |
|
|
23
|
+
| `cc-run proxy reset` | 重置代理配置 |
|
|
24
|
+
| `cc-run proxy status` | 查看代理状态 |
|
|
25
|
+
| `cc-run proxy help` | 代理帮助信息 |
|
|
26
|
+
|
|
27
|
+
## 项目结构
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
cc-run/
|
|
31
|
+
├── package.json
|
|
32
|
+
├── tsconfig.json
|
|
33
|
+
├── src/
|
|
34
|
+
│ ├── index.ts # CLI 入口
|
|
35
|
+
│ ├── commands/
|
|
36
|
+
│ │ ├── run.ts # 启动命令
|
|
37
|
+
│ │ ├── add.ts # 添加 endpoint
|
|
38
|
+
│ │ ├── list.ts # 列出 endpoint
|
|
39
|
+
│ │ ├── remove.ts # 删除 endpoint
|
|
40
|
+
│ │ └── proxy.ts # 代理管理命令
|
|
41
|
+
│ ├── config/
|
|
42
|
+
│ │ ├── storage.ts # 配置存储管理
|
|
43
|
+
│ │ ├── endpoints.ts # 内置 endpoint 定义
|
|
44
|
+
│ │ └── types.ts # 类型定义
|
|
45
|
+
│ └── utils/
|
|
46
|
+
│ ├── env.ts # 环境变量设置
|
|
47
|
+
│ └── launcher.ts # 启动 claude
|
|
48
|
+
└── README.md
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 内置 Endpoints
|
|
52
|
+
|
|
53
|
+
| 名称 | Endpoint |
|
|
54
|
+
|------|----------|
|
|
55
|
+
| glm | https://open.bigmodel.cn/api/paas/v4/ |
|
|
56
|
+
| deepseek | https://api.deepseek.com |
|
|
57
|
+
| minimax | https://api.minimax.chat/v1 |
|
|
58
|
+
|
|
59
|
+
## 配置存储
|
|
60
|
+
|
|
61
|
+
### ~/.cc-run/config.json(启动器配置)
|
|
62
|
+
`proxy.on/off` 会修改此文件的 proxy 配置,`cc-run <provider>` 会保存 token:
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"endpoints": [
|
|
66
|
+
{
|
|
67
|
+
"name": "my-custom",
|
|
68
|
+
"endpoint": "https://api.example.com/v1",
|
|
69
|
+
"token": "sk-xxxxxxxx"
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"tokens": {
|
|
73
|
+
"glm": "sk-xxxxxxxx",
|
|
74
|
+
"deepseek": "sk-yyyyyyyy",
|
|
75
|
+
"minimax": "sk-zzzzzzzz"
|
|
76
|
+
},
|
|
77
|
+
"lastUsed": "glm",
|
|
78
|
+
"proxy": {
|
|
79
|
+
"enabled": true,
|
|
80
|
+
"url": "http://agent.baidu.com:8891",
|
|
81
|
+
"clearForOfficial": false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### ~/.claude/settings.json(Claude 官方配置)
|
|
87
|
+
`proxy on/off` 会修改此文件的 proxy 配置:
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"proxy": "http://agent.baidu.com:8891"
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Proxy 处理逻辑
|
|
95
|
+
|
|
96
|
+
### cc-run proxy on
|
|
97
|
+
1. 提示输入代理地址(首次)
|
|
98
|
+
2. 保存到 `~/.cc-run/config.json`
|
|
99
|
+
3. 修改 `~/.claude/settings.json`,添加 proxy 配置
|
|
100
|
+
|
|
101
|
+
### cc-run proxy off
|
|
102
|
+
1. 更新 `~/.cc-run/config.json`(enabled: false)
|
|
103
|
+
2. 修改 `~/.claude/settings.json`,删除 proxy 配置
|
|
104
|
+
|
|
105
|
+
## 运行逻辑
|
|
106
|
+
|
|
107
|
+
### cc-run(无参数)
|
|
108
|
+
|
|
109
|
+
总是启动官方 claude。启动前会检查并清理 `~/.claude/settings.json`:
|
|
110
|
+
|
|
111
|
+
1. 读取当前的 `~/.claude/settings.json`
|
|
112
|
+
2. 检查是否有 `proxy` 配置
|
|
113
|
+
3. 检查是否有 `apiUrl` / `anthropicApiKey` 等第三方 endpoint 配置
|
|
114
|
+
4. 根据清理策略清理:
|
|
115
|
+
- **proxy 清理**:由 `~/.cc-run/config.json` 中 `proxy.clearForOfficial` 决定
|
|
116
|
+
- **endpoint 清理**:总是清除第三方 endpoint 配置
|
|
117
|
+
5. 启动 claude
|
|
118
|
+
6. claude 退出后恢复被清除的配置
|
|
119
|
+
|
|
120
|
+
**proxy 清理策略**(`~/.cc-run/config.json`):
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"proxy": {
|
|
124
|
+
"clearForOfficial": true // 启动官方 claude 时是否清除 proxy
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### cc-run <provider>
|
|
130
|
+
|
|
131
|
+
使用指定 endpoint,通过环境变量启动。
|
|
132
|
+
|
|
133
|
+
**Token 获取逻辑**:
|
|
134
|
+
1. 检查 `~/.cc-run/config.json` 中是否已保存该 provider 的 token
|
|
135
|
+
2. 如果没有,提示用户输入:
|
|
136
|
+
```
|
|
137
|
+
请输入 glm 的 API Token: [输入框]
|
|
138
|
+
```
|
|
139
|
+
3. 保存 token 到 `~/.cc-run/config.json`:
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"tokens": {
|
|
143
|
+
"glm": "sk-xxxxxxxx",
|
|
144
|
+
"deepseek": "sk-yyyyyyyy",
|
|
145
|
+
"minimax": "sk-zzzzzzzz"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
4. 使用保存的 token 启动
|
|
150
|
+
|
|
151
|
+
### cc-run <provider> --claude
|
|
152
|
+
使用指定 endpoint,并**配置原生 `claude` 命令**的默认行为:
|
|
153
|
+
1. 使用指定 endpoint 启动 cc-run
|
|
154
|
+
2. 修改 `~/.claude/settings.json`,设置:
|
|
155
|
+
- `apiUrl`: 指定 provider 的 endpoint
|
|
156
|
+
- `anthropicApiKey`: 指定 provider 的 token
|
|
157
|
+
3. 之后直接运行原生 `claude` 命令时,会使用这个第三方 endpoint
|
|
158
|
+
4. **不影响** `cc-run` 无参数的行为(`cc-run` 仍然总是启动官方 claude)
|
|
159
|
+
|
|
160
|
+
### cc-run --claude(无 provider)
|
|
161
|
+
**恢复原生 `claude` 命令使用官方 endpoint**:
|
|
162
|
+
1. 删除 `~/.claude/settings.json` 中的 `apiUrl` 和 `anthropicApiKey`
|
|
163
|
+
2. 之后直接运行原生 `claude` 命令时,会使用官方 endpoint
|
|
164
|
+
3. 不启动 cc-run
|
|
165
|
+
|
|
166
|
+
> **注**:`--claude` 只影响原生 `claude` 命令,不影响 `cc-run`
|
|
167
|
+
|
|
168
|
+
## 环境变量
|
|
169
|
+
|
|
170
|
+
启动 CC 时设置:
|
|
171
|
+
- `ANTHROPIC_BASE_URL` - API endpoint
|
|
172
|
+
- `ANTHROPIC_AUTH_TOKEN` - API token
|
|
173
|
+
- `http_proxy` / `https_proxy` - 代理(如果配置)
|
|
174
|
+
|
|
175
|
+
## 关键文件
|
|
176
|
+
|
|
177
|
+
| 文件 | 说明 |
|
|
178
|
+
|------|------|
|
|
179
|
+
| `src/index.ts` | CLI 入口,使用 commander 解析参数 |
|
|
180
|
+
| `src/config/storage.ts` | 配置文件读写、token 管理、endpoint 管理 |
|
|
181
|
+
| `src/utils/token.ts` | Token 获取和保存逻辑(首次使用时提示输入) |
|
|
182
|
+
| `src/commands/run.ts` | 核心启动逻辑,处理官方模式的 proxy 临时清除 |
|
|
183
|
+
| `src/commands/proxy.ts` | 代理管理命令(on/off/reset/status/help) |
|
|
184
|
+
| `src/utils/launcher.ts` | spawn claude 进程 |
|
|
185
|
+
| `src/utils/claude-settings.ts` | 读写 `~/.claude/settings.json` 的 proxy 和 endpoint 配置 |
|
|
186
|
+
| `src/config/types.ts` | TypeScript 类型定义 |
|
|
187
|
+
|
|
188
|
+
## 代理命令实现要点
|
|
189
|
+
|
|
190
|
+
| 命令 | 说明 |
|
|
191
|
+
|------|------|
|
|
192
|
+
| `cc-run proxy on` | 首次运行时提示输入代理地址,保存并修改 `~/.claude/settings.json` |
|
|
193
|
+
| `cc-run proxy off` | 关闭代理,删除 `~/.claude/settings.json` 中的 proxy 配置 |
|
|
194
|
+
| `cc-run proxy reset` | 重置代理配置 |
|
|
195
|
+
| `cc-run proxy status` | 显示代理状态(是否启用、地址) |
|
|
196
|
+
| `cc-run proxy help` | 显示代理相关帮助 |
|
|
197
|
+
|
|
198
|
+
## 依赖
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"dependencies": {
|
|
203
|
+
"commander": "^12.0.0"
|
|
204
|
+
},
|
|
205
|
+
"devDependencies": {
|
|
206
|
+
"@types/node": "^20.0.0",
|
|
207
|
+
"bun-types": "latest"
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 验证方式
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# 1. 构建
|
|
216
|
+
bun run build
|
|
217
|
+
|
|
218
|
+
# 2. 测试 list
|
|
219
|
+
bun run src/index.ts list
|
|
220
|
+
|
|
221
|
+
# 3. 测试 add
|
|
222
|
+
bun run src/index.ts add test https://api.test.com sk-test
|
|
223
|
+
|
|
224
|
+
# 4. 测试 proxy
|
|
225
|
+
bun run src/index.ts proxy status
|
|
226
|
+
bun run src/index.ts proxy on
|
|
227
|
+
bun run src/index.ts proxy off
|
|
228
|
+
|
|
229
|
+
# 5. 测试 run(需要已有 token)
|
|
230
|
+
bun run src/index.ts glm
|
|
231
|
+
|
|
232
|
+
# 6. 全局安装后测试
|
|
233
|
+
bun install -g
|
|
234
|
+
cc-run list
|
|
235
|
+
cc-run proxy status
|
|
236
|
+
```
|
package/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# cc-run
|
|
2
|
+
|
|
3
|
+
Claude CLI 启动器,支持切换不同的 API endpoint。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 🔄 快速切换官方/第三方 API endpoint
|
|
8
|
+
- 🔐 保存和管理多个 API Token
|
|
9
|
+
- 🌐 代理配置管理
|
|
10
|
+
- ⚙️ 配置原生 `claude` 命令使用第三方 endpoint
|
|
11
|
+
- 📝 自定义 endpoint 支持
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# 全局安装
|
|
17
|
+
bun install -g .
|
|
18
|
+
|
|
19
|
+
# 或使用 npm
|
|
20
|
+
npm install -g .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 快速开始
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 查看所有可用的 endpoints
|
|
27
|
+
cc-run list
|
|
28
|
+
|
|
29
|
+
# 使用第三方 endpoint
|
|
30
|
+
cc-run glm
|
|
31
|
+
|
|
32
|
+
# 配置原生 claude 命令使用 glm
|
|
33
|
+
cc-run glm --claude
|
|
34
|
+
|
|
35
|
+
# 恢复原生 claude 使用官方 endpoint
|
|
36
|
+
cc-run --claude
|
|
37
|
+
|
|
38
|
+
# 启动官方 claude
|
|
39
|
+
cc-run
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 命令说明
|
|
43
|
+
|
|
44
|
+
### Endpoint 管理
|
|
45
|
+
|
|
46
|
+
| 命令 | 说明 |
|
|
47
|
+
|------|------|
|
|
48
|
+
| `cc-run` | 启动官方 claude |
|
|
49
|
+
| `cc-run glm` | 使用 glm endpoint |
|
|
50
|
+
| `cc-run deepseek` | 使用 deepseek endpoint |
|
|
51
|
+
| `cc-run minimax` | 使用 minimax endpoint |
|
|
52
|
+
| `cc-run list` | 列出所有 endpoints |
|
|
53
|
+
| `cc-run add <name> <endpoint> [token]` | 添加自定义 endpoint |
|
|
54
|
+
| `cc-run remove <name>` | 删除自定义 endpoint |
|
|
55
|
+
|
|
56
|
+
### 原生命令配置
|
|
57
|
+
|
|
58
|
+
| 命令 | 说明 |
|
|
59
|
+
|------|------|
|
|
60
|
+
| `cc-run <provider> --claude` | 配置原生 `claude` 命令使用第三方 endpoint |
|
|
61
|
+
| `cc-run --claude` | 恢复原生 `claude` 命令使用官方 endpoint |
|
|
62
|
+
|
|
63
|
+
### 代理管理
|
|
64
|
+
|
|
65
|
+
| 命令 | 说明 |
|
|
66
|
+
|------|------|
|
|
67
|
+
| `cc-run proxy on` | 开启代理 |
|
|
68
|
+
| `cc-run proxy off` | 关闭代理 |
|
|
69
|
+
| `cc-run proxy status` | 查看代理状态 |
|
|
70
|
+
| `cc-run proxy reset` | 重置代理配置 |
|
|
71
|
+
|
|
72
|
+
## 内置 Endpoints
|
|
73
|
+
|
|
74
|
+
| 名称 | Endpoint |
|
|
75
|
+
|------|----------|
|
|
76
|
+
| glm | https://open.bigmodel.cn/api/paas/v4/ |
|
|
77
|
+
| deepseek | https://api.deepseek.com |
|
|
78
|
+
| minimax | https://api.minimax.chat/v1 |
|
|
79
|
+
|
|
80
|
+
## 配置文件
|
|
81
|
+
|
|
82
|
+
### ~/.cc-run/config.json
|
|
83
|
+
|
|
84
|
+
```json
|
|
85
|
+
{
|
|
86
|
+
"endpoints": [
|
|
87
|
+
{
|
|
88
|
+
"name": "my-custom",
|
|
89
|
+
"endpoint": "https://api.example.com/v1",
|
|
90
|
+
"token": "sk-xxxxxxxx"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
"tokens": {
|
|
94
|
+
"glm": "sk-xxxxxxxx",
|
|
95
|
+
"deepseek": "sk-yyyyyyyy",
|
|
96
|
+
"minimax": "sk-zzzzzzzz"
|
|
97
|
+
},
|
|
98
|
+
"lastUsed": "glm",
|
|
99
|
+
"proxy": {
|
|
100
|
+
"enabled": true,
|
|
101
|
+
"url": "http://agent.baidu.com:8891",
|
|
102
|
+
"clearForOfficial": false
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### ~/.claude/settings.json
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"proxy": "http://agent.baidu.com:8891"
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## 使用示例
|
|
116
|
+
|
|
117
|
+
### 添加自定义 endpoint
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
cc-run add my-api https://api.my-service.com/v1 sk-my-token
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 切换 endpoint
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# 使用 glm
|
|
127
|
+
cc-run glm
|
|
128
|
+
|
|
129
|
+
# 使用 deepseek
|
|
130
|
+
cc-run deepseek
|
|
131
|
+
|
|
132
|
+
# 使用自定义 endpoint
|
|
133
|
+
cc-run my-api
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### 配置代理
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# 开启代理(首次会提示输入代理地址)
|
|
140
|
+
cc-run proxy on
|
|
141
|
+
|
|
142
|
+
# 查看代理状态
|
|
143
|
+
cc-run proxy status
|
|
144
|
+
|
|
145
|
+
# 关闭代理
|
|
146
|
+
cc-run proxy off
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 配置原生命令
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# 让原生 claude 命令使用 glm
|
|
153
|
+
cc-run glm --claude
|
|
154
|
+
|
|
155
|
+
# 之后直接使用 claude 命令即可
|
|
156
|
+
claude "你好"
|
|
157
|
+
|
|
158
|
+
# 恢复使用官方 endpoint
|
|
159
|
+
cc-run --claude
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Token 管理
|
|
163
|
+
|
|
164
|
+
首次使用某个 endpoint 时,如果未配置 token,会提示输入:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
$ cc-run glm
|
|
168
|
+
请输入 glm 的 API Token: [输入框]
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
Token 会被保存到 `~/.cc-run/config.json`,下次使用时无需再次输入。
|
|
172
|
+
|
|
173
|
+
## 开发
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# 安装依赖
|
|
177
|
+
bun install
|
|
178
|
+
|
|
179
|
+
# 运行开发模式
|
|
180
|
+
bun run dev
|
|
181
|
+
|
|
182
|
+
# 构建
|
|
183
|
+
bun run build
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
MIT
|
package/bun.lock
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"configVersion": 1,
|
|
4
|
+
"workspaces": {
|
|
5
|
+
"": {
|
|
6
|
+
"name": "cc-run",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"commander": "^12.0.0",
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/node": "^20.0.0",
|
|
12
|
+
"bun-types": "latest",
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
"packages": {
|
|
17
|
+
"@types/node": ["@types/node@20.19.30", "https://registry.npmmirror.com/@types/node/-/node-20.19.30.tgz", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-WJtwWJu7UdlvzEAUm484QNg5eAoq5QR08KDNx7g45Usrs2NtOPiX8ugDqmKdXkyL03rBqU5dYNYVQetEpBHq2g=="],
|
|
18
|
+
|
|
19
|
+
"bun-types": ["bun-types@1.3.6", "https://registry.npmmirror.com/bun-types/-/bun-types-1.3.6.tgz", { "dependencies": { "@types/node": "*" } }, "sha512-OlFwHcnNV99r//9v5IIOgQ9Uk37gZqrNMCcqEaExdkVq3Avwqok1bJFmvGMCkCE0FqzdY8VMOZpfpR3lwI+CsQ=="],
|
|
20
|
+
|
|
21
|
+
"commander": ["commander@12.1.0", "https://registry.npmmirror.com/commander/-/commander-12.1.0.tgz", {}, "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA=="],
|
|
22
|
+
|
|
23
|
+
"undici-types": ["undici-types@6.21.0", "https://registry.npmmirror.com/undici-types/-/undici-types-6.21.0.tgz", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
|
|
24
|
+
}
|
|
25
|
+
}
|