@h1d3rone/claude-proxy 0.1.0 → 0.1.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.
- package/README.md +50 -281
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,338 +1,107 @@
|
|
|
1
1
|
# claude-proxy
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## 中文
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### 项目说明
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`claude-proxy` 是一个本地单机版 Claude 代理工具。它会在本机提供 Claude 兼容的 `/v1/messages` 服务,把请求转发到 OpenAI 兼容上游,并管理 Claude Code 与 Codex 的本地配置。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- 交互式生成和维护 `~/.claude-proxy/config.toml`
|
|
11
|
-
- 自动修改 `~/.claude/settings.json`,让 Claude Code 走本地代理
|
|
12
|
-
- 自动修改 `~/.codex/config.toml` 和 `~/.codex/auth.json`
|
|
13
|
-
- 支持全量配置/清理,也支持只处理 `claude` 或 `openai` 单项
|
|
14
|
-
- 支持 Claude 会话开始自动启动代理、结束自动停止代理
|
|
15
|
-
- 只支持本机,不再支持远端主机配置
|
|
9
|
+
### 安装
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Node.js `>= 18`
|
|
20
|
-
- 已安装 Claude Code
|
|
21
|
-
- 如果需要同步配置 Codex,需要本机存在 `~/.codex`
|
|
22
|
-
|
|
23
|
-
## 安装
|
|
24
|
-
|
|
25
|
-
推荐全局安装,因为 Claude Hook 需要能直接在 `PATH` 中找到 `claude-proxy`。
|
|
11
|
+
`npm` 快速安装:
|
|
26
12
|
|
|
27
13
|
```bash
|
|
28
14
|
npm install -g @h1d3rone/claude-proxy
|
|
15
|
+
claude-proxy config
|
|
29
16
|
```
|
|
30
17
|
|
|
31
|
-
|
|
18
|
+
提示:包名带作用域,但实际命令仍然是 `claude-proxy`。
|
|
32
19
|
|
|
33
|
-
|
|
34
|
-
claude-proxy
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
开发环境:
|
|
20
|
+
Git 源码安装:
|
|
38
21
|
|
|
39
22
|
```bash
|
|
23
|
+
git clone https://github.com/H1d3rOne/claude-proxy.git
|
|
24
|
+
cd claude-proxy
|
|
40
25
|
npm install
|
|
41
|
-
npm
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## 快速开始
|
|
45
|
-
|
|
46
|
-
1. 全量配置:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
26
|
+
npm link
|
|
49
27
|
claude-proxy config
|
|
50
28
|
```
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
claude-proxy config get
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
3. 手动启动代理:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
claude-proxy start
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
如果已经执行过 `claude-proxy config`,Claude Code 会在会话开始时自动检查代理是否已运行,未运行则启动;会话结束时自动停止。
|
|
65
|
-
|
|
66
|
-
## 命令
|
|
67
|
-
|
|
68
|
-
### 配置命令
|
|
30
|
+
### 使用方法
|
|
69
31
|
|
|
70
32
|
```bash
|
|
71
33
|
claude-proxy config
|
|
72
34
|
claude-proxy config claude
|
|
73
35
|
claude-proxy config openai
|
|
74
36
|
claude-proxy config get
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
- `claude-proxy config`
|
|
78
|
-
交互式配置全部字段,并同时应用到 Claude Code 和 Codex。
|
|
79
37
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
- `claude-proxy config openai`
|
|
84
|
-
只配置 OpenAI/Codex 相关字段,并只更新 Codex 配置。
|
|
85
|
-
|
|
86
|
-
- `claude-proxy config get`
|
|
87
|
-
显示配置文件、Claude、Codex 的当前状态。
|
|
88
|
-
|
|
89
|
-
### 清理命令
|
|
38
|
+
claude-proxy start
|
|
39
|
+
claude-proxy stop
|
|
90
40
|
|
|
91
|
-
```bash
|
|
92
41
|
claude-proxy clean
|
|
93
42
|
claude-proxy clean claude
|
|
94
43
|
claude-proxy clean openai
|
|
95
44
|
```
|
|
96
45
|
|
|
97
|
-
- `
|
|
98
|
-
|
|
46
|
+
- `config`:交互式写入本地配置并应用配置
|
|
47
|
+
- `config claude`:只配置 Claude 相关部分
|
|
48
|
+
- `config openai`:只配置 OpenAI/Codex 相关部分
|
|
49
|
+
- `config get`:查看配置文件、Claude、Codex 当前状态
|
|
50
|
+
- `start`:启动本地代理服务器
|
|
51
|
+
- `stop`:停止本地代理服务器
|
|
52
|
+
- `clean`:一键清除全部受管配置
|
|
53
|
+
- `clean claude`:只清除 Claude 配置
|
|
54
|
+
- `clean openai`:只清除 OpenAI/Codex 配置
|
|
99
55
|
|
|
100
|
-
|
|
101
|
-
只恢复 Claude 相关文件,并清除 `config.toml` 中 Claude 相关字段。
|
|
56
|
+
## English
|
|
102
57
|
|
|
103
|
-
|
|
104
|
-
只恢复 Codex/OpenAI 相关文件,并清除 `config.toml` 中 OpenAI 相关字段。
|
|
58
|
+
### Overview
|
|
105
59
|
|
|
106
|
-
|
|
60
|
+
`claude-proxy` is a local single-machine Claude proxy. It exposes a Claude-compatible `/v1/messages` endpoint, forwards requests to an OpenAI-compatible upstream, and manages local Claude Code and Codex configuration.
|
|
107
61
|
|
|
108
|
-
|
|
109
|
-
- 如果需要停止代理,使用 `claude-proxy stop`
|
|
62
|
+
### Installation
|
|
110
63
|
|
|
111
|
-
|
|
64
|
+
Quick install with `npm`:
|
|
112
65
|
|
|
113
66
|
```bash
|
|
114
|
-
claude-proxy
|
|
115
|
-
claude-proxy
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
- `claude-proxy start`
|
|
119
|
-
使用当前配置启动本地代理,前台运行,启动成功后会输出监听地址和端口。
|
|
120
|
-
|
|
121
|
-
- `claude-proxy stop`
|
|
122
|
-
停止当前受管代理进程。
|
|
123
|
-
|
|
124
|
-
## 配置文件
|
|
125
|
-
|
|
126
|
-
默认配置文件路径:
|
|
127
|
-
|
|
128
|
-
```bash
|
|
129
|
-
~/.claude-proxy/config.toml
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
也可以用 `--config` 指定:
|
|
133
|
-
|
|
134
|
-
```bash
|
|
135
|
-
claude-proxy config --config /path/to/config.toml
|
|
136
|
-
claude-proxy config claude --config /path/to/config.toml
|
|
137
|
-
claude-proxy config openai --config /path/to/config.toml
|
|
138
|
-
claude-proxy config get --config /path/to/config.toml
|
|
139
|
-
claude-proxy clean --config /path/to/config.toml
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
参考示例见 [config_example.toml](./config_example.toml)。
|
|
143
|
-
|
|
144
|
-
### 配置项
|
|
145
|
-
|
|
146
|
-
- `server_host`
|
|
147
|
-
代理监听地址,默认 `127.0.0.1`
|
|
148
|
-
|
|
149
|
-
- `server_port`
|
|
150
|
-
代理监听端口,默认 `8082`
|
|
151
|
-
|
|
152
|
-
- `base_url`
|
|
153
|
-
OpenAI 兼容上游地址
|
|
154
|
-
|
|
155
|
-
- `api_key`
|
|
156
|
-
上游 API Key
|
|
157
|
-
|
|
158
|
-
- `big_model`
|
|
159
|
-
Claude `opus` 请求映射到的上游模型
|
|
160
|
-
|
|
161
|
-
- `middle_model`
|
|
162
|
-
Claude `sonnet` 请求映射到的上游模型
|
|
163
|
-
|
|
164
|
-
- `small_model`
|
|
165
|
-
Claude `haiku` 请求映射到的上游模型
|
|
166
|
-
|
|
167
|
-
- `default_claude_model`
|
|
168
|
-
Claude Code 默认模型
|
|
169
|
-
|
|
170
|
-
- `home_dir`
|
|
171
|
-
家目录基路径,默认 `~`
|
|
172
|
-
|
|
173
|
-
- `claude_dir`
|
|
174
|
-
Claude 配置目录,默认 `~/.claude`
|
|
175
|
-
|
|
176
|
-
- `codex_dir`
|
|
177
|
-
Codex 配置目录,默认 `~/.codex`
|
|
178
|
-
|
|
179
|
-
- `codex_provider`
|
|
180
|
-
Codex 中要修改的 provider 名称,可选
|
|
181
|
-
|
|
182
|
-
### 字段归属
|
|
183
|
-
|
|
184
|
-
`claude-proxy config claude` / `claude-proxy clean claude` 管理这些字段:
|
|
185
|
-
|
|
186
|
-
- `server_port`
|
|
187
|
-
- `big_model`
|
|
188
|
-
- `middle_model`
|
|
189
|
-
- `small_model`
|
|
190
|
-
- `default_claude_model`
|
|
191
|
-
- `claude_dir`
|
|
192
|
-
|
|
193
|
-
`claude-proxy config openai` / `claude-proxy clean openai` 管理这些字段:
|
|
194
|
-
|
|
195
|
-
- `base_url`
|
|
196
|
-
- `api_key`
|
|
197
|
-
- `codex_dir`
|
|
198
|
-
- `codex_provider`
|
|
199
|
-
|
|
200
|
-
`claude-proxy config` / `claude-proxy clean` 会处理以上全部受管字段。
|
|
201
|
-
|
|
202
|
-
## Claude 与 Codex 的实际改动
|
|
203
|
-
|
|
204
|
-
### Claude
|
|
205
|
-
|
|
206
|
-
执行配置命令后,会修改 `~/.claude/settings.json` 中的受管部分:
|
|
207
|
-
|
|
208
|
-
- `ANTHROPIC_BASE_URL=http://localhost:<server_port>`
|
|
209
|
-
- `ANTHROPIC_API_KEY=arbitrary value`
|
|
210
|
-
- 默认模型相关环境变量
|
|
211
|
-
- `SessionStart` Hook:自动确保代理运行
|
|
212
|
-
- `SessionEnd` Hook:自动停止代理
|
|
213
|
-
|
|
214
|
-
### Codex
|
|
215
|
-
|
|
216
|
-
执行配置命令后,会修改:
|
|
217
|
-
|
|
218
|
-
- `~/.codex/config.toml`
|
|
219
|
-
将目标 provider 的 `base_url` 改为配置文件中的 `base_url`
|
|
220
|
-
|
|
221
|
-
- `~/.codex/auth.json`
|
|
222
|
-
将 `OPENAI_API_KEY` 改为配置文件中的 `api_key`
|
|
223
|
-
|
|
224
|
-
## 兼容性说明
|
|
225
|
-
|
|
226
|
-
### 上游 `base_url`
|
|
227
|
-
|
|
228
|
-
如果你填的是 provider 根地址,例如:
|
|
229
|
-
|
|
230
|
-
```toml
|
|
231
|
-
base_url = "https://newapis.xyz"
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
代理会自动把 Claude 转发流量发送到:
|
|
235
|
-
|
|
236
|
-
```text
|
|
237
|
-
/v1/chat/completions
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
如果你已经显式填写了 `/v1`,例如:
|
|
241
|
-
|
|
242
|
-
```toml
|
|
243
|
-
base_url = "https://newapis.xyz/v1"
|
|
67
|
+
npm install -g @h1d3rone/claude-proxy
|
|
68
|
+
claude-proxy config
|
|
244
69
|
```
|
|
245
70
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
### 单机模式
|
|
249
|
-
|
|
250
|
-
本项目当前只支持单机模式:
|
|
71
|
+
Note: the published package is scoped, but the command name is still `claude-proxy`.
|
|
251
72
|
|
|
252
|
-
|
|
253
|
-
- 不支持 `--host`
|
|
254
|
-
- 不支持旧版远端同步逻辑
|
|
255
|
-
|
|
256
|
-
## 常见工作流
|
|
257
|
-
|
|
258
|
-
### 首次接入
|
|
73
|
+
Install from Git source:
|
|
259
74
|
|
|
260
75
|
```bash
|
|
76
|
+
git clone https://github.com/H1d3rOne/claude-proxy.git
|
|
77
|
+
cd claude-proxy
|
|
78
|
+
npm install
|
|
79
|
+
npm link
|
|
261
80
|
claude-proxy config
|
|
262
|
-
claude-proxy config get
|
|
263
|
-
claude-proxy start
|
|
264
81
|
```
|
|
265
82
|
|
|
266
|
-
###
|
|
83
|
+
### Usage
|
|
267
84
|
|
|
268
85
|
```bash
|
|
86
|
+
claude-proxy config
|
|
269
87
|
claude-proxy config claude
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### 只重配 OpenAI/Codex
|
|
273
|
-
|
|
274
|
-
```bash
|
|
275
88
|
claude-proxy config openai
|
|
276
|
-
|
|
89
|
+
claude-proxy config get
|
|
277
90
|
|
|
278
|
-
|
|
91
|
+
claude-proxy start
|
|
92
|
+
claude-proxy stop
|
|
279
93
|
|
|
280
|
-
```bash
|
|
281
94
|
claude-proxy clean
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### 只还原 Claude
|
|
285
|
-
|
|
286
|
-
```bash
|
|
287
95
|
claude-proxy clean claude
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
### 只还原 OpenAI/Codex
|
|
291
|
-
|
|
292
|
-
```bash
|
|
293
96
|
claude-proxy clean openai
|
|
294
97
|
```
|
|
295
98
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
-
|
|
301
|
-
-
|
|
302
|
-
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
```bash
|
|
307
|
-
claude-proxy config
|
|
308
|
-
claude-proxy config claude
|
|
309
|
-
claude-proxy config openai
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
不是:
|
|
313
|
-
|
|
314
|
-
```bash
|
|
315
|
-
claude-proxy config set
|
|
316
|
-
claude-proxy config set claude
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
## 开发
|
|
320
|
-
|
|
321
|
-
```bash
|
|
322
|
-
npm install
|
|
323
|
-
npm test
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
常用 npm script:
|
|
327
|
-
|
|
328
|
-
```bash
|
|
329
|
-
npm run config
|
|
330
|
-
npm run config:claude
|
|
331
|
-
npm run config:openai
|
|
332
|
-
npm run config:get
|
|
333
|
-
npm run clean
|
|
334
|
-
npm run clean:claude
|
|
335
|
-
npm run clean:openai
|
|
336
|
-
npm run start
|
|
337
|
-
npm run stop
|
|
338
|
-
```
|
|
99
|
+
- `config`: interactively write and apply local configuration
|
|
100
|
+
- `config claude`: configure only Claude-related settings
|
|
101
|
+
- `config openai`: configure only OpenAI/Codex-related settings
|
|
102
|
+
- `config get`: show current config-file, Claude, and Codex state
|
|
103
|
+
- `start`: start the local proxy server
|
|
104
|
+
- `stop`: stop the local proxy server
|
|
105
|
+
- `clean`: clear all managed configuration
|
|
106
|
+
- `clean claude`: clear only Claude configuration
|
|
107
|
+
- `clean openai`: clear only OpenAI/Codex configuration
|