cclens-trace-analyzer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCCLens Trace Analyzer
CCLens Trace Analyzer
cclens tracelist → show → export → Read markdowncclens tracelist → show → export → Read markdown前置检查
Pre-check
执行任何 trace 命令前,先确认 是否可用:
cclens tracebash
cclens trace --help 2>&1- 如果输出以 开头 → 正常使用
Usage: cclens trace。cclens trace - 如果输出的是 Claude Code 的帮助()→ 说明当前安装的
Usage: claude [options]版本还不包含 trace 功能,升级到最新版本:cclens
bash
npm install -g claude-code-lens安装完成后再次运行 确认可用。
cclens trace --help 2>&1Before executing any trace commands, first confirm if is available:
cclens tracebash
cclens trace --help 2>&1- If the output starts with → Use
Usage: cclens tracenormally.cclens trace - If the output shows Claude Code's help () → The currently installed
Usage: claude [options]version does not include the trace feature. Upgrade to the latest version:cclens
bash
npm install -g claude-code-lensRun again after installation to confirm availability.
cclens trace --help 2>&1核心原则
Core Principles
- 是唯一可信来源。不打开浏览器 UI,不猜测 raw log 路径。
cclens trace - 始终使用 。将 CLI 输出视为结构化数据,而非自然语言。
-f json - 默认选择能回答用户问题的最窄范围 — 先看 或单个 subagent,必要时分别导出两者对照。
lead - 仅在需要排查归因统计、log 文件路径或 per-agent 工具调用分布时使用,常规分析不添加。
--debug - 匹配到多个 session 时,用 、
startedAt和context区分后再继续。status
- is the only trusted source. Do not open the browser UI or guess raw log paths.
cclens trace - Always use . Treat CLI output as structured data, not natural language.
-f json - By default, select the narrowest scope that can answer the user's question — first check the or a single subagent, and export both for comparison if necessary.
lead - is only used when troubleshooting attribution statistics, log file paths, or per-agent tool call distribution; do not add it for routine analysis.
--debug - When multiple sessions are matched, distinguish them using ,
startedAt, andcontextbefore proceeding.status
工作流
Workflow
1. 列出候选 Session
1. List Candidate Sessions
bash
cclens trace list -f json| 参数 | 用途 |
|---|---|
| 匹配 sessionId、context、status、agents 或 agent 名称 |
| 仅返回指定 ISO 8601 时间戳之后的 session |
| 限制返回数量(在构建摘要前截断,非正整数会触发 |
| 截断 context、status、does、outcome 等摘要字段(默认 120–220 字符不等) |
如果 返回空列表,或列表中找不到用户提及的 session,说明该会话不是通过 cclens 启动的 Claude Code,无法获取 trace 数据。此时应直接告知用户:该会话缺少 trace 记录,可能是未使用 cclens 启动,建议后续通过 cclens 启动 Claude Code 以便捕获 trace。
cclens trace list每个 session 的关键字段:
- —
sessionId和show的主键export - — 区分同一任务的多次运行
startedAt - — 首条模型 thinking 或 fallback 会话上下文,用于确认目标 trace
context - — session 当前或最终结果摘要
status - — agent 数量概览,如
agentslead + 6 subagents
bash
cclens trace list -f json| Parameter | Purpose |
|---|---|
| Match sessionId, context, status, agents, or agent names |
| Only return sessions after the specified ISO 8601 timestamp |
| Limit the number of returns (truncate before building summaries; non-positive integers will trigger |
| Truncate summary fields such as context, status, does, outcome (default 120–220 characters) |
If returns an empty list, or the user's mentioned session cannot be found in the list, it means the session is a Claude Code session not started via cclens, and trace data cannot be obtained. In this case, directly inform the user: This session lacks trace records, possibly because it was not started using cclens. It is recommended to start Claude Code via cclens in the future to capture traces.
cclens trace listKey fields of each session:
- — Primary key for
sessionIdandshowexport - — Distinguish multiple runs of the same task
startedAt - — The first model thinking or fallback session context, used to confirm the target trace
context - — Current or final result summary of the session
status - — Overview of the number of agents, e.g.,
agentslead + 6 subagents
2. 查看 Session 中的 Agent
2. View Agents in the Session
bash
cclens trace show --session <sessionId> -f json每个 agent 的关键字段:
- — 传给
idexport --agent - —
role或leadsubagent - — 紧凑可识别名称,subagent 格式为
name<type> · <description> - — 该 agent 被派去做什么
does - — 该 agent 交付了什么
outcome
按用户意图选择导出目标:
| 用户意图 | 导出目标 | 匹配方式 |
|---|---|---|
| 排查整体流程、任务编排问题 | | 直接指定 |
| 调查某个 subagent 的行为或失败原因 | | 按 |
| 对比 Lead 和 Subagent 的协作 | 分别导出 | 先用 |
在运行 之前先读取 输出中的 和 ,避免对错误 session 做无效操作。
showlistcontextstatusbash
cclens trace show --session <sessionId> -f jsonKey fields of each agent:
- — Passed to
idexport --agent - —
roleorleadsubagent - — Compact and recognizable name; subagent format is
name<type> · <description> - — What the agent was assigned to do
does - — What the agent delivered
outcome
Select export targets based on user intent:
| User Intent | Export Target | Matching Method |
|---|---|---|
| Troubleshoot overall process or task orchestration issues | | Directly specify |
| Investigate the behavior or failure cause of a specific subagent | | Match by |
| Compare collaboration between Lead and Subagent | Export | First use |
Read the and in the output before running to avoid invalid operations on the wrong session.
contextstatuslistshow3. 导出 Trace 为 Markdown
3. Export Trace as Markdown
bash
cclens trace export --session <sessionId> --agent <agentId|lead> -f json| 值 | 范围 |
|---|---|
| 仅主 Agent |
| 指定 subagent(id 来自 |
指定输出路径:
bash
cclens trace export --session <sessionId> --agent <id> --out /tmp/cclens-<session>-<agent>.md -f json返回的 JSON 中 是下一步要读取的绝对路径,同时返回 和 ,读取前先确认导出对象与目标一致。
markdownPathagent.doesagent.outcome未指定 时,默认输出到 。
--out~/.claude-code-lens/exports/trace-<session前8位>-<agentId>.mdbash
cclens trace export --session <sessionId> --agent <agentId|lead> -f json| Value | Scope |
|---|---|
| Only the main Agent |
| Specified subagent (id comes from |
Specify output path:
bash
cclens trace export --session <sessionId> --agent <id> --out /tmp/cclens-<session>-<agent>.md -f jsonThe in the returned JSON is the absolute path to read in the next step. It also returns and . Confirm that the exported object matches the target before reading.
markdownPathagent.doesagent.outcomeWhen is not specified, the default output path is .
--out~/.claude-code-lens/exports/trace-<first 8 digits of session>-<agentId>.md4. 读取并分析 Markdown
4. Read and Analyze Markdown
对 用 工具读取。
markdownPathRead分析重点:
- 范围过大、重复或可避免的工具调用
- 与实际行为不一致的 subagent
does - 因 Skill 指令不清晰导致的过长 thinking 路径
- Skill 中缺失的约束、决策规则或示例
- 可减少步骤、工具调用或 agent 交接的机会
Use the tool to read .
ReadmarkdownPathKey analysis points:
- Overly broad, repetitive, or avoidable tool calls
- Subagents where does not match actual behavior
does - Excessively long thinking paths caused by unclear Skill instructions
- Missing constraints, decision rules, or examples in Skills
- Opportunities to reduce steps, tool calls, or agent handovers
错误处理
Error Handling
所有错误以结构化 JSON 返回。读取 决定恢复路径,不要解析 做判断。
error.codemessage| 错误码 | 触发条件 | 恢复方式 |
|---|---|---|
| | 提示用户先运行 CCLens 捕获一次会话 |
| 列表为空 | | 告知用户:该会话不是通过 cclens 启动的,无法获取 trace。建议后续使用 cclens 启动 Claude Code |
| 指定的 | 重新运行 |
| 指定的 agent id 在 session 中不存在 | 重新运行 |
| Markdown 写入失败 | 用 |
| 使用了 | 使用 |
| | 检查参数值,传入有效正整数 |
All errors are returned as structured JSON. Read to determine the recovery path; do not parse for judgment.
error.codemessage| Error Code | Trigger Condition | Recovery Method |
|---|---|---|
| No sessions captured in | Prompt the user to run CCLens to capture a session first |
| Empty list | | Inform the user: This session was not started via cclens, so trace data cannot be obtained. It is recommended to start Claude Code using cclens in the future |
| The specified | Re-run |
| The specified agent id does not exist in the session | Re-run |
| Markdown writing failed | Retry with |
| Formats other than | Use |
| | Check parameter values and pass a valid positive integer |
汇报要求
Reporting Requirements
汇报结果时包含以下要素,缺一不可:
- 目标 session:和
sessionIdstartedAt - 目标 agent:、
id、role、namedoes - 证据:导出 Markdown 中的简短引用片段,不凭空断言
- 建议:具体的 Skill 或工作流修改方案,而非泛泛的观察
- 置信度:说明是否使用了 ,以及分析了
--debug、单个 subagent,还是两者都分析了lead
Include the following elements in the report results; none can be missing:
- Target session: and
sessionIdstartedAt - Target agent: ,
id,role,namedoes - Evidence: Short quoted fragments from the exported Markdown; do not assert without basis
- Recommendations: Specific modification plans for Skills or workflows, rather than general observations
- Confidence: Indicate whether was used, and whether the analysis covered the
--debug, a single subagent, or bothlead