‹ 首页

trace-claude-code

@parcadei · 收录于 1 周前 · 上游提交 5 个月前

Automatically trace Claude Code conversations to Braintrust for observability. Captures sessions, conversation turns, and tool calls as hierarchical traces.

适合你,如果正在用 Claude Code 并需要记录对话用于调试或分析

/ 下载安装
trace-claude-code.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add parcadei/continuous-claude-v3/trace-claude-code
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- parcadei/continuous-claude-v3/trace-claude-code
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify parcadei/continuous-claude-v3/trace-claude-code
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
3859GitHub stars
~1.2K上下文体积 · 单文件
镜像托管

怎么用

商店整理自技能原文 · 版本 d07ff4b · 表述以原文为准
它做什么

安装后,Claude Code 的每次对话和工具调用都会被自动记录到 Braintrust,形成层级分明的追踪记录,方便你查看 AI 编程会话的完整过程。

什么时候触发

当你启动 Claude Code 并执行操作(如读取文件、编辑代码、运行命令)时,该技能会自动捕获每个会话、对话轮次和工具调用。

装好后可以这样说
终端命令和 Claude 的响应都会被追踪。
Git 命令和提交信息都会被记录。
技能原文 SKILL.md作者撰写 · MIT · d07ff4b

Trace Claude Code to Braintrust

Automatically send Claude Code conversations to Braintrust for tracing and observability. Get full visibility into your AI coding sessions with hierarchical traces showing sessions, turns, and every tool call.

What you get
Claude Code Session (root trace)
├── Turn 1: "Add error handling"
│   ├── Read: src/app.ts
│   ├── Edit: src/app.ts
│   └── Response: "I've added try-catch..."
├── Turn 2: "Now run the tests"
│   ├── Terminal: npm test
│   └── Response: "All tests pass..."
└── Turn 3: "Great, commit this"
    ├── Terminal: git add .
    ├── Terminal: git commit -m "..."
    └── Response: "Changes committed..."
How it works

Four hooks capture the complete workflow:

| Hook | What it captures | |------|------------------| | SessionStart | Creates root trace when you start Claude Code | | PostToolUse | Captures every tool call (file reads, edits, terminal commands) | | Stop | Captures conversation turns (your message + Claude's response) | | SessionEnd | Logs session summary when you exit |

Quick setup

Run the setup script in any project directory where you want tracing:

bash /path/to/skills/trace-claude-code/setup.sh

The script prompts for your API key and project name, then configures all hooks automatically.

Manual setup
Prerequisites
Configuration

Create .claude/settings.local.json in your project directory:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash /path/to/hooks/session_start.sh"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "*",
        "hooks": [
          {
            "type": "command",
            "command": "bash /path/to/hooks/post_tool_use.sh"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash /path/to/hooks/stop_hook.sh"
          }
        ]
      }
    ],
    "SessionEnd": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "bash /path/to/hooks/session_end.sh"
          }
        ]
      }
    ]
  },
  "env": {
    "TRACE_TO_BRAINTRUST": "true",
    "BRAINTRUST_API_KEY": "sk-...",
    "BRAINTRUST_CC_PROJECT": "my-project"
  }
}

Replace /path/to/hooks/ with the actual path to this skill's hooks directory.

Environment variables

| Variable | Required | Description | |----------|----------|-------------| | TRACE_TO_BRAINTRUST | Yes | Set to "true" to enable tracing | | BRAINTRUST_API_KEY | Yes | Your Braintrust API key | | BRAINTRUST_CC_PROJECT | No | Project name (default: claude-code) | | BRAINTRUST_CC_DEBUG | No | Set to "true" for verbose logging |

Viewing traces

After running Claude Code with tracing enabled:

  1. Go to braintrust.dev
  2. Navigate to your project (e.g., claude-code)
  3. Click Logs to see all traced sessions

Each trace shows:

  • Session root: The overall Claude Code session
  • Turns: Each conversation exchange (user input → assistant response)
  • Tool calls: Individual operations (file reads, edits, terminal commands)
Trace structure

Traces are hierarchical:

  • Session (root span)
  • span_attributes.type: "task"
  • metadata.session_id: Unique session identifier
  • metadata.workspace: Project directory
  • Turn (child of session)
  • span_attributes.type: "llm"
  • input: User message
  • output: Assistant response
  • metadata.turn_number: Sequential turn number
  • Tool call (child of turn or session)
  • span_attributes.type: "tool"
  • input: Tool input (file path, command, etc.)
  • output: Tool result
  • metadata.tool_name: Name of the tool used
Troubleshooting
No traces appearing
  1. Check hooks are running: ```bash tail -f ~/.claude/state/braintrust_hook.log ```
  1. Verify environment variables in .claude/settings.local.json:
  2. TRACE_TO_BRAINTRUST must be "true"
  3. BRAINTRUST_API_KEY must be valid
  1. Enable debug mode: ```json { "env": { "BRAINTRUST_CC_DEBUG": "true" } } ```
Permission errors

Make hook scripts executable:

chmod +x /path/to/hooks/*.sh
Missing jq command

Install jq:

  • macOS: brew install jq
  • Ubuntu/Debian: sudo apt-get install jq
State issues

Reset the tracing state:

rm ~/.claude/state/braintrust_state.json
Hook logs

View detailed hook execution logs:

# Follow logs in real-time
tail -f ~/.claude/state/braintrust_hook.log

# View last 50 lines
tail -50 ~/.claude/state/braintrust_hook.log

# Clear logs
> ~/.claude/state/braintrust_hook.log
File structure
hooks/
├── common.sh          # Shared utilities (logging, API, state)
├── session_start.sh   # Creates root trace span
├── post_tool_use.sh   # Captures tool calls
├── stop_hook.sh       # Captures conversation turns
└── session_end.sh     # Finalizes trace
Alternative: SDK integration

For programmatic use with the Claude Agent SDK, use the native Braintrust integration:

import { initLogger, wrapClaudeAgentSDK } from "braintrust";
import * as claudeSDK from "@anthropic-ai/claude-agent-sdk";

initLogger({
  projectName: "my-project",
  apiKey: process.env.BRAINTRUST_API_KEY,
});

const { query, tool } = wrapClaudeAgentSDK(claudeSDK);

See Braintrust Claude Agent SDK docs for details.

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。