trace-claude-code
Automatically trace Claude Code conversations to Braintrust for observability. Captures sessions, conversation turns, and tool calls as hierarchical traces.
Install
mkdir -p .claude/skills/trace-claude-code && curl -L -o skill.zip "https://mcp.directory/api/skills/download/3773" && unzip -o skill.zip -d .claude/skills/trace-claude-code && rm skill.zipInstalls to .claude/skills/trace-claude-code
About this skill
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
- Claude Code CLI installed
- Braintrust API key
jqcommand-line tool (brew install jqon macOS)
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:
- Go to braintrust.dev
- Navigate to your project (e.g.,
claude-code) - 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 identifiermetadata.workspace: Project directory
-
Turn (child of session)
span_attributes.type:"llm"input: User messageoutput: Assistant responsemetadata.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 resultmetadata.tool_name: Name of the tool used
Troubleshooting
No traces appearing
-
Check hooks are running:
tail -f ~/.claude/state/braintrust_hook.log -
Verify environment variables in
.claude/settings.local.json:TRACE_TO_BRAINTRUSTmust be"true"BRAINTRUST_API_KEYmust be valid
-
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.
More by parcadei
View all skills by parcadei →You might also like
flutter-development
aj-geddes
Build beautiful cross-platform mobile apps with Flutter and Dart. Covers widgets, state management with Provider/BLoC, navigation, API integration, and material design.
ui-ux-pro-max
nextlevelbuilder
"UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient."
drawio-diagrams-enhanced
jgtolentino
Create professional draw.io (diagrams.net) diagrams in XML format (.drawio files) with integrated PMP/PMBOK methodologies, extensive visual asset libraries, and industry-standard professional templates. Use this skill when users ask to create flowcharts, swimlane diagrams, cross-functional flowcharts, org charts, network diagrams, UML diagrams, BPMN, project management diagrams (WBS, Gantt, PERT, RACI), risk matrices, stakeholder maps, or any other visual diagram in draw.io format. This skill includes access to custom shape libraries for icons, clipart, and professional symbols.
godot
bfollington
This skill should be used when working on Godot Engine projects. It provides specialized knowledge of Godot's file formats (.gd, .tscn, .tres), architecture patterns (component-based, signal-driven, resource-based), common pitfalls, validation tools, code templates, and CLI workflows. The `godot` command is available for running the game, validating scripts, importing resources, and exporting builds. Use this skill for tasks involving Godot game development, debugging scene/resource files, implementing game systems, or creating new Godot components.
nano-banana-pro
garg-aayush
Generate and edit images using Google's Nano Banana Pro (Gemini 3 Pro Image) API. Use when the user asks to generate, create, edit, modify, change, alter, or update images. Also use when user references an existing image file and asks to modify it in any way (e.g., "modify this image", "change the background", "replace X with Y"). Supports both text-to-image generation and image-to-image editing with configurable resolution (1K default, 2K, or 4K for high resolution). DO NOT read the image file first - use this skill directly with the --input-image parameter.
pdf-to-markdown
aliceisjustplaying
Convert entire PDF documents to clean, structured Markdown for full context loading. Use this skill when the user wants to extract ALL text from a PDF into context (not grep/search), when discussing or analyzing PDF content in full, when the user mentions "load the whole PDF", "bring the PDF into context", "read the entire PDF", or when partial extraction/grepping would miss important context. This is the preferred method for PDF text extraction over page-by-page or grep approaches.
Related MCP Servers
Browse all serversSend and receive WhatsApp messages from Claude and other AI assistants. Search chats, manage contacts, and automate work
Claude Code is an AI powered coding assistant that streamlines coding tasks, file ops, Git, and searches by auto-bypassi
Claude Historian: AI-powered search for Claude Code conversations—find files, errors, context, and sessions via JSONL pa
Voice Hooks — real-time voice for Claude Code: browser speech recognition, natural TTS replies, and conversation state m
Sub-Agents delegates tasks to specialized AI assistants, automating workflow orchestration with performance monitoring a
Knowledge Graph: persistent local memory for Claude that stores entities, observations and relations to enable structure