Back to Skills

trace-claude-code

parcadei
Updated Today
36 views
3,101
217
3,101
View on GitHub
Developmentaiautomation

About

This skill automatically traces Claude Code conversations to Braintrust for observability. It captures entire sessions, individual conversation turns, and every tool call as hierarchical traces. Use it to gain full visibility into AI-assisted coding workflows for debugging and analysis.

Quick Install

Claude Code

Recommended
Primary
npx skills add parcadei/Continuous-Claude-v3
Plugin CommandAlternative
/plugin add https://github.com/parcadei/Continuous-Claude-v3
Git CloneAlternative
git clone https://github.com/parcadei/Continuous-Claude-v3.git ~/.claude/skills/trace-claude-code

Copy and paste this command in Claude Code to install this skill

Documentation

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:

HookWhat it captures
SessionStartCreates root trace when you start Claude Code
PostToolUseCaptures every tool call (file reads, edits, terminal commands)
StopCaptures conversation turns (your message + Claude's response)
SessionEndLogs 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

VariableRequiredDescription
TRACE_TO_BRAINTRUSTYesSet to "true" to enable tracing
BRAINTRUST_API_KEYYesYour Braintrust API key
BRAINTRUST_CC_PROJECTNoProject name (default: claude-code)
BRAINTRUST_CC_DEBUGNoSet 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:

    tail -f ~/.claude/state/braintrust_hook.log
    
  2. Verify environment variables in .claude/settings.local.json:

    • TRACE_TO_BRAINTRUST must be "true"
    • BRAINTRUST_API_KEY must be valid
  3. Enable debug mode:

    {
      "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.

GitHub Repository

parcadei/Continuous-Claude-v3
Path: .claude/plugins/braintrust-tracing/skills/trace-claude-code
agentsclaude-codeclaude-code-cliclaude-code-hooksclaude-code-mcpclaude-code-skills

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

himalaya-email-manager

Communication

This Claude Skill enables email management through the Himalaya CLI tool using IMAP. It allows developers to search, summarize, and delete emails from an IMAP account with natural language queries. Use it for automated email workflows like getting daily summaries or performing batch operations directly from Claude.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill

evaluating-llms-harness

Testing

This Claude Skill runs the lm-evaluation-harness to benchmark LLMs across 60+ standardized academic tasks like MMLU and GSM8K. It's designed for developers to compare model quality, track training progress, or report academic results. The tool supports various backends including HuggingFace and vLLM models.

View skill