cc-viewer 1.2.5 → 1.2.8

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # CC-Viewer
2
2
 
3
- A request monitoring system for Claude Code that captures and visualizes all API requests and responses in real time. Helps developers monitor their Context for reviewing and debugging during Vibe Coding.
3
+ A Claude Code request monitoring system that captures and visualizes all API requests and responses from Claude Code in real time (raw text, unredacted). Helps developers monitor their context for review and troubleshooting during Vibe Coding sessions.
4
4
 
5
- [简体中文](./docs/README.zh.md) | [繁體中文](./docs/README.zh-TW.md) | [한국어](./docs/README.ko.md) | [日本語](./docs/README.ja.md) | [Deutsch](./docs/README.de.md) | [Español](./docs/README.es.md) | [Français](./docs/README.fr.md) | [Italiano](./docs/README.it.md) | [Dansk](./docs/README.da.md) | [Polski](./docs/README.pl.md) | [Русский](./docs/README.ru.md) | [العربية](./docs/README.ar.md) | [Norsk](./docs/README.no.md) | [Português (Brasil)](./docs/README.pt-BR.md) | [ไทย](./docs/README.th.md) | [Türkçe](./docs/README.tr.md) | [Українська](./docs/README.uk.md)
5
+ English | [简体中文](./docs/README.zh.md) | [繁體中文](./docs/README.zh-TW.md) | [한국어](./docs/README.ko.md) | [日本語](./docs/README.ja.md) | [Deutsch](./docs/README.de.md) | [Español](./docs/README.es.md) | [Français](./docs/README.fr.md) | [Italiano](./docs/README.it.md) | [Dansk](./docs/README.da.md) | [Polski](./docs/README.pl.md) | [Русский](./docs/README.ru.md) | [العربية](./docs/README.ar.md) | [Norsk](./docs/README.no.md) | [Português (Brasil)](./docs/README.pt-BR.md) | [ไทย](./docs/README.th.md) | [Türkçe](./docs/README.tr.md) | [Українська](./docs/README.uk.md)
6
6
 
7
7
  ## Usage
8
8
 
@@ -12,32 +12,40 @@ A request monitoring system for Claude Code that captures and visualizes all API
12
12
  npm install -g cc-viewer
13
13
  ```
14
14
 
15
- ### Run & Auto-Configuration
15
+ ### Running and Auto-Configuration
16
16
 
17
17
  ```bash
18
18
  ccv
19
19
  ```
20
20
 
21
- This command automatically detects your Claude Code installation method (NPM or Native Install) and configures itself.
21
+ This command automatically detects how Claude Code is installed locally (NPM or Native Install) and adapts accordingly.
22
22
 
23
- - **NPM Install**: Injects interceptor script into `cli.js` of Claude Code.
24
- - **Native Install**: Detects `claude` binary, sets up a local transparent proxy, and configures a Zsh Shell Hook to route traffic through the proxy automatically.
23
+ - **NPM Install**: Automatically injects an interceptor script into Claude Code's `cli.js`.
24
+ - **Native Install**: Automatically detects the `claude` binary, configures a local transparent proxy, and sets up a Zsh Shell Hook to forward traffic automatically.
25
25
 
26
26
  ### Configuration Override
27
27
 
28
- If you need to use a custom API endpoint (e.g., corporate proxy), simply configure it in `~/.claude/settings.json` or set `ANTHROPIC_BASE_URL` environment variable. `ccv` will respect these settings and forward requests correctly.
28
+ If you need to use a custom API endpoint (e.g., a corporate proxy), simply configure it in `~/.claude/settings.json` or set the `ANTHROPIC_BASE_URL` environment variable. `ccv` will automatically detect and correctly forward requests.
29
29
 
30
30
  ### Silent Mode
31
31
 
32
- By default, `ccv` runs in silent mode when wrapping `claude`, ensuring your terminal output remains clean and identical to the original Claude Code experience. All logs are captured in the background and visible at `http://localhost:7008`.
32
+ By default, `ccv` runs in silent mode when wrapping `claude`, keeping your terminal output clean and consistent with the native experience. All logs are captured in the background and can be viewed at `http://localhost:7008`.
33
33
 
34
- Once configured, use `claude` as usual. Open `http://localhost:7008` to view the monitoring interface.
34
+ Once configured, use the `claude` command as normal. Visit `http://localhost:7008` to access the monitoring interface.
35
35
 
36
36
  ### Troubleshooting
37
37
 
