@braintrust/pi-extension package traces pi sessions to Braintrust, including turns, model calls, tool executions, and compactions.
This page documents interactive pi sessions with the Braintrust pi extension. To trace
@earendil-works/pi-coding-agent SDK usage in your own application, see Pi Coding Agent SDK.Trace pi sessions
The@braintrust/pi-extension package traces pi sessions to Braintrust by observing pi, not by proxying it:
- Pi talks to its model provider directly.
- Native events notify the extension when sessions start, turns run, models respond, and tools execute.
- The extension uses the
btCLI to build and send traces to Braintrust. - Authentication happens through
bt login. The extension never handles credentials. - If the extension or
bthas a problem, pi keeps working. However, you won’t see traces until the setup is fixed.
Set up tracing
The extension requires@braintrust/pi-extension v1.0.0 or later, bt v0.16.0 or later, and pi v0.65.0 or later.
1
Install pi
If you haven’t already, install pi.
2
Install bt and authenticate
Tracing runs through You can also install with mise or npm, or with PowerShell on Windows.
bt, and the pi extension does not install it for you. Install the CLI and authenticate:3
Configure the extension
After
bt is installed and authenticated, run the following command:4
Restart pi
Restart pi so it loads the extension.
What gets traced
pi traces in Braintrust include:- Session spans with
session_id,source, pi version, and Git repository metadata. - Turn spans with prompts, model names, thinking level, and
loaded_skill_nameswhen the prompt requests skills. - Model call spans with conversation input, response output, errors, and token metrics.
- Tool spans with tool inputs and outputs. When pi runs the
skilltool, the span is namedskill: <name>. - Compaction spans (
Compaction) for context-window compactions. - Branch summary spans (
Branch Summary) when pi summarizes a branch while navigating the session’s history tree.
Settings
bt trace setup pi saves your tracing configuration to ~/.pi/agent/braintrust.json. These saved settings control where traces go during normal pi sessions.
Notes:
-
For pi tracing, environment variables override saved settings. The project config (
.pi/braintrust.json) overrides the global config (~/.pi/agent/braintrust.json). The project config directory follows pi’sCONFIG_DIR_NAMEsetting. -
Credentials are stored by
bt, not the configuration file. Authenticate withbt loginorBRAINTRUST_API_KEY. See credential precedence. -
To use different settings for one launched session without changing saved configuration, use
bt trace run. -
To switch projects, re-run setup:
Common workflows
Use custom settings for one run
Use custom settings for one run
To apply custom settings to a single pi run, launch pi with
bt trace run:bt trace run automatically injects the extension (via pi’s -e flag), so the extension does not need to be installed globally. This command can send one run to a different project, profile, or organization without changing the saved settings in ~/.pi/agent/braintrust.json.To run pi non-interactively, pass its -p flag after --:Load the extension for one session
Load the extension for one session
To load the extension for a single session without installing it, use pi’s This uses your saved tracing settings from
-e flag:~/.pi/agent/braintrust.json but does not permanently install the extension.Upgrade
To get the latestbt and @braintrust/pi-extension, follow these steps. If you are upgrading from @braintrust/pi-extension before v1.0.0, the steps also cover the required migration.
1
Update bt
Update
bt before updating @braintrust/pi-extension.If you’re also migrating from an older
bt version with bt auth commands, review the CLI migration guide. It explains how saved logins carry over, how profiles and organizations changed, and which commands replaced the old auth commands.bt update updates installs made with the standalone shell or PowerShell installer. If you installed with mise or npm, update bt with that package manager instead. If a Windows install older than bt v0.17.0 cannot update itself, rerun the PowerShell installer.2
Authenticate bt
Starting in v1.0.0,
@braintrust/pi-extension uses bt for tracing and authentication. If you haven’t authenticated with bt, run bt login. You can also authenticate with BRAINTRUST_API_KEY.3
Run setup
Run setup with the Braintrust project that should receive your pi traces. This updates
@braintrust/pi-extension and writes the latest tracing settings.Before v1.0.0, the extension read the destination project from the
BRAINTRUST_PROJECT environment variable or the top-level project key in ~/.pi/agent/braintrust.json or your project’s .pi/braintrust.json. If you are upgrading from one of these versions, find the old value. In the command above, replace my-project with that value. bt trace setup does not migrate the old top-level key automatically.4
Migrate settings from an extension version before v1.0.0
If you are upgrading from an extension version before v1.0.0, use this table to migrate environment variables and settings from
~/.pi/agent/braintrust.json or your project’s .pi/braintrust.json:Troubleshooting
Traces do not appear
Traces do not appear
Check the following, in order:
- Verify
btis installed and current:bt --version(v0.16.0 or later). - Verify
btis authenticated: runbt status. Authenticate withbt loginorBRAINTRUST_API_KEY. - Verify the extension is installed: run
pi listand check for@braintrust/pi-extension. - Verify tracing is enabled: re-run
bt trace setup pito settrace_to_braintrusttotrue. - Restart pi after any configuration change.
- Run at least one prompt. A session root span is only created for sessions that actually produce a turn.
The trace link widget does not appear
The trace link widget does not appear
- The widget is only shown in interactive mode.
- Run at least one prompt so the extension has a trace to link to.
- Check that
show_trace_linkis not set tofalse.
Connect to the Braintrust MCP server
Pi does not include built-in MCP support. If you add MCP to pi through a third-party adapter, you can connect to the Braintrust MCP server using the client setup instructions.Next steps
- Learn the CLI: See the full
bt tracereference, including setup and per-run tracing. - Run evaluations: Check out the evaluation guide to learn evaluation patterns.
- Explore MCP tools: See the MCP documentation for all available commands.
- Browse the source: The coding-agent plugins repository contains the extension source code.