Skip to main content
skill CX Codex

trace-claude-code — Claude Code skill: what it does, how to install

trace-claude-code streams Claude Code interactions directly into Braintrust. Captures multi-turn conversations, tool executions, and file edits as structured spans.

MIT ★ 3,951 updated 2026-01-26

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add parcadei/Continuous-Claude-v3 --skill trace-claude-code -a claude-code
Open on GitHub

What trace-claude-code does

This skill integrates observability directly into local coding workflows by forwarding activity to Braintrust. Each Claude Code execution forms a structured hierarchy: the root task span tracks the overall session, nested records log each turn with input and output messages, and individual tool events capture terminal commands alongside file modifications.

Under the hood, four bash routines handle tracking: session_start.sh initialises the trace, post_tool_use.sh monitors tool operations, stop_hook.sh aggregates message pairs, and session_end.sh writes the closing summary. Configuration is applied via setup.sh or through hook declarations inside .claude/settings.local.json.

Tracing relies strictly on the command-line utility jq and a valid BRAINTRUST_API_KEY. Without TRACE_TO_BRAINTRUST set to "true", outgoing trace delivery remains completely inactive.

What it helps with

  • stream Claude Code execution history into Braintrust dashboards
  • inspect granular tool invocations including terminal actions and file diffs
  • debug failed assistant workflows using local trace logs
  • structure development sessions into parent spans and individual conversational turns

Example prompts for the agent

  • Run the setup script for trace-claude-code to configure my Braintrust key
  • Add the trace hooks into my local .claude/settings.local.json file
  • Check the debug output inside ~/.claude/state/braintrust_hook.log

How to install trace-claude-code

1Skills CLI (Vercel)

npx skills add parcadei/Continuous-Claude-v3 --skill trace-claude-code -a claude-code

2Manually: put the files in place

~/.claude/skills/trace-claude-code/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/trace-claude-code/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about trace-claude-code

How to install trace-claude-code in Claude Code?

Run npx skills add parcadei/Continuous-Claude-v3 --skill trace-claude-code -a claude-code in your terminal or place the file into ~/.claude/skills/trace-claude-code/SKILL.md.

What does trace-claude-code do?

It intercepts session lifecycles, assistant turns, and tool executions in Claude Code, converting them into hierarchical observability traces inside Braintrust.

What dependencies are needed for the scripts?

You need jq available in your command line and executable permissions granted on all .sh files inside the hooks directory.

Source text

SKILL.md · MIT
---
name: trace-claude-code
description: |
  Automatically trace Claude Code conversations to Braintrust for observability.
  Captures sessions, conversation turns, and tool calls as hierarchical traces.
version: 1.1.0
---

# 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
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](https://docs.anthropic.com/en/docs/claude-code) installed
- [Braintrust API key](https://www.braintrust.dev/app/settings/api-keys)
- `jq` command-line tool (`brew install jq` on macOS)

### Configuration

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

```json
{
  "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](https://www.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
   ```

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:**
   ```json
   {
     "env": {
       "BRAINTRUST_CC_DEBUG": "true"
     }
   }
   ```

### Permission errors

Make hook scripts executable:

```bash
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:

```bash
rm ~/.claude/state/braintrust_state.json
```

### Hook logs

View detailed hook execution logs:

```bash
# 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:

```typescript
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](https://www.braintrust.dev/docs/integrations/sdk-integrations/claude-agent-sdk) for details.

© parcadei · MIT · parcadei/Continuous-Claude-v3

Similar skills

All skills for Agent setup: memory, context, orchestration →

From the same set161

The whole set →
liaison liaison is a Claude Code subagent that reviews integrations and API implementations. It joins tasks focused on an external service or data exchange. CX Codex ★ 3,951repo stars agentica-agent Generates Python agents with the Agentica SDK. It scaffolds @agentic functions, configures spawn() setups, and writes multi-agent orchestration flows. CX Codex ★ 3,951repo stars memory-extractor The memory-extractor subagent finds shifts in understanding inside Claude session reasoning and saves them as learnings. Use it to retain codebase patterns and debugging lessons. CX Codex ★ 3,951repo stars plan-reviewer plan-reviewer is a subagent that reviews feature designs and change plans, checking requirements, security, and completeness before implementation. CX Codex ★ 3,951repo stars maestro maestro splits complex work into phases, assigns tasks to subagents, and combines their results. Use it when a task depends on several agents. CX Codex ★ 3,951repo stars wiring The wiring skill ensures infrastructure components are actually invoked, not left as dead code. It teaches how to verify entry points, trace call paths, test integration end-to-end, and detect orphaned modules. CX Codex +1 ★ 3,951repo stars kraken kraken is a Claude Code subagent that implements features and refactors code through strict TDD checkpoints. CX Codex ★ 3,951repo stars review-agent review-agent compares a plan with Braintrust session data and the Git diff, then writes a report on gaps and checks. Run it after implementation and before handoff. CX Codex ★ 3,951repo stars

Project sponsors

Companies that keep this analytics open