38
- - **Mixed Output**: If you see `[CC-Viewer]` debug logs mixed with Claude's output, please update to the latest version (`npm install -g cc-viewer`).
39
- - **Connection Refused**: Ensure `ccv` background process is running. Running `ccv` or `claude` (after hook installation) should start it automatically.
40
- - **Empty Body**: If you see "No Body" in the viewer, it might be due to non-standard SSE formats. The viewer now attempts to capture raw content as a fallback.
38
+ If you encounter issues starting cc-viewer, here is the ultimate troubleshooting approach:
39
+
40
+ Step 1: Open Claude Code in any directory.
41
+
42
+ Step 2: Give Claude Code the following instruction:
43
+ ```
44
+ I have installed the cc-viewer npm package but cannot get it to start. Please check cc-viewer's cli.js and findcc.js, and adapt them to the local Claude Code deployment based on the specifics. Keep the scope of changes as constrained as possible within findcc.js.
45
+ ```
46
+ Letting Claude Code diagnose the issue itself is more effective than asking anyone or reading any documentation!
47
+
48
+ After the above instruction is completed, `findcc.js` will be updated. If your project frequently requires local deployment, or if forked code often needs to resolve installation issues, keeping this file lets you simply copy it next time. At this stage, many projects and companies using Claude Code are not deploying on Mac but rather on server-side hosted environments, so the author has separated `findcc.js` to make it easier to track cc-viewer source code updates going forward.
41
49
 
42
50
  ### Uninstall
43
51
 
@@ -54,77 +62,49 @@ ccv --version
54
62
  ## Features
55
63
 
56
64
  ### Request Monitoring (Raw Mode)
57
-
58
- - Real-time capture of all API requests from Claude Code, including streaming responses
59
- - Left panel shows request method, URL, duration, and status code
60
- - Automatically identifies and labels Main Agent and Sub Agent requests (with sub-types: Bash, Task, Plan, General)
61
- - Request list auto-scrolls to the selected item (centered on mode switch, nearest on manual click)
62
- - Right panel supports Request / Response tab switching
63
- - Request Body expands `messages`, `system`, `tools` one level by default
64
- - Response Body fully expanded by default
65
- - Toggle between JSON view and plain text view
66
- - One-click JSON content copy
67
- - MainAgent requests support Body Diff JSON, showing a collapsible diff with the previous MainAgent request (only changed/added fields)
68
- - Diff section supports JSON/Text view switching and one-click copy
69
- - "Expand Diff" setting: when enabled, MainAgent requests auto-expand the diff section
70
- - Body Diff JSON tooltip is dismissible; once closed, the preference is persisted server-side and never shown again
71
- - Sensitive headers (`x-api-key`, `authorization`) are automatically masked in JSONL log files to prevent credential leakage
65
+ <img width="1500" height="720" alt="image" src="https://github.com/user-attachments/assets/519dd496-68bd-4e76-84d7-2a3d14ae3f61" />
66
+ - Captures all API requests made by Claude Code in real time, ensuring raw content rather than truncated logs (this is important!!!)
67
+ - Automatically identifies and labels Main Agent and Sub Agent requests (subtypes: Bash, Task, Plan, General)
68
+ - MainAgent requests support Body Diff JSON, showing a collapsed diff of changes from the previous MainAgent request (only changed/added fields)
72
69
  - Inline token usage stats per request (input/output tokens, cache creation/read, hit rate)
