@uvl000/claude-trace 3.0.13-workflowexp.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.
Files changed (258) hide show
  1. package/README.md +477 -0
  2. package/README.zh-CN.md +477 -0
  3. package/dist/adapt/api-format.d.ts +41 -0
  4. package/dist/adapt/api-format.d.ts.map +1 -0
  5. package/dist/adapt/api-format.js +132 -0
  6. package/dist/adapt/api-format.js.map +1 -0
  7. package/dist/adapt/openai-adapter.d.ts +123 -0
  8. package/dist/adapt/openai-adapter.d.ts.map +1 -0
  9. package/dist/adapt/openai-adapter.js +628 -0
  10. package/dist/adapt/openai-adapter.js.map +1 -0
  11. package/dist/cli/cli-common.d.ts +73 -0
  12. package/dist/cli/cli-common.d.ts.map +1 -0
  13. package/dist/cli/cli-common.js +189 -0
  14. package/dist/cli/cli-common.js.map +1 -0
  15. package/dist/cli/cli.d.ts +23 -0
  16. package/dist/cli/cli.d.ts.map +1 -0
  17. package/dist/cli/cli.js +175 -0
  18. package/dist/cli/cli.js.map +1 -0
  19. package/dist/cli/codex-cli.d.ts +24 -0
  20. package/dist/cli/codex-cli.d.ts.map +1 -0
  21. package/dist/cli/codex-cli.js +146 -0
  22. package/dist/cli/codex-cli.js.map +1 -0
  23. package/dist/cli/opencode-cli.d.ts +23 -0
  24. package/dist/cli/opencode-cli.d.ts.map +1 -0
  25. package/dist/cli/opencode-cli.js +156 -0
  26. package/dist/cli/opencode-cli.js.map +1 -0
  27. package/dist/cli/trace-runner.d.ts +21 -0
  28. package/dist/cli/trace-runner.d.ts.map +1 -0
  29. package/dist/cli/trace-runner.js +282 -0
  30. package/dist/cli/trace-runner.js.map +1 -0
  31. package/dist/cli/validate-trace.d.ts +30 -0
  32. package/dist/cli/validate-trace.d.ts.map +1 -0
  33. package/dist/cli/validate-trace.js +230 -0
  34. package/dist/cli/validate-trace.js.map +1 -0
  35. package/dist/cli/verify-offline-bundle.d.ts +13 -0
  36. package/dist/cli/verify-offline-bundle.d.ts.map +1 -0
  37. package/dist/cli/verify-offline-bundle.js +89 -0
  38. package/dist/cli/verify-offline-bundle.js.map +1 -0
  39. package/dist/cli/vibe-coding-proxy-cli.d.ts +12 -0
  40. package/dist/cli/vibe-coding-proxy-cli.d.ts.map +1 -0
  41. package/dist/cli/vibe-coding-proxy-cli.js +218 -0
  42. package/dist/cli/vibe-coding-proxy-cli.js.map +1 -0
  43. package/dist/config/claude-config-overlay.d.ts +69 -0
  44. package/dist/config/claude-config-overlay.d.ts.map +1 -0
  45. package/dist/config/claude-config-overlay.js +229 -0
  46. package/dist/config/claude-config-overlay.js.map +1 -0
  47. package/dist/config/codex-config-overlay.d.ts +122 -0
  48. package/dist/config/codex-config-overlay.d.ts.map +1 -0
  49. package/dist/config/codex-config-overlay.js +352 -0
  50. package/dist/config/codex-config-overlay.js.map +1 -0
  51. package/dist/index.d.ts +15 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +37 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/intercept/forward-proxy.d.ts +77 -0
  56. package/dist/intercept/forward-proxy.d.ts.map +1 -0
  57. package/dist/intercept/forward-proxy.js +368 -0
  58. package/dist/intercept/forward-proxy.js.map +1 -0
  59. package/dist/intercept/header-redaction.d.ts +7 -0
  60. package/dist/intercept/header-redaction.d.ts.map +1 -0
  61. package/dist/intercept/header-redaction.js +28 -0
  62. package/dist/intercept/header-redaction.js.map +1 -0
  63. package/dist/intercept/interceptor-loader.js +26 -0
  64. package/dist/intercept/interceptor.d.ts +164 -0
  65. package/dist/intercept/interceptor.d.ts.map +1 -0
  66. package/dist/intercept/interceptor.js +496 -0
  67. package/dist/intercept/interceptor.js.map +1 -0
  68. package/dist/intercept/mitm-cert.d.ts +53 -0
  69. package/dist/intercept/mitm-cert.d.ts.map +1 -0
  70. package/dist/intercept/mitm-cert.js +259 -0
  71. package/dist/intercept/mitm-cert.js.map +1 -0
  72. package/dist/intercept/proxy-log-writer.d.ts +77 -0
  73. package/dist/intercept/proxy-log-writer.d.ts.map +1 -0
  74. package/dist/intercept/proxy-log-writer.js +323 -0
  75. package/dist/intercept/proxy-log-writer.js.map +1 -0
  76. package/dist/intercept/proxy-targets.d.ts +69 -0
  77. package/dist/intercept/proxy-targets.d.ts.map +1 -0
  78. package/dist/intercept/proxy-targets.js +129 -0
  79. package/dist/intercept/proxy-targets.js.map +1 -0
  80. package/dist/intercept/reverse-proxy.d.ts +191 -0
  81. package/dist/intercept/reverse-proxy.d.ts.map +1 -0
  82. package/dist/intercept/reverse-proxy.js +807 -0
  83. package/dist/intercept/reverse-proxy.js.map +1 -0
  84. package/dist/intercept/token-extractor.js +28 -0
  85. package/dist/report/html-generator.d.ts +96 -0
  86. package/dist/report/html-generator.d.ts.map +1 -0
  87. package/dist/report/html-generator.js +225 -0
  88. package/dist/report/html-generator.js.map +1 -0
  89. package/dist/report/index-generator.d.ts +89 -0
  90. package/dist/report/index-generator.d.ts.map +1 -0
  91. package/dist/report/index-generator.js +319 -0
  92. package/dist/report/index-generator.js.map +1 -0
  93. package/dist/report/shared-conversation-processor.d.ts +200 -0
  94. package/dist/report/shared-conversation-processor.d.ts.map +1 -0
  95. package/dist/report/shared-conversation-processor.js +720 -0
  96. package/dist/report/shared-conversation-processor.js.map +1 -0
  97. package/dist/routing/codex-routing.d.ts +40 -0
  98. package/dist/routing/codex-routing.d.ts.map +1 -0
  99. package/dist/routing/codex-routing.js +96 -0
  100. package/dist/routing/codex-routing.js.map +1 -0
  101. package/dist/routing/proxy-routing.d.ts +48 -0
  102. package/dist/routing/proxy-routing.d.ts.map +1 -0
  103. package/dist/routing/proxy-routing.js +113 -0
  104. package/dist/routing/proxy-routing.js.map +1 -0
  105. package/dist/tools/binary-utils.d.ts +29 -0
  106. package/dist/tools/binary-utils.d.ts.map +1 -0
  107. package/dist/tools/binary-utils.js +134 -0
  108. package/dist/tools/binary-utils.js.map +1 -0
  109. package/dist/tools/claude.d.ts +61 -0
  110. package/dist/tools/claude.d.ts.map +1 -0
  111. package/dist/tools/claude.js +449 -0
  112. package/dist/tools/claude.js.map +1 -0
  113. package/dist/tools/codex.d.ts +70 -0
  114. package/dist/tools/codex.d.ts.map +1 -0
  115. package/dist/tools/codex.js +492 -0
  116. package/dist/tools/codex.js.map +1 -0
  117. package/dist/tools/opencode.d.ts +85 -0
  118. package/dist/tools/opencode.d.ts.map +1 -0
  119. package/dist/tools/opencode.js +401 -0
  120. package/dist/tools/opencode.js.map +1 -0
  121. package/dist/tools/types.d.ts +91 -0
  122. package/dist/tools/types.d.ts.map +1 -0
  123. package/dist/tools/types.js +11 -0
  124. package/dist/tools/types.js.map +1 -0
  125. package/dist/types.d.ts +158 -0
  126. package/dist/types.d.ts.map +1 -0
  127. package/dist/types.js +12 -0
  128. package/dist/types.js.map +1 -0
  129. package/frontend/dist/index.global.js +1551 -0
  130. package/frontend/dist/styles.css +1027 -0
  131. package/frontend/template.html +19 -0
  132. package/node_modules/agent-base/LICENSE +22 -0
  133. package/node_modules/agent-base/README.md +69 -0
  134. package/node_modules/agent-base/dist/helpers.d.ts +15 -0
  135. package/node_modules/agent-base/dist/helpers.d.ts.map +1 -0
  136. package/node_modules/agent-base/dist/helpers.js +66 -0
  137. package/node_modules/agent-base/dist/helpers.js.map +1 -0
  138. package/node_modules/agent-base/dist/index.d.ts +41 -0
  139. package/node_modules/agent-base/dist/index.d.ts.map +1 -0
  140. package/node_modules/agent-base/dist/index.js +178 -0
  141. package/node_modules/agent-base/dist/index.js.map +1 -0
  142. package/node_modules/agent-base/package.json +46 -0
  143. package/node_modules/debug/LICENSE +20 -0
  144. package/node_modules/debug/README.md +481 -0
  145. package/node_modules/debug/package.json +64 -0
  146. package/node_modules/debug/src/browser.js +272 -0
  147. package/node_modules/debug/src/common.js +292 -0
  148. package/node_modules/debug/src/index.js +10 -0
  149. package/node_modules/debug/src/node.js +263 -0
  150. package/node_modules/http-proxy-agent/LICENSE +22 -0
  151. package/node_modules/http-proxy-agent/README.md +44 -0
  152. package/node_modules/http-proxy-agent/dist/index.d.ts +44 -0
  153. package/node_modules/http-proxy-agent/dist/index.d.ts.map +1 -0
  154. package/node_modules/http-proxy-agent/dist/index.js +148 -0
  155. package/node_modules/http-proxy-agent/dist/index.js.map +1 -0
  156. package/node_modules/http-proxy-agent/package.json +47 -0
  157. package/node_modules/https-proxy-agent/LICENSE +22 -0
  158. package/node_modules/https-proxy-agent/README.md +70 -0
  159. package/node_modules/https-proxy-agent/dist/index.d.ts +47 -0
  160. package/node_modules/https-proxy-agent/dist/index.d.ts.map +1 -0
  161. package/node_modules/https-proxy-agent/dist/index.js +180 -0
  162. package/node_modules/https-proxy-agent/dist/index.js.map +1 -0
  163. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts +15 -0
  164. package/node_modules/https-proxy-agent/dist/parse-proxy-response.d.ts.map +1 -0
  165. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js +101 -0
  166. package/node_modules/https-proxy-agent/dist/parse-proxy-response.js.map +1 -0
  167. package/node_modules/https-proxy-agent/package.json +50 -0
  168. package/node_modules/ms/index.js +162 -0
  169. package/node_modules/ms/license.md +21 -0
  170. package/node_modules/ms/package.json +38 -0
  171. package/node_modules/ms/readme.md +59 -0
  172. package/node_modules/node-forge/LICENSE +331 -0
  173. package/node_modules/node-forge/README.md +2071 -0
  174. package/node_modules/node-forge/dist/forge.all.min.js +2 -0
  175. package/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
  176. package/node_modules/node-forge/dist/forge.min.js +2 -0
  177. package/node_modules/node-forge/dist/forge.min.js.map +1 -0
  178. package/node_modules/node-forge/dist/prime.worker.min.js +2 -0
  179. package/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
  180. package/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
  181. package/node_modules/node-forge/lib/aes.js +1091 -0
  182. package/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
  183. package/node_modules/node-forge/lib/asn1-validator.js +91 -0
  184. package/node_modules/node-forge/lib/asn1.js +1503 -0
  185. package/node_modules/node-forge/lib/baseN.js +186 -0
  186. package/node_modules/node-forge/lib/cipher.js +230 -0
  187. package/node_modules/node-forge/lib/cipherModes.js +999 -0
  188. package/node_modules/node-forge/lib/des.js +496 -0
  189. package/node_modules/node-forge/lib/ed25519.js +1091 -0
  190. package/node_modules/node-forge/lib/forge.js +13 -0
  191. package/node_modules/node-forge/lib/form.js +149 -0
  192. package/node_modules/node-forge/lib/hmac.js +146 -0
  193. package/node_modules/node-forge/lib/http.js +1346 -0
  194. package/node_modules/node-forge/lib/index.all.js +16 -0
  195. package/node_modules/node-forge/lib/index.js +33 -0
  196. package/node_modules/node-forge/lib/jsbn.js +1294 -0
  197. package/node_modules/node-forge/lib/kem.js +168 -0
  198. package/node_modules/node-forge/lib/log.js +319 -0
  199. package/node_modules/node-forge/lib/md.all.js +13 -0
  200. package/node_modules/node-forge/lib/md.js +11 -0
  201. package/node_modules/node-forge/lib/md5.js +289 -0
  202. package/node_modules/node-forge/lib/mgf.js +12 -0
  203. package/node_modules/node-forge/lib/mgf1.js +57 -0
  204. package/node_modules/node-forge/lib/oids.js +180 -0
  205. package/node_modules/node-forge/lib/pbe.js +1023 -0
  206. package/node_modules/node-forge/lib/pbkdf2.js +211 -0
  207. package/node_modules/node-forge/lib/pem.js +237 -0
  208. package/node_modules/node-forge/lib/pkcs1.js +276 -0
  209. package/node_modules/node-forge/lib/pkcs12.js +1078 -0
  210. package/node_modules/node-forge/lib/pkcs7.js +1260 -0
  211. package/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
  212. package/node_modules/node-forge/lib/pki.js +102 -0
  213. package/node_modules/node-forge/lib/prime.js +297 -0
  214. package/node_modules/node-forge/lib/prime.worker.js +168 -0
  215. package/node_modules/node-forge/lib/prng.js +419 -0
  216. package/node_modules/node-forge/lib/pss.js +241 -0
  217. package/node_modules/node-forge/lib/random.js +191 -0
  218. package/node_modules/node-forge/lib/rc2.js +410 -0
  219. package/node_modules/node-forge/lib/rsa.js +1968 -0
  220. package/node_modules/node-forge/lib/sha1.js +319 -0
  221. package/node_modules/node-forge/lib/sha256.js +327 -0
  222. package/node_modules/node-forge/lib/sha512.js +561 -0
  223. package/node_modules/node-forge/lib/socket.js +287 -0
  224. package/node_modules/node-forge/lib/ssh.js +236 -0
  225. package/node_modules/node-forge/lib/tls.js +4282 -0
  226. package/node_modules/node-forge/lib/tlssocket.js +249 -0
  227. package/node_modules/node-forge/lib/util.js +2652 -0
  228. package/node_modules/node-forge/lib/x509.js +3251 -0
  229. package/node_modules/node-forge/lib/xhr.js +738 -0
  230. package/node_modules/node-forge/package.json +123 -0
  231. package/node_modules/smol-toml/LICENSE +24 -0
  232. package/node_modules/smol-toml/README.md +239 -0
  233. package/node_modules/smol-toml/dist/date.d.ts +41 -0
  234. package/node_modules/smol-toml/dist/date.js +127 -0
  235. package/node_modules/smol-toml/dist/error.d.ts +38 -0
  236. package/node_modules/smol-toml/dist/error.js +63 -0
  237. package/node_modules/smol-toml/dist/extract.d.ts +30 -0
  238. package/node_modules/smol-toml/dist/extract.js +100 -0
  239. package/node_modules/smol-toml/dist/index.cjs +897 -0
  240. package/node_modules/smol-toml/dist/index.d.ts +43 -0
  241. package/node_modules/smol-toml/dist/index.js +33 -0
  242. package/node_modules/smol-toml/dist/parse.d.ts +37 -0
  243. package/node_modules/smol-toml/dist/parse.js +148 -0
  244. package/node_modules/smol-toml/dist/primitive.d.ts +31 -0
  245. package/node_modules/smol-toml/dist/primitive.js +179 -0
  246. package/node_modules/smol-toml/dist/stringify.d.ts +31 -0
  247. package/node_modules/smol-toml/dist/stringify.js +167 -0
  248. package/node_modules/smol-toml/dist/struct.d.ts +32 -0
  249. package/node_modules/smol-toml/dist/struct.js +184 -0
  250. package/node_modules/smol-toml/dist/util.d.ts +42 -0
  251. package/node_modules/smol-toml/dist/util.js +111 -0
  252. package/node_modules/smol-toml/package.json +54 -0
  253. package/offline/bin/claude-trace +6 -0
  254. package/offline/bin/claude-wrapper +13 -0
  255. package/offline/bin/install-agent +14 -0
  256. package/offline/bin/validate-trace +6 -0
  257. package/offline/bin/verify-bundle +7 -0
  258. package/package.json +103 -0
package/README.md ADDED
@@ -0,0 +1,477 @@
1
+ # claude-trace
2
+
3
+ [English](README.md) | [简体中文](README.zh-CN.md)
4
+
5
+ Record API traffic from **Claude Code**, **OpenCode**, **Codex CLI**, and allowlisted LLM endpoints through a standalone forward proxy. Inspect everything the tools hide — system prompts, tool outputs, thinking blocks, and raw request/response data — in a self-contained HTML viewer.
6
+
7
+ **Fork of [mariozechner/claude-trace](https://github.com/badlogic/lemmy/tree/main/apps/claude-trace)**, extended with [Claude Code V2+](https://docs.anthropic.com/en/docs/claude-code) native-binary support, a dedicated **[OpenCode](https://opencode.ai)** CLI with multi-provider interception (Anthropic and OpenAI API formats), and **[Codex CLI](https://developers.openai.com/codex/cli) ChatGPT OAuth** tracing (login via ChatGPT account — the default Codex auth path for most users).
8
+
9
+ ## Proxy modes (forward & reverse)
10
+
11
+ This project supports **both**:
12
+
13
+ - **Reverse proxy (built-in tool wrappers)**: `claude-trace`, `opencode-trace`, `codex-trace` start a local reverse proxy and launch the target tool with its upstream base URL redirected to the proxy (so traffic is logged automatically).
14
+ - **Forward proxy (standalone)**: `vibe-coding-proxy` starts an HTTP/HTTPS forward proxy only. You must **export `HTTP_PROXY` / `HTTPS_PROXY` / `ALL_PROXY` before starting the client** you want to trace.
15
+
16
+ ## Supported tools
17
+
18
+ | Tool | CLI command | Log directory | Interception |
19
+ |------|-------------|---------------|--------------|
20
+ | **Claude Code** | `claude-trace` | `.claude-trace/` | V1: Node.js `fetch()` hook · V2+: reverse proxy via `ANTHROPIC_BASE_URL` |
21
+ | **OpenCode** | `opencode-trace` | `.opencode-trace/` | Reverse proxy + model routing; Anthropic & OpenAI API formats |
22
+ | **Codex CLI** | `codex-trace` | `.codex-trace/` | Reverse proxy via `CODEX_HOME` overlay; **ChatGPT OAuth** & OpenAI API Key (Responses API) |
23
+ | **Standalone proxy** | `vibe-coding-proxy` | `.vibe-coding-proxy/` | Forward proxy via `HTTP_PROXY` / `HTTPS_PROXY`; allowlist-scoped HTTPS MITM |
24
+
25
+ All commands share the same HTML report UI, JSONL/JSON export, and `--index` conversation summarization.
26
+
27
+ ## Quick start
28
+
29
+ ```bash
30
+ npm install -g @uvl000/claude-trace
31
+
32
+ # Claude Code
33
+ claude-trace
34
+
35
+ # OpenCode
36
+ opencode-trace
37
+
38
+ # Codex CLI
39
+ codex-trace
40
+
41
+ # Standalone forward proxy
42
+ vibe-coding-proxy --target-url https://api.deepseek.com/anthropic
43
+ ```
44
+
45
+ When a session ends, the latest HTML report opens in your browser automatically (disable with `--no-open`).
46
+
47
+ ## Install
48
+
49
+ ### From npm
50
+
51
+ ```bash
52
+ npm install -g @uvl000/claude-trace
53
+ ```
54
+
55
+ ### From source
56
+
57
+ ```bash
58
+ git clone https://github.com/hanqunfeng/claude-trace.git
59
+ cd claude-trace
60
+ npm run setup # installs root + frontend dependencies
61
+ npm run build
62
+ npm link # optional: global `claude-trace`, `opencode-trace`, `codex-trace`, and `vibe-coding-proxy`
63
+ # Without link: node dist/cli/cli.js / node dist/cli/opencode-cli.js / node dist/cli/codex-cli.js / node dist/cli/vibe-coding-proxy-cli.js
64
+ ```
65
+
66
+ ## Claude Code (`claude-trace`)
67
+
68
+ ### Usage
69
+
70
+ ```bash
71
+ # Start Claude Code with logging (auto-detects V1 JS vs V2+ native binary)
72
+ claude-trace
73
+
74
+ # Include all API requests (proxy mode defaults to /v1/messages only)
75
+ claude-trace --include-all-requests
76
+
77
+ # Log auth headers without redaction (use with care)
78
+ claude-trace --include-sensitive-headers
79
+
80
+ # Pass arguments to Claude
81
+ claude-trace --run-with chat --model sonnet-3.5
82
+
83
+ # Custom Claude binary path
84
+ claude-trace --claude-path /usr/local/Caskroom/claude-code/2.1.153/claude
85
+
86
+ # Extract OAuth token (V1 Node.js path)
87
+ claude-trace --extract-token
88
+
89
+ # Generate HTML from a previous .jsonl log
90
+ claude-trace --generate-html logs.jsonl report.html
91
+
92
+ # Generate conversation summaries and searchable index
93
+ claude-trace --index
94
+
95
+ claude-trace --help
96
+ ```
97
+
98
+ Logs: `.claude-trace/log-YYYY-MM-DD-HH-MM-SS.{jsonl,json,html}` in the current directory.
99
+
100
+ ### CLI options
101
+
102
+ | Flag | Description |
103
+ |------|-------------|
104
+ | `--include-all-requests` | Log all API traffic, not just `/v1/messages` |
105
+ | `--include-sensitive-headers` | Log auth tokens and cookies without redaction |
106
+ | `--log NAME` | Custom log file base name (without extension) |
107
+ | `--claude-path PATH` | Path to Claude binary (auto-detected if omitted) |
108
+ | `--no-open` | Don't open generated HTML in browser |
109
+ | `--run-with ARGS...` | Pass remaining arguments to Claude |
110
+ | `--extract-token` | Extract OAuth token and exit |
111
+ | `--generate-html FILE [OUT]` | Generate HTML report from JSONL |
112
+ | `--index` | Generate conversation summaries and index |
113
+
114
+ ### Claude Code V2+ (native binary)
115
+
116
+ Claude Code V2 ships as a **native binary** (Mach-O / ELF / PE), not a Node.js script. The original `node --require interceptor claude` approach no longer works.
117
+
118
+ | Claude Code version | Binary type | Interception mode |
119
+ |---------------------|-------------|-------------------|
120
+ | V1.x | Node.js script | `interceptor-loader.js` via `--require` |
121
+ | **V2+** | Native binary | Local reverse proxy; `ANTHROPIC_BASE_URL` redirected |
122
+
123
+ Flow:
124
+
125
+ 1. Start a local HTTP reverse proxy on `127.0.0.1`
126
+ 2. Point Claude Code at the proxy via `ANTHROPIC_BASE_URL`
127
+ 3. Forward traffic to the real upstream (`~/.claude/settings.json` or env)
128
+ 4. Log request/response pairs to `.claude-trace/` in real time
129
+
130
+ If `~/.claude/settings.json` already sets `ANTHROPIC_BASE_URL`, a persistent config overlay is used (`~/.claude-trace/claude-config-overlay/`): only `settings.json` is rewritten without that key; other entries are symlinked back to your real config when possible (directory **junctions** on Windows; files fall back to copy). **A failed link for one entry does not block startup** — the proxy still works. Skipped entries are logged only when `CLAUDE_TRACE_DEBUG=1`.
131
+
132
+ ### Third-party models (CC-Switch & custom endpoints)
133
+
134
+ Works with any setup that routes Claude Code through a custom `ANTHROPIC_BASE_URL` — [CC-Switch](https://github.com/farion1231/cc-switch), LiteLLM, corporate gateways, self-hosted proxies, etc.
135
+
136
+ ```
137
+ Claude Code → claude-trace proxy (logs) → CC-Switch / custom endpoint → model provider
138
+ ```
139
+
140
+ Example with CC-Switch:
141
+
142
+ ```bash
143
+ # CC-Switch writes ~/.claude/settings.json; then:
144
+ claude-trace
145
+ ```
146
+
147
+ Manual upstream:
148
+
149
+ ```bash
150
+ export ANTHROPIC_BASE_URL="https://your-gateway.example.com"
151
+ claude-trace
152
+ ```
153
+
154
+ Notes:
155
+
156
+ - Upstream must speak the **Anthropic Messages API** (`/v1/messages`), or use a gateway that translates to it
157
+ - API keys and other `env` entries from settings are preserved — only `ANTHROPIC_BASE_URL` is overridden locally
158
+ - HTML logs show the actual upstream URL and model name per request
159
+
160
+ ### Request filtering (Claude)
161
+
162
+ **Proxy mode (V2+):** default `/v1/messages`; `--include-all-requests` logs all proxied traffic.
163
+
164
+ **Interceptor mode (V1, Node.js):** default logs `/v1/messages` with more than 2 messages in context; `--include-all-requests` logs all `api.anthropic.com` requests.
165
+
166
+ ---
167
+
168
+ ## OpenCode (`opencode-trace`)
169
+
170
+ ### Usage
171
+
172
+ ```bash
173
+ # Start OpenCode TUI with logging
174
+ opencode-trace
175
+
176
+ # One-shot prompt
177
+ opencode-trace --run-with run "Explain async/await"
178
+
179
+ # Specific model
180
+ opencode-trace --run-with run -m my-deepseek/deepseek-v4-flash "Refactor this module"
181
+
182
+ # Generate HTML from a previous session
183
+ opencode-trace --generate-html .opencode-trace/log-2025-01-01-12-00-00.jsonl
184
+
185
+ # Conversation index
186
+ opencode-trace --index
187
+
188
+ opencode-trace --help
189
+ ```
190
+
191
+ Logs: `.opencode-trace/log-YYYY-MM-DD-HH-MM-SS.{jsonl,json,html}` in the current directory. Proxy runtime errors are appended to `.opencode-trace/proxy-errors.log`.
192
+
193
+ ### How interception works
194
+
195
+ OpenCode is a native binary. `opencode-trace` starts a local reverse proxy and injects a runtime config override via `OPENCODE_CONFIG_CONTENT` — **your original `opencode.json` is never modified**.
196
+
197
+ For every provider in your config, all `baseURL` values point at the local proxy. The proxy reads the `model` field from each request body, maps it to the correct provider and real upstream URL, then forwards the request. Supports **Anthropic** (`/v1/messages`) and **OpenAI** formats (`/v1/chat/completions`, `/v1/responses` via `@ai-sdk/openai-compatible` and `@ai-sdk/openai`).
198
+
199
+ ```
200
+ OpenCode → opencode-trace proxy (logs) → provider baseURL (DeepSeek, MiniMax, etc.)
201
+ ```
202
+
203
+ Config lookup order:
204
+
205
+ 1. `OPENCODE_CONFIG` environment variable
206
+ 2. `OPENCODE_CONFIG_DIR/opencode.json`
207
+ 3. `~/.config/opencode/opencode.json`
208
+ 4. `.opencode/opencode.json` in the current directory
209
+
210
+ ### Supported API formats
211
+
212
+ | OpenCode `npm` package | API format | Endpoints | Conversation view label |
213
+ |------------------------|------------|-----------|-------------------------|
214
+ | `@ai-sdk/anthropic` | Anthropic Messages | `/v1/messages` | Anthropic Messages |
215
+ | `@ai-sdk/openai-compatible` | OpenAI Chat Completions | `/v1/chat/completions` | OpenAI Chat |
216
+ | `@ai-sdk/openai` | OpenAI Responses | `/v1/responses` | OpenAI Responses |
217
+
218
+ The proxy reads `model` from each request body and routes to the matching provider `baseURL`. Per-model `npm` overrides are supported when a single provider mixes chat and responses APIs. Provider-level fallback (`providerId/*`) handles models not explicitly listed in `opencode.json`.
219
+
220
+ ### CLI options
221
+
222
+ | Flag | Description |
223
+ |------|-------------|
224
+ | `--opencode-path PATH` | Path to OpenCode binary (auto-detected if omitted) |
225
+ | `--include-all-requests` | Log all proxied API traffic, not just message endpoints |
226
+ | `--include-sensitive-headers` | Log auth tokens without redaction |
227
+ | `--log NAME` | Custom log file base name |
228
+ | `--no-open` | Don't open generated HTML in browser |
229
+ | `--run-with ARGS...` | Pass remaining arguments to OpenCode |
230
+
231
+ ### Debugging
232
+
233
+ By default, runtime logs are **silent** so they do not pollute OpenCode's TUI input area.
234
+
235
+ | Output | Default | With `OPENCODE_TRACE_DEBUG=1` |
236
+ |--------|---------|-------------------------------|
237
+ | Per-request routing (model → provider → upstream) | Hidden | Printed to stderr |
238
+ | Proxy errors (e.g. upstream TLS failure) | Written to `.opencode-trace/proxy-errors.log` | Also printed to stderr |
239
+
240
+ ```bash
241
+ OPENCODE_TRACE_DEBUG=1 opencode-trace
242
+ ```
243
+
244
+ Use this when a model is not routed correctly, requests are missing from the log, or upstream connections fail.
245
+
246
+ ### OpenCode limitations
247
+
248
+ - **Conversation view** supports Anthropic-format (`@ai-sdk/anthropic`) and OpenAI-format (`@ai-sdk/openai-compatible`, `@ai-sdk/openai`) providers; complex fields (multimodal, reasoning, etc.) may only appear fully in Raw/JSON views.
249
+ - Built-in `models.dev` providers not defined in your `opencode.json` are not intercepted yet.
250
+
251
+ ---
252
+
253
+ ## Codex CLI (`codex-trace`)
254
+
255
+ **Primary auth mode: ChatGPT OAuth.** If you use Codex signed in with your ChatGPT account (the default for most installs), `codex-trace` fully supports tracing that path — multi-turn conversations, zstd-compressed requests, and SSE streaming responses appear correctly in HTML reports.
256
+
257
+ ### Usage
258
+
259
+ ```bash
260
+ # Start Codex TUI with logging (ChatGPT OAuth or API Key)
261
+ codex-trace
262
+
263
+ # One-shot headless prompt
264
+ codex-trace --run-with exec "Explain async/await"
265
+
266
+ # Generate HTML from a previous session
267
+ codex-trace --generate-html .codex-trace/log-2025-01-01-12-00-00.jsonl
268
+
269
+ # Conversation index
270
+ codex-trace --index
271
+
272
+ codex-trace --help
273
+ ```
274
+
275
+ Logs: `.codex-trace/log-YYYY-MM-DD-HH-MM-SS.{jsonl,json,html}` in the current directory.
276
+
277
+ ### ChatGPT OAuth mode (recommended)
278
+
279
+ Most users run Codex with **ChatGPT login** (`codex login` or the TUI sign-in flow). `codex-trace` reads `~/.codex/auth.json` and, when `auth_mode` is `"chatgpt"`, routes all LLM traffic to the ChatGPT OAuth upstream (`chatgpt.com/backend-api/codex`) — **even if `OPENAI_BASE_URL` is set in your shell** for other tools (Cursor, LiteLLM, etc.).
280
+
281
+ | Check | Expected |
282
+ |-------|----------|
283
+ | Auth file | `~/.codex/auth.json` contains `"auth_mode": "chatgpt"` |
284
+ | Session data | Symlinked from your real `$CODEX_HOME`; OAuth tokens are not rewritten |
285
+ | HTML report | Multi-turn threads show each assistant reply, including the final turn |
286
+
287
+ ```
288
+ Codex CLI (ChatGPT OAuth) → codex-trace proxy (logs) → chatgpt.com/backend-api/codex
289
+ ```
290
+
291
+ **Tip:** Log in to Codex with ChatGPT *before* starting `codex-trace`. Switching auth inside Codex without restarting the trace session may require a fresh `codex-trace` run.
292
+
293
+ ### OpenAI API Key mode
294
+
295
+ If you use Codex with an **OpenAI API Key** instead of ChatGPT login, traffic is routed via `openai_base_url` / `OPENAI_BASE_URL` / `api.openai.com` (or your custom gateway). Do not mix ChatGPT OAuth tokens with a custom `OPENAI_BASE_URL` gateway — use one auth mode at a time.
296
+
297
+ ### How interception works
298
+
299
+ Codex CLI is a native Rust binary. `codex-trace` starts a local reverse proxy and builds a config overlay at `~/.claude-trace/codex-config-overlay/` — **your original `~/.codex/config.toml` is never modified**.
300
+
301
+ The overlay rewrites `openai_base_url`, `chatgpt_base_url`, and custom `model_providers.*.base_url` to point at the proxy. `auth.json` and session data are symlinked so ChatGPT OAuth continues to work. The proxy picks the upstream from **`auth.json` auth mode** (ChatGPT OAuth vs API Key) and request path:
302
+
303
+ - **ChatGPT OAuth** (`auth_mode: "chatgpt"`): `/responses`, `/v1/responses`, `/backend-api/codex/...` → `chatgpt.com`
304
+ - **ChatGPT Apps MCP** (`codex_apps`): `/api/codex/apps` → `chatgpt.com/backend-api/wham/apps`; `/backend-api/wham/...` → `chatgpt.com` (site origin)
305
+ - **OpenAI API Key**: `/v1/responses`, `/responses` → `openai_base_url` / `OPENAI_BASE_URL` / default OpenAI host
306
+ - **Custom `model_providers`**: non-reserved provider IDs with explicit `base_url`
307
+
308
+ ```
309
+ Codex CLI → codex-trace proxy (logs) → chatgpt.com (OAuth) / api.openai.com / custom provider
310
+ ```
311
+
312
+ Config lookup: `CODEX_HOME` (overlay) or `~/.codex/config.toml`.
313
+
314
+ ### CLI options
315
+
316
+ | Flag | Description |
317
+ |------|-------------|
318
+ | `--codex-path PATH` | Path to Codex binary (auto-detected if omitted) |
319
+ | `--include-all-requests` | Log all proxied API traffic, not just LLM API paths |
320
+ | `--include-sensitive-headers` | Log auth tokens without redaction |
321
+ | `--log NAME` | Custom log file base name |
322
+ | `--no-open` | Don't open generated HTML in browser |
323
+ | `--run-with ARGS...` | Pass remaining arguments to Codex |
324
+
325
+ ### Codex limitations
326
+
327
+ - WebSocket Responses transport is disabled in the overlay (`supports_websockets = false`) so HTTP/SSE traffic can be logged.
328
+ - Built-in provider IDs (`openai`, `ollama`, `lmstudio`) cannot be overridden via `model_providers`; ChatGPT OAuth uses `chatgpt_base_url`, API Key mode uses `openai_base_url`.
329
+ - **Ollama / LM Studio** built-in providers are not intercepted (traffic bypasses the proxy).
330
+ - Older `auth.json` files without `auth_mode` fall back to legacy heuristics; re-login with ChatGPT if OAuth routing misbehaves.
331
+ - **Node.js:** Codex ChatGPT OAuth tracing works on **Node.js 16+** (the proxy forwards zstd request bodies unchanged). **Node.js 22+** is recommended so zstd-compressed request bodies are decompressed in logs and HTML; on Node 16–21, request entries show a placeholder instead of parsed JSON (responses and proxy behavior are unaffected).
332
+
333
+ ---
334
+
335
+ ## Standalone forward proxy (`vibe-coding-proxy`)
336
+
337
+ `vibe-coding-proxy` starts only the proxy service. It does not spawn Claude Code, OpenCode, Codex, or any other client. Point any compatible CLI at the printed proxy URL with `HTTP_PROXY`, `HTTPS_PROXY`, or `ALL_PROXY`.
338
+
339
+ ### Compatibility & usage order
340
+
341
+ - **Tested clients**: Claude Code, OpenCode, Codex CLI. Other clients may work if they respect standard proxy env vars, but are not tested yet.
342
+ - **Order matters**: start `vibe-coding-proxy` → export env vars in the same shell/session → then start your client/tool. If you start the client first, it may not pick up the proxy settings.
343
+
344
+ ### Usage
345
+
346
+ ```bash
347
+ # Log a specific DeepSeek Anthropic-compatible endpoint
348
+ vibe-coding-proxy --target-url https://api.deepseek.com/anthropic
349
+
350
+ # Log every HTTPS request on a host
351
+ vibe-coding-proxy --mitm-host api.deepseek.com
352
+
353
+ # Use a fixed local port
354
+ vibe-coding-proxy --target-url https://api.deepseek.com --port 8888
355
+
356
+ # Generate HTML from a previous .jsonl log
357
+ vibe-coding-proxy --generate-html .vibe-coding-proxy/log-2025-01-01-12-00-00.jsonl
358
+ ```
359
+
360
+ After startup, export the printed proxy URL:
361
+
362
+ ```bash
363
+ export HTTP_PROXY=http://127.0.0.1:PORT
364
+ export HTTPS_PROXY=http://127.0.0.1:PORT
365
+ export ALL_PROXY=http://127.0.0.1:PORT
366
+ export NODE_TLS_REJECT_UNAUTHORIZED=0
367
+ export SSL_CERT_FILE=CA_CERT_PATH
368
+ ```
369
+
370
+ Logs: `.vibe-coding-proxy/log-YYYY-MM-DD-HH-MM-SS.{jsonl,json,html}` in the current directory.
371
+
372
+ ### HTTPS logging and CA trust
373
+
374
+ HTTPS requests sent through `HTTPS_PROXY` normally use `CONNECT host:443`, which hides JSON bodies from the proxy. To log request/response bodies, `vibe-coding-proxy` performs MITM only for `--target-url` / `--mitm-host` allowlist entries and prints a local CA certificate path.
375
+
376
+ Trust that CA only in clients whose model traffic you want to inspect. The command never installs the CA into your system trust store automatically. `NODE_TLS_REJECT_UNAUTHORIZED=0` only helps Node.js clients; Codex ChatGPT OAuth is a Rust client and may require `SSL_CERT_FILE` or OS-level trust for the printed CA. Non-allowlisted HTTPS traffic is passed through as a raw CONNECT tunnel and only logged as metadata when `--include-all-requests` is enabled.
377
+
378
+ ### Local CA lifecycle
379
+
380
+ The local CA is reused across proxy runs from `~/.claude-trace/vibe-coding-proxy-ca/` unless you pass `--ca-dir`. `ca.crt` is valid for 10 years; per-host leaf certificates such as `api.deepseek.com.crt.pem` are valid for 1 year. Expired leaf certificates are reissued automatically. If the CA expires, it is regenerated and all cached leaf certificates are removed; you must trust the new CA again.
381
+
382
+
383
+ ### CLI options
384
+
385
+ | Flag | Description |
386
+ |------|-------------|
387
+ | `--target-url URL` | URL prefix to decrypt and fully log (repeatable) |
388
+ | `--mitm-host HOST` | Hostname to decrypt and fully log (repeatable) |
389
+ | `--host HOST` | Listen host (default `127.0.0.1`) |
390
+ | `--port PORT` | Listen port (default `0`, random) |
391
+ | `--log-dir DIR` | Log directory (default `.vibe-coding-proxy`) |
392
+ | `--log NAME` | Custom log file base name |
393
+ | `--ca-dir DIR` | Local CA and leaf certificate cache directory |
394
+ | `--no-mitm` | Disable TLS MITM; HTTPS CONNECT is pass-through only |
395
+ | `--include-all-requests` | Log pass-through CONNECT metadata and non-target HTTP traffic |
396
+ | `--include-sensitive-headers` | Log auth headers without redaction |
397
+ | `--no-open` | Don't open generated HTML on exit |
398
+ | `--generate-html FILE [OUT]` | Generate HTML report from JSONL |
399
+
400
+ ---
401
+
402
+ ## Shared features
403
+
404
+ ### HTML report
405
+
406
+ Each session produces a self-contained HTML file (embedded CSS/JS) you can open offline. On exit, the browser opens automatically unless you pass `--no-open`.
407
+
408
+ ### What you'll see
409
+
410
+ - **System prompts** — hidden instructions sent to the model
411
+ - **Tool definitions & outputs** — parameters and raw tool results
412
+ - **Thinking blocks** — internal reasoning (when present)
413
+ - **Token usage** — detailed breakdown including cache hits
414
+ - **Raw JSONL logs** — complete request/response pairs
415
+ - **Interactive viewer** — conversation, raw HTTP, and JSON debug tabs
416
+ - **API format label** — each conversation shows its request format (e.g. `8 messages · OpenAI Chat`) in the session header
417
+
418
+ ### Conversation index
419
+
420
+ ```bash
421
+ claude-trace --index
422
+ # or
423
+ opencode-trace --index
424
+ # or
425
+ codex-trace --index
426
+ ```
427
+
428
+ Scans log files, summarizes meaningful conversations via Claude CLI, and generates a searchable `index.html`. **Note:** indexing uses additional API tokens.
429
+
430
+ ## Requirements
431
+
432
+ - Node.js 16+ (Node.js 22+ recommended for full Codex OAuth request-body display in logs)
433
+ - **Claude Code** CLI (V1 Node.js or V2+ native binary) for `claude-trace`
434
+ - **OpenCode** CLI for `opencode-trace`
435
+ - **Codex CLI** for `codex-trace`
436
+
437
+ ## Development
438
+
439
+ ```bash
440
+ npm run setup # first time
441
+ npm run dev # watch mode; preview at http://localhost:8080/test
442
+ npm run build
443
+ npm run typecheck
444
+ npm run test:unit
445
+ ```
446
+
447
+ ### Architecture
448
+
449
+ **Backend** (`src/`):
450
+
451
+ - **CLI** (`cli/cli.ts`, `cli/opencode-cli.ts`, `cli/codex-cli.ts`, `cli/cli-common.ts`) — thin entry points and shared arg parsing
452
+ - **Trace Runner** (`cli/trace-runner.ts`) — shared launch + proxy/interceptor dispatch
453
+ - **Tool Profiles** (`tools/claude.ts`, `tools/opencode.ts`, `tools/codex.ts`, `tools/binary-utils.ts`) — per-tool config, binary detection, upstream resolution
454
+ - **Config Overlays** (`config/claude-config-overlay.ts`, `config/codex-config-overlay.ts`) — persistent proxy overlays without modifying user config
455
+ - **Reverse Proxy** (`intercept/reverse-proxy.ts`) — native-binary interception, real-time HTML generation
456
+ - **Interceptor** (`intercept/interceptor.ts`) + **Loader** (`intercept/interceptor-loader.js`, `intercept/token-extractor.js`) — Claude Code V1
457
+ - **Routing** (`routing/proxy-routing.ts`, `routing/codex-routing.ts`) — OpenCode model routes and Codex path/auth upstream selection
458
+ - **API Format** (`adapt/api-format.ts`) — format detection and display labels
459
+ - **OpenAI Adapter** (`adapt/openai-adapter.ts`) — OpenAI request/response → Anthropic `Message` for the viewer
460
+ - **Report** (`report/html-generator.ts`, `report/index-generator.ts`, `report/shared-conversation-processor.ts`) — HTML generation and shared conversation parsing
461
+
462
+ **Frontend** (`frontend/src/`): Lit + Tailwind interactive viewer embedded into HTML reports.
463
+
464
+ ## Documentation
465
+
466
+ Maintainer and contributor docs live under [`doc/`](doc/):
467
+
468
+ | Document | Description |
469
+ |----------|-------------|
470
+ | [doc/publishing/oidc.md](doc/publishing/oidc.md) | Recommended npm release via GitHub Actions OIDC |
471
+ | [doc/publishing/access-token.md](doc/publishing/access-token.md) | Legacy local release with npm Access Token |
472
+ | [doc/github-actions-workflow-guide.md](doc/github-actions-workflow-guide.md) | GitHub Actions workflow reference and examples |
473
+ | [doc/npm-v12-security-changelog.md](doc/npm-v12-security-changelog.md) | npm v12 install-time security and GAT deprecation notes |
474
+
475
+ ## License
476
+
477
+ MIT — originally by [Mario Zechner](https://github.com/badlogic/lemmy/tree/main/apps/claude-trace), based on [@hanqunfeng/claude-trace](https://github.com/hanqunfeng/claude-trace), and packaged for WorkflowExp as `@uvl000/claude-trace`.