ccoding 0.2.0__tar.gz → 0.2.2__tar.gz

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 (37) hide show
  1. ccoding-0.2.2/PKG-INFO +455 -0
  2. ccoding-0.2.2/README.md +404 -0
  3. {ccoding-0.2.0 → ccoding-0.2.2}/pyproject.toml +16 -2
  4. ccoding-0.2.2/screenshot_mobile1.jpeg +0 -0
  5. ccoding-0.2.2/screenshot_mobile2.jpeg +0 -0
  6. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/config.py +85 -24
  7. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/remote.py +125 -164
  8. ccoding-0.2.2/src/ccode/remote_cli.py +226 -0
  9. ccoding-0.2.2/src/ccode/remote_client.py +274 -0
  10. ccoding-0.2.2/src/ccode/remote_common.py +194 -0
  11. ccoding-0.2.2/src/ccode/remote_server.py +302 -0
  12. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/ui.py +104 -36
  13. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/app.js +205 -21
  14. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/index.html +17 -1
  15. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/style.css +111 -0
  16. ccoding-0.2.2/uv.lock +699 -0
  17. ccoding-0.2.0/PKG-INFO +0 -189
  18. ccoding-0.2.0/README.md +0 -146
  19. ccoding-0.2.0/src/ccode/remote_cli.py +0 -182
  20. ccoding-0.2.0/uv.lock +0 -680
  21. {ccoding-0.2.0 → ccoding-0.2.2}/.github/workflows/publish.yml +0 -0
  22. {ccoding-0.2.0 → ccoding-0.2.2}/.gitignore +0 -0
  23. {ccoding-0.2.0 → ccoding-0.2.2}/CLAUDE.md +0 -0
  24. {ccoding-0.2.0 → ccoding-0.2.2}/LICENSE +0 -0
  25. {ccoding-0.2.0 → ccoding-0.2.2}/screenshot.png +0 -0
  26. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/__init__.py +0 -0
  27. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/__main__.py +0 -0
  28. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/api.py +0 -0
  29. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/cli.py +0 -0
  30. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/env_schema.json +0 -0
  31. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/logo.py +0 -0
  32. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/__init__.py +0 -0
  33. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/assets/addon-fit.js +0 -0
  34. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/assets/xterm-LICENSE +0 -0
  35. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/assets/xterm-addon-fit-LICENSE +0 -0
  36. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/assets/xterm.css +0 -0
  37. {ccoding-0.2.0 → ccoding-0.2.2}/src/ccode/web/assets/xterm.js +0 -0
ccoding-0.2.2/PKG-INFO ADDED
@@ -0,0 +1,455 @@
1
+ Metadata-Version: 2.4
2
+ Name: ccoding
3
+ Version: 0.2.2
4
+ Summary: Curses-based Claude Code launcher
5
+ Project-URL: Homepage, https://github.com/8DE4732A/ccode
6
+ Project-URL: Repository, https://github.com/8DE4732A/ccode
7
+ Project-URL: Issues, https://github.com/8DE4732A/ccode/issues
8
+ Author: 8de4732a
9
+ License: MIT License
10
+
11
+ Copyright (c) 2025 8DE4732A
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: claude,claude-code,curses,launcher,tui
32
+ Classifier: Environment :: Console :: Curses
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Operating System :: POSIX
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3 :: Only
37
+ Requires-Python: >=3.10
38
+ Requires-Dist: windows-curses; sys_platform == 'win32'
39
+ Provides-Extra: remote
40
+ Requires-Dist: fastapi; extra == 'remote'
41
+ Requires-Dist: pexpect; (sys_platform != 'win32') and extra == 'remote'
42
+ Requires-Dist: uvicorn[standard]; extra == 'remote'
43
+ Requires-Dist: websockets; extra == 'remote'
44
+ Provides-Extra: remote-client
45
+ Requires-Dist: pexpect; (sys_platform != 'win32') and extra == 'remote-client'
46
+ Requires-Dist: websockets; extra == 'remote-client'
47
+ Provides-Extra: remote-server
48
+ Requires-Dist: fastapi; extra == 'remote-server'
49
+ Requires-Dist: uvicorn[standard]; extra == 'remote-server'
50
+ Description-Content-Type: text/markdown
51
+
52
+ # CCode Launcher (Curses UI)
53
+
54
+ 这是一个基于 curses 的 Claude Code 启动器,提供键盘全操作的终端界面,用于配置 Base URL、API Key、模型选择和常用开关,并直接启动 `claude` 命令。
55
+
56
+ 工具的目的是方便启动 claude code 时快速选择想要使用的模型。模型网关可以使用 litellm proxy 或者 CLI Proxy API。
57
+
58
+ ![](screenshot.png)
59
+
60
+ <p align="center">
61
+ <img src="screenshot_mobile1.jpeg" alt="Mobile remote terminal screenshot 1" width="45%" />
62
+ <img src="screenshot_mobile2.jpeg" alt="Mobile remote terminal screenshot 2" width="45%" />
63
+ </p>
64
+
65
+ ## 功能特点
66
+
67
+ - 终端 curses UI,键盘全操作
68
+ - 主界面选择 OPUS / SONNET / HAIKU 的 owned_by 与 model_id
69
+ - 配置界面编辑 Base URL / API Key 与常用开关
70
+ - 自动保存配置到 `~/.ccode/config.json`
71
+ - 直接启动 `claude` 并传递额外参数
72
+ - Remote/Web 模式:通过 tmux 保留多个 Claude Code 会话,并在浏览器中选择和操作
73
+ - 支持本机 local hub,也支持公网中心 `ccode-remote-server` 聚合多台设备
74
+ - 动画 Logo(颜色渐变 / 流光 / 轻微波浪)
75
+
76
+ ## 安装
77
+
78
+ 推荐使用 [uv](https://github.com/astral-sh/uv) 安装为全局工具:
79
+
80
+ ```bash
81
+ uv tool install ccoding
82
+ ```
83
+
84
+ 如果需要 Remote/Web 功能,按使用场景安装对应 extra:
85
+
86
+ ```bash
87
+ uv tool install 'ccoding[remote-client]' # 客户端设备:运行 ccode,并连接中心 server
88
+ uv tool install 'ccoding[remote-server]' # 公网中心 server:运行 ccode-remote-server
89
+ uv tool install 'ccoding[remote]' # 同时包含 client/server remote 依赖
90
+ ```
91
+
92
+ 已经安装过基础版本时,可以用 `--reinstall` 重新安装带 extra 的版本:
93
+
94
+ ```bash
95
+ uv tool install --reinstall 'ccoding[remote]'
96
+ ```
97
+
98
+ 或使用 [pipx](https://pipx.pypa.io):
99
+
100
+ ```bash
101
+ pipx install ccoding
102
+ pipx install 'ccoding[remote]'
103
+ ```
104
+
105
+ ### uv tool extras 区别
106
+
107
+ `uv tool install 'ccoding[remote-client]'`、`uv tool install 'ccoding[remote-server]'` 和 `uv tool install 'ccoding[remote]'` 安装的都是同一个 Python 包 `ccoding`,因此都会安装基础命令入口。区别只在于额外依赖是否齐全,以及对应 remote 能力是否可用。
108
+
109
+ | 安装方式 | `ccode` 基础 TUI | `ccode-remote` | `ccode-remote-server` | 安装的额外依赖 | 适合场景 |
110
+ |---|---:|---:|---:|---|---|
111
+ | `uv tool install ccoding` | 可用 | 命令存在,但 remote 功能依赖不足 | 命令存在,但缺 server 依赖不能运行 | 无 | 只用模型选择 TUI |
112
+ | `uv tool install 'ccoding[remote-client]'` | 可用 | 可管理 client connector;local hub 可能缺 FastAPI/uvicorn | 命令存在,但缺 FastAPI/uvicorn 不能运行 | `pexpect`、`websockets` | 客户端设备:启动 Claude session 并连接中心 server |
113
+ | `uv tool install 'ccoding[remote-server]'` | 可用 | 命令存在,但 client/local 能力依赖不足 | 可运行 | `fastapi`、`uvicorn[standard]` | 只部署公网中心 server |
114
+ | `uv tool install 'ccoding[remote]'` | 可用 | 可用 | 可用 | `pexpect`、`websockets`、`fastapi`、`uvicorn[standard]` | 开发环境或单机全功能 |
115
+
116
+ 推荐选择:
117
+
118
+ - 只在本机选择模型并启动 Claude:`uv tool install ccoding`
119
+ - 这台机器是“客户端设备”,需要用 `ccode` 启动 remote session 并连接中心 server:`uv tool install 'ccoding[remote-client]'`
120
+ - 这台机器只负责运行公网中心 server:`uv tool install 'ccoding[remote-server]'`
121
+ - 不想区分角色,或开发调试需要本机同时跑 server 和 client:`uv tool install 'ccoding[remote]'`
122
+
123
+ 安装后直接运行:
124
+
125
+ ```bash
126
+ ccode
127
+ ccode --chrome # 传递额外参数给 claude
128
+ ccode-remote # 查看 remote hub / client connector 状态
129
+ ```
130
+
131
+ ## 开发者运行方式
132
+
133
+ 需要 Python >=3.10。基础 TUI 不再强制安装 remote 依赖。Remote/Web 模式需要额外依赖,并需要系统中已安装 `tmux` 和 `claude`;Windows 建议在 WSL 中使用 remote 模式。
134
+
135
+ 使用 Remote/Web 时,推荐在 `~/.tmux.conf` 中配置:
136
+
137
+ ```tmux
138
+ set -g history-limit 50000
139
+ set -g mouse on
140
+ set -g default-terminal "screen-256color"
141
+ set-option -ga terminal-overrides ",xterm-256color:Tc"
142
+ ```
143
+
144
+ ```bash
145
+ git clone https://github.com/8DE4732A/ccode
146
+ cd ccode
147
+ uv sync
148
+ uv run ccode
149
+ ```
150
+
151
+ 按需安装 remote extras:
152
+
153
+ ```bash
154
+ uv sync --extra remote-client # 客户端 connector:pexpect + websockets
155
+ uv sync --extra remote-server # 公网中心 server:FastAPI + uvicorn
156
+ uv sync --extra remote # 同时安装 client/server 依赖
157
+ ```
158
+
159
+ ## 快捷键(主界面)
160
+
161
+ - `↑ / ↓`:切换 OPUS / SONNET / HAIKU 行
162
+ - `← / →`:切换 owned_by / model_id 字段
163
+ - `a / d`:循环切换当前字段的可选项
164
+ - `b`:刷新模型列表
165
+ - `r`:切换 Remote/Web 模式
166
+ - `c`:进入配置界面
167
+ - `Enter`:校验并启动本地 `claude`;Remote/Web 模式开启时启动 remote session
168
+ - `q`:退出
169
+
170
+ > 提示:首次使用需要先在配置界面设置 Base URL 与 API Key,然后返回主界面按 `b` 获取模型列表。
171
+
172
+ ## 快捷键(配置界面)
173
+
174
+ - `↑ / ↓`:移动字段焦点
175
+ - `Enter / Space`:切换开关项
176
+ - 文本输入:编辑 BASE_URL / API_KEY、remote local/server URL/token/device/prefix 等字段
177
+ - `g`:在 Remote local token 或 server client token 字段重新生成访问 token
178
+ - `ESC`:自动保存并返回主界面
179
+
180
+ ## 配置文件
181
+
182
+ 配置自动保存在:
183
+
184
+ ```
185
+ ~/.ccode/config.json
186
+ ```
187
+
188
+ 示例结构:
189
+
190
+ ```json
191
+ {
192
+ "base_url": "http://127.0.0.1:8317",
193
+ "api_key": "",
194
+ "models": {
195
+ "opus": {"owned_by": null, "id": null},
196
+ "sonnet": {"owned_by": null, "id": null},
197
+ "haiku": {"owned_by": null, "id": null}
198
+ },
199
+ "toggles": {
200
+ "CLAUDE_CODE_ENABLE_TELEMETRY": "0",
201
+ "DISABLE_COST_WARNINGS": "1",
202
+ "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
203
+ },
204
+ "remote": {
205
+ "enabled": false,
206
+ "mode": "local",
207
+ "session_name": "ccode-claude",
208
+ "reuse_session": true,
209
+ "local": {
210
+ "host": "127.0.0.1",
211
+ "port": 8765,
212
+ "token": ""
213
+ },
214
+ "server": {
215
+ "url": "",
216
+ "token": "",
217
+ "device_name": "",
218
+ "device_id": "",
219
+ "auto_connect": true,
220
+ "verify_tls": true
221
+ }
222
+ }
223
+ }
224
+ ```
225
+
226
+ ## Remote/Web 模式
227
+
228
+ Remote/Web 让 Claude Code 运行在 tmux session 中,浏览器通过 WebSocket attach 到这个 session。它有两种模式:
229
+
230
+ | 模式 | 浏览器访问 | session 所在位置 | 适合场景 |
231
+ |---|---|---|---|
232
+ | `local` | 直接访问本机 local hub | 当前这台机器 | 单机使用,或把这一台机器通过 tunnel 暴露出去 |
233
+ | `server` | 访问公网中心 `ccode-remote-server` | 各客户端设备本机 | 多设备、NAT 后设备、统一入口管理多个 sessions |
234
+
235
+ ### local 模式
236
+
237
+ local 模式会在本机启动一个共享 FastAPI hub。浏览器直接访问这个 hub,hub 再 attach 到本机 tmux session。
238
+
239
+ ```text
240
+ Browser
241
+ │ HTTP / WebSocket
242
+ ▼
243
+ Local ccode remote hub
244
+ │ pexpect attach
245
+ ▼
246
+ tmux session
247
+ │
248
+ ▼
249
+ claude
250
+ ```
251
+
252
+ 使用步骤:
253
+
254
+ 1. 安装完整 remote 或至少确保 local hub 依赖可用:
255
+
256
+ ```bash
257
+ uv tool install 'ccoding[remote]'
258
+ ```
259
+
260
+ 2. 运行 `ccode`,进入配置页:
261
+
262
+ - `MODE`:`local`
263
+ - `LOCAL HOST`:默认 `127.0.0.1`
264
+ - `LOCAL PORT`:默认 `8765`
265
+ - `LOCAL TOKEN`:手动输入,或在该字段按 `g` 生成
266
+
267
+ 3. 回到主界面,按 `r` 开启 Remote/Web,再按 `Enter` 启动 remote session。
268
+
269
+ 4. 浏览器打开终端输出的本地地址,输入 `LOCAL TOKEN`,选择 session 后进入 terminal。
270
+
271
+ local 模式默认只监听 `127.0.0.1`。终端只输出不带 token 的本地访问地址。浏览器打开页面后需要手动输入 token,前端会用 `sessionStorage` 做浏览器会话级缓存;关闭该浏览器会话后需要重新输入。所有 session list、session API 和 WebSocket 连接仍然需要 token。
272
+
273
+ 每个启用 Remote/Web 的 `ccode` 进程都会创建一个唯一 tmux session,session 名由配置里的 `session_name` 前缀、时间戳和进程号组成,例如 `ccode-claude-20260509-153022-12345`。本机只启动一个共享 remote hub,多个本地 `ccode` 进程会复用同一个 host/port/token。浏览器认证后会先显示 session 列表,选择某个 session 后进入 terminal,也可以返回列表重新选择。
274
+
275
+ 如果通过 Cloudflare Tunnel、Nginx、Caddy 等反向代理暴露 local hub,建议额外叠加 Cloudflare Access、Basic Auth 或 OAuth2 proxy。监听 `0.0.0.0` 会把所有 remote sessions 暴露给网络内可达主机,请保护好访问入口和 token。
276
+
277
+ ```bash
278
+ cloudflared tunnel --url http://127.0.0.1:8765
279
+ ```
280
+
281
+ local hub 日志写入 `~/.ccode/remote_server.log`,记录 hub 启停、session 注册、session API 和 WebSocket 连接状态,不记录 token。启动 hub 前如果日志超过 5 MiB 会自动轮转,默认保留 3 个历史文件(`.1`、`.2`、`.3`)。
282
+
283
+ ### server 模式和 `ccode-remote-server`
284
+
285
+ `ccode-remote-server` 是可部署到公网的中心 registry/router/relay。它不创建本地 PTY,也不会保存 Anthropic API key、模型配置、客户端环境变量或 terminal 内容;每台客户端继续负责自己的 tmux/Claude 会话,并通过出站 WebSocket 连接 server。
286
+
287
+ 整体结构:
288
+
289
+ ```text
290
+ Browser
291
+ │
292
+ │ HTTPS/WSS + admin token
293
+ ▼
294
+ ┌───────────────────────┐
295
+ │ ccode-remote-server │
296
+ │ registry/router/relay │
297
+ └───────────┬───────────┘
298
+ │ attach relay
299
+ ┌─────────────┼─────────────┐
300
+ │ │ │
301
+ ▼ ▼ ▼
302
+ ┌────────────┐ ┌────────────┐ ┌────────────┐
303
+ │ Laptop A │ │ Server B │ │ Desktop C │
304
+ │ connector │ │ connector │ │ connector │
305
+ │ tmux/claude│ │ tmux/claude│ │ tmux/claude│
306
+ └────────────┘ └────────────┘ └────────────┘
307
+ ```
308
+
309
+ 连接方向:
310
+
311
+ ```text
312
+ 客户端设备 ──出站 WebSocket──▶ ccode-remote-server ◀──浏览器访问── Browser
313
+ ```
314
+
315
+ server 不反连客户端,所以客户端可以在 NAT、家庭网络或公司内网后面。只要客户端能主动访问 server,就可以注册设备和暴露自己的 remote sessions。
316
+
317
+ #### server token
318
+
319
+ server token 不会自动生成,必须通过环境变量显式设置:
320
+
321
+ - `CCODE_REMOTE_SERVER_ADMIN_TOKEN`:浏览器 Web UI / `/api/*` / browser WebSocket 使用的管理 token。
322
+ - `CCODE_REMOTE_SERVER_CLIENT_TOKEN`:各设备客户端 connector 注册和心跳使用的 token。
323
+ - `CCODE_REMOTE_SERVER_HOST` / `CCODE_REMOTE_SERVER_PORT`:可选,默认监听 `127.0.0.1:8765`。
324
+
325
+ 启动中心 server:
326
+
327
+ ```bash
328
+ CCODE_REMOTE_SERVER_ADMIN_TOKEN="admin-secret" \
329
+ CCODE_REMOTE_SERVER_CLIENT_TOKEN="client-secret" \
330
+ ccode-remote-server --host 127.0.0.1 --port 8765
331
+ ```
332
+
333
+ 如果使用源码开发环境运行:
334
+
335
+ ```bash
336
+ CCODE_REMOTE_SERVER_ADMIN_TOKEN="admin-secret" \
337
+ CCODE_REMOTE_SERVER_CLIENT_TOKEN="client-secret" \
338
+ uv run --extra remote-server ccode-remote-server --host 127.0.0.1 --port 8765
339
+ ```
340
+
341
+ 浏览器访问 server 页面时输入 `admin-secret`。如果未设置 `CCODE_REMOTE_SERVER_ADMIN_TOKEN`,管理 API 会返回 401,页面上任何 token 都无法通过认证。
342
+
343
+ #### 客户端设备配置
344
+
345
+ 每台客户端设备需要安装 client extra:
346
+
347
+ ```bash
348
+ uv tool install 'ccoding[remote-client]'
349
+ ```
350
+
351
+ 然后运行 `ccode`,在配置页设置:
352
+
353
+ - `MODE`:`server`
354
+ - `SERVER URL`:中心 server 地址,例如 `http://127.0.0.1:8765`;如果只填 `127.0.0.1:8765`,会自动按 `http://127.0.0.1:8765` 处理
355
+ - `CLIENT TOKEN`:与 server 的 `CCODE_REMOTE_SERVER_CLIENT_TOKEN` 一致
356
+ - `DEVICE NAME`:设备显示名,可留空后由配置迁移填充 hostname
357
+ - `DEVICE ID`:稳定设备 ID,可留空后自动生成
358
+ - `AUTO CONNECT`:是否默认自动连接中心 server
359
+
360
+ 配置完成后,在主界面按 `r` 开启 Remote/Web,再按 `Enter` 启动 remote session。server 模式会注册本地 tmux session,并确保后台 client connector 运行。浏览器打开中心 server 后即可看到所有在线设备和 sessions。
361
+
362
+ 也可以用命令检查和管理客户端 connector:
363
+
364
+ ```bash
365
+ ccode-remote client status
366
+ ccode-remote client start
367
+ ccode-remote client restart
368
+ ccode-remote client stop
369
+ ```
370
+
371
+ #### attach 数据流
372
+
373
+ 浏览器点击某个设备上的 session 时,server 会创建一次性短生命周期 `attach_id`,通知目标客户端主动建立 attach WebSocket,然后在浏览器和客户端之间转发 terminal JSON 帧。
374
+
375
+ ```text
376
+ 1. Browser ── WS /ws/devices/{device_id}/sessions/{session_id} ──▶ Server
377
+ 2. Server ── attach_request(attach_id, session_id) ─────────────▶ Client connector
378
+ 3. Client ── WS /client/attach/{attach_id} ─────────────────────▶ Server
379
+ 4. Server ◀──────────── relay input/output/resize ─────────────▶ Browser
380
+ 5. Client connector ── pexpect ──▶ local tmux session ──▶ claude
381
+ ```
382
+
383
+ server 只做 registry/router/relay,不保存 terminal frame data,不保存 Anthropic API key,不保存模型配置。`cwd`、tmux session 名、创建时间等 metadata 会用于 session 列表展示。
384
+
385
+ #### Cloudflare Tunnel / 反向代理
386
+
387
+ 如果用 Cloudflare Tunnel 暴露中心 server,只需要 tunnel server 这一处入口,多台客户端设备都配置同一个 `SERVER URL` 和 `CLIENT TOKEN`:
388
+
389
+ ```bash
390
+ cloudflared tunnel --url http://127.0.0.1:8765
391
+ ```
392
+
393
+ 生产环境建议只使用 HTTPS/WSS;如果 `SERVER URL` 使用 `http://`,客户端会提示明文连接风险。建议再叠加 Cloudflare Access、Basic Auth 或 OAuth2 proxy。
394
+
395
+ ### remote 管理命令
396
+
397
+ `ccode-remote` 会根据当前配置的 `remote.mode` 自动管理 local hub 或 client connector;也可以显式指定 `local` / `client`:
398
+
399
+ ```bash
400
+ ccode-remote
401
+ ccode-remote status
402
+ ccode-remote start
403
+ ccode-remote restart
404
+ ccode-remote stop
405
+
406
+ ccode-remote local status
407
+ ccode-remote local start
408
+ ccode-remote local stop
409
+
410
+ ccode-remote client status
411
+ ccode-remote client start
412
+ ccode-remote client restart
413
+ ccode-remote client stop
414
+ ```
415
+
416
+ 日志和状态文件:
417
+
418
+ | 文件 | 用途 |
419
+ |---|---|
420
+ | `~/.ccode/remote_sessions.json` | 本机 session registry,只记录 tmux session、cwd、args、创建时间和 owner pid |
421
+ | `~/.ccode/remote_server.log` | local hub 日志 |
422
+ | `~/.ccode/remote_client.log` | server 模式 client connector 日志 |
423
+ | `~/.ccode/remote_hub.pid` | local hub 后台进程 pid |
424
+ | `~/.ccode/remote_client.pid` | client connector 后台进程 pid |
425
+
426
+ 浏览器和多个本地终端可以同时 attach 到同一个 tmux session,输入会互相影响,这是预期行为。可用 `Ctrl+B` 然后 `D` 从本地终端 detach;remote hub 或 client connector 会独立留在后台运行,tmux session 不会因为浏览器断开而被 kill。
427
+
428
+ ## 工作原理
429
+
430
+ 基础启动流程:
431
+
432
+ ```text
433
+ ~/.ccode/config.json
434
+ │
435
+ ▼
436
+ ccode curses UI ── fetch /v1/models ──▶ LiteLLM proxy / CLI Proxy API
437
+ │
438
+ ▼
439
+ 选择 OPUS / SONNET / HAIKU model_id
440
+ │
441
+ ▼
442
+ build_env() 注入环境变量
443
+ │
444
+ ▼
445
+ subprocess.run(["claude", ...])
446
+ ```
447
+
448
+ 1. 从 `~/.ccode/config.json` 读取配置(首次运行自动生成)。
449
+ 2. 根据 Base URL + API Key 拉取模型列表。
450
+ 3. 选择 OPUS / SONNET / HAIKU 的 owned_by / model_id。
451
+ 4. 启动 `claude`,并注入相关环境变量。
452
+
453
+ ## 许可证
454
+
455
+ MIT