73
- - Compatible with Claude Code Router (CCR) and other proxy setupsrequests are matched by API path pattern as a fallback
74
-
75
- ### Chat Mode
76
-
77
- Click the "Chat mode" button in the top right to parse Main Agent's full conversation history into a chat interface:
78
-
79
- - User messages right-aligned (blue bubbles), Main Agent replies left-aligned (dark bubbles) with Markdown rendering
80
- - `/compact` messages auto-detected and displayed collapsed, click to expand full summary
81
- - Tool call results displayed inline within the corresponding Assistant message
82
- - `thinking` blocks collapsed by default, rendered as Markdown, click to expand; supports one-click translation
83
- - `tool_use` shown as compact tool call cards (Bash, Read, Edit, Write, Glob, Grep, Task each have dedicated displays)
84
- - Task (SubAgent) tool results rendered as Markdown
85
- - User selection messages (AskUserQuestion) shown in Q&A format
86
- - System tags (`<system-reminder>`, `<project-reminder>`, etc.) auto-collapsed
87
- - Skill loaded messages auto-detected and collapsed, showing skill name; click to expand full documentation with Markdown rendering
88
- - Skills reminder auto-detected and collapsed
89
- - System text auto-filtered, showing only real user input
90
- - Multi-session segmented display (auto-segmented after `/compact`, `/clear`, etc.)
91
- - Each message shows a timestamp accurate to the second, derived from API request timing
92
- - Each message has a "View Request" link to jump back to raw mode at the corresponding API request
93
- - Bidirectional mode sync: switching to chat mode scrolls to the conversation matching the selected request; switching back scrolls to the selected request
94
- - Settings panel: toggle default collapse state for tool results and thinking blocks
95
- - Global settings: toggle filtering of irrelevant requests (count_tokens, heartbeat) from the request list
96
-
97
- ### Translation
98
-
99
- - Thinking blocks and assistant messages support one-click translation
100
- - Powered by Claude Haiku API, uses `x-api-key` authentication only (OAuth session tokens are excluded to prevent context pollution)
101
- - Automatically captures haiku model name from mainAgent requests; defaults to `claude-haiku-4-5-20251001`
102
- - Translation results are cached; click again to toggle back to the original text
103
- - Loading spinner animation shown during translation
104
- - (?) help icon on `authorization` header links to concept doc explaining context pollution
105
-
106
- ### Token Stats
107
-
108
- Hover panel in the header area:
109
-
110
- - Token counts grouped by model (input/output)
111
- - Cache creation/read counts and cache hit rate
112
- - Cache rebuild statistics: grouped by reason (TTL, system/tools/model change, message truncation/modification, key change) with count and cache_creation tokens
113
- - Tool usage statistics: call counts per tool, sorted by frequency
114
- - Skill usage statistics: call counts per skill, sorted by frequency
115
- - Concept help (?) icons: click to view built-in documentation for MainAgent, CacheRebuild, and each tool
116
- - Main Agent cache expiration countdown
70
+ - Compatible with Claude Code Router (CCR) and other proxy scenariosfalls back to API path pattern matching
71
+
72
+ ### Conversation Mode
73
+
74
+ Click the "Conversation Mode" button in the top-right corner to parse the Main Agent's full conversation history into a chat interface:
75
+ <img width="1500" height="730" alt="image" src="https://github.com/user-attachments/assets/c973f142-748b-403f-b2b7-31a5d81e33e6" />
76
+
77
+
78
+ - Agent Team display is not yet supported
79
+ - User messages are right-aligned (blue bubbles), Main Agent replies are left-aligned (dark bubbles)
80
+ - `thinking` blocks are collapsed by default, rendered in Markdown, and can be expanded to view the reasoning process; one-click translation is supported (feature is still unstable)
81
+ - User selection messages (AskUserQuestion) are displayed in a Q&A format
82
+ - Bidirectional mode sync: switching to Conversation Mode automatically navigates to the conversation corresponding to the selected request; switching back to Raw Mode automatically navigates to the selected request
83
+ - Settings panel: toggle the default collapsed state of tool results and thinking blocks
84
+
85
+
86
+ ### Statistics Tool
87
+
88
+ The "Data Statistics" floating panel in the header area:
89
+ <img width="1500" height="729" alt="image" src="https://github.com/user-attachments/assets/b23f9a81-fc3d-4937-9700-e70d84e4e5ce" />
90
+
91
+ - Displays cache creation/read counts and cache hit rate
92
+ - Cache rebuild statistics: grouped by reason (TTL, system/tools/model changes, message truncation/modification, key changes) showing counts and cache_creation tokens
93
+ - Tool usage statistics: displays call frequency for each tool sorted by number of calls
94
+ - Skill usage statistics: displays call frequency for each skill sorted by number of calls
95
+ - Concept help (?) icon: click to view built-in documentation for MainAgent, CacheRebuild, and each tool
117
96
 
118
97
  ### Log Management
119
98
 
120
- Via the CC-Viewer dropdown menu in the top left:
99
+ Via the CC-Viewer dropdown menu in the top-left corner:
100
+ <img width="1200" height="672" alt="image" src="https://github.com/user-attachments/assets/8cf24f5b-9450-4790-b781-0cd074cd3b39" />
121
101
 
122
- - Import local logs: browse historical log files, grouped by project, opens in new window
123
- - Load local JSONL file: directly select and load a local `.jsonl` file (up to 500MB)
124
- - Download current log: download the current monitoring JSONL log file
102
+ - Import local logs: browse historical log files grouped by project, open in a new window
103
+ - Load local JSONL file: directly select a local `.jsonl` file to load and view (supports up to 500MB)
104
+ - Save current log as: download the current monitoring JSONL log file
125
105
  - Merge logs: combine multiple JSONL log files into a single session for unified analysis
126
- - Export user prompts: extract and display all user inputs with three view modes — Original (raw content), Context (with system tags collapsible), and Text (plain text only); slash commands (`/model`, `/context`, etc.) shown as standalone entries; command-related tags auto-hidden from prompt content
127
- - Export prompts to TXT: export user prompts (text only, excluding system tags) to a local `.txt` file
106
+ - View user Prompts: extract and display all user inputs, supporting three view modes — Raw mode (original content), Context mode (system tags collapsible), Text mode (plain text); slash commands (`/model`, `/context`, etc.) shown as standalone entries; command-related tags are auto-hidden from Prompt content
107
+ - Export Prompts to TXT: export user Prompts (plain text, excluding system tags) to a local `.txt` file
128
108
 
129
109
  ### Multi-language Support
130
110
 
package/cli.js CHANGED
@@ -1,58 +1,24 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { readFileSync, writeFileSync, existsSync } from 'node:fs';
4
- import { resolve, join } from 'node:path';
4
+ import { resolve } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import { homedir } from 'node:os';
7
- import { spawn, execSync } from 'node:child_process';
7
+ import { spawn } from 'node:child_process';
8
8
  import { t } from './i18n.js';
9
+ import { INJECT_IMPORT, resolveCliPath, resolveNativePath, buildShellCandidates } from './findcc.js';
9
10
 
10
11
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
11
12
 
12
13
  const INJECT_START = '// >>> Start CC Viewer Web Service >>>';
13
14
  const INJECT_END = '// <<< Start CC Viewer Web Service <<<';
14
- const INJECT_IMPORT = "import '../../cc-viewer/interceptor.js';";
15
15
  const INJECT_BLOCK = `${INJECT_START}\n${INJECT_IMPORT}\n${INJECT_END}`;
16
16
 
17
17
 
18
18
  const SHELL_HOOK_START = '# >>> CC-Viewer Auto-Inject >>>';
19
19
  const SHELL_HOOK_END = '# <<< CC-Viewer Auto-Inject <<<';
20
20
 
21
- // Claude Code cli.js 包名候选列表,按优先级排列
22
- const CLAUDE_CODE_PACKAGES = [
23
- '@anthropic-ai/claude-code',
24
- '@ali/claude-code',
25
- ];
26
-
27
- function getGlobalNodeModulesDir() {
28
- try {
29
- return execSync('npm root -g', { encoding: 'utf-8' }).trim();
30
- } catch {
31
- return null;
32
- }
33
- }
34
-
35
- function resolveClaudeCodeCliPath() {
36
- // 候选基础目录:__dirname 的上级(适用于常规 npm 安装)+ 全局 node_modules(适用于符号链接安装)
37
- const baseDirs = [resolve(__dirname, '..')];
38
- const globalRoot = getGlobalNodeModulesDir();
39
- if (globalRoot && globalRoot !== resolve(__dirname, '..')) {
40
- baseDirs.push(globalRoot);
41
- }
42
-
43
- for (const baseDir of baseDirs) {
44
- for (const packageName of CLAUDE_CODE_PACKAGES) {
45
- const candidate = join(baseDir, packageName, 'cli.js');
46
- if (existsSync(candidate)) {
47
- return candidate;
48
- }
49
- }
50
- }
51
- // 兜底:返回全局目录下的默认路径,便于错误提示
52
- return join(globalRoot || resolve(__dirname, '..'), CLAUDE_CODE_PACKAGES[0], 'cli.js');
53
- }
54
-
55
- const cliPath = resolveClaudeCodeCliPath();
21
+ const cliPath = resolveCliPath();
56
22
 
57
23
  function getShellConfigPath() {
58
24
  const shell = process.env.SHELL || '';
@@ -80,10 +46,11 @@ claude() {
80
46
  ${SHELL_HOOK_END}`;
81
47
  }
82
48
 
49
+ const candidates = buildShellCandidates();
83
50
  return `${SHELL_HOOK_START}
84
51
  claude() {
85
52
  local cli_js=""
86
- for candidate in "$HOME/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js" "$HOME/.npm-global/lib/node_modules/@ali/claude-code/cli.js"; do
53
+ for candidate in ${candidates}; do
87
54
  if [ -f "$candidate" ]; then
88
55
  cli_js="$candidate"
89
56
  break
@@ -161,37 +128,6 @@ function removeCliJsInjection() {
161
128
  }
162
129
  }
163
130
 
164
- function getNativeInstallPath() {
165
- // 1. 尝试 which/command -v(继承当前 process.env PATH)
166
- for (const cmd of ['which claude', 'command -v claude']) {
167
- try {
168
- const result = execSync(cmd, { encoding: 'utf-8', shell: true, env: process.env }).trim();
169
- // 排除 shell function 的输出(多行说明不是路径)
170
- if (result && !result.includes('\n') && existsSync(result)) {
171
- return result;
172
- }
173
- } catch {
174
- // ignore
175
- }
176
- }
177
-
178
- // 2. 检查常见 native 安装路径
179
- const home = homedir();
180
- const candidates = [
181
- join(home, '.claude', 'local', 'claude'),
182
- '/usr/local/bin/claude',
183
- join(home, '.local', 'bin', 'claude'),
184
- '/opt/homebrew/bin/claude',
185
- ];
186
- for (const p of candidates) {
187
- if (existsSync(p)) {
188
- return p;
189
- }
190
- }
191
-
192
- return null;
193
- }
194
-
195
131
  async function runProxyCommand(args) {
196
132
  try {
197
133
  // Dynamic import to avoid side effects when just installing
@@ -229,49 +165,24 @@ async function runProxyCommand(args) {
229
165
  }
230
166
 
231
167
  const env = { ...process.env };
232
- // [Debug] Verify hook execution
233
- // console.error(`[CC-Viewer] Hook triggered for: ${cmd} ${cmdArgs.join(' ')}`);
234
-
235
168
  // Determine the path to the native 'claude' executable
236
169
  if (cmd === 'claude') {
237
- const nativePath = getNativeInstallPath();
170
+ const nativePath = resolveNativePath();
238
171
  if (nativePath) {
239
172
  cmd = nativePath;
240
173
  }
241
174
  }
242
175
  env.ANTHROPIC_BASE_URL = `http://127.0.0.1:${proxyPort}`;
243
176
 
244
- // [Debug] Force ANTHROPIC_BASE_URL via process.env is not enough for some reason?
245
- // Let's also check if we can pass it via command line args if supported, but claude cli doesn't seem to have a --base-url arg documented.
246
- // However, maybe the issue is that 'env' in spawn options isn't overriding what claude internal config has?
247
- // Claude Code likely reads from ~/.claude/settings.json which might take precedence over env vars?
248
- // No, usually env vars take precedence.
249
-
250
- // [Fix] Check if user has ANTHROPIC_BASE_URL in settings.json and use it in proxy.js
251
- // We already do that in proxy.js: getOriginalBaseUrl().
252
-
253
- // [Crucial Fix]
254
- // Use --settings JSON argument to force ANTHROPIC_BASE_URL configuration
255
- // This is safer and more reliable than env vars which might be ignored.
256
-
257
- // console.error(`[CC-Viewer] Setting ANTHROPIC_BASE_URL to ${env.ANTHROPIC_BASE_URL}`);
258
-
259
- // Construct settings JSON string
260
- // Note: We need to be careful with quoting for the shell/spawn.
261
- // Since we use spawn without shell, we can pass the JSON string directly as an argument.
262
177
  const settingsJson = JSON.stringify({
263
178
  env: {
264
179
  ANTHROPIC_BASE_URL: env.ANTHROPIC_BASE_URL
265
180
  }
266
181
  });
267
182
 
268
- // Inject --settings argument
269
- // We put it at the beginning of args to ensure it's picked up
270
183
  cmdArgs.unshift(settingsJson);
271
184
  cmdArgs.unshift('--settings');
272
185
 
273
- // Force non-interactive if needed? No, we want interactive.
274
-
275
186
  const child = spawn(cmd, cmdArgs, { stdio: 'inherit', env });
276
187
 
277
188
  child.on('exit', (code) => {
@@ -292,8 +203,14 @@ async function runProxyCommand(args) {
292
203
 
293
204
  const args = process.argv.slice(2);
294
205
  const isUninstall = args.includes('--uninstall');
206
+ const isHelp = args.includes('--help') || args.includes('-h') || args[0] === 'help';
295
207
  const isVersion = args.includes('--v') || args.includes('--version') || args.includes('-v');
296
208
 
209
+ if (isHelp) {
210
+ console.log(t('cli.help'));
211
+ process.exit(0);
212
+ }
213
+
297
214
  if (isVersion) {
298
215
  try {
299
216
  const pkg = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
@@ -335,7 +252,7 @@ if (args[0] === 'run') {
335
252
  if (existsSync(cliPath)) {
336
253
  mode = 'npm';
337
254
  } else {
338
- const nativePath = getNativeInstallPath();
255
+ const nativePath = resolveNativePath();
339
256
  if (nativePath) {
340
257
  mode = 'native';
341
258
  }