@earendil-works/pi-coding-agent SDK usage in your own application, see Pi Coding Agent SDK.Trace pi sessions
The@braintrust/pi-extension extension passes your interactions with pi to bt, which in turn uses a background process to build and deliver the trace to Braintrust.
pi continues to communicate directly with its model provider, and tracing failures do not stop your pi session.
Set up tracing
@braintrust/pi-extension is already installed, follow Update the tracing extension.Install pi
Install and authenticate bt
bt CLI quickstart to install bt v0.19.3 or later, authenticate, and set your active context.Enable tracing
- Installs (or updates)
@braintrust/pi-extensionglobally through pi’s package installer, using the^2version range. - Writes
~/.pi/agent/braintrust.json, which records whether tracing is enabled and which project receives traces.
.pi/braintrust.json can override the global tracing settings.For more information, see bt trace enable.Restart pi
Log a test trace
What Braintrust traces
pi traces in Braintrust include:- Session spans with the session ID, local username, Git repository metadata, and pi version when available.
- Turn spans with prompts, thinking level, and requested skills.
- Model call spans with conversation input, response output, errors, and token metrics.
- Tool spans with inputs and outputs, including skill loads when pi reads a
SKILL.mdfile. - Compaction spans for context compactions.
- Branch summary spans when pi summarizes a branch while navigating session history.
braintrust.plugin.pi.
Common workflows
Use different tracing settings for one session
Use different tracing settings for one session
bt trace run to trace a single pi invocation without changing the saved tracing configuration.This workflow launches pi from the terminal.To change the saved destination, profile, or organization, rerun bt trace enable pi with the corresponding options. Running bt switch does not change the saved tracing configuration.To add root-span metadata, pass --additional-metadata '<JSON>' to bt trace run for one invocation or to bt trace enable for future sessions. Standard session metadata takes precedence when keys conflict.With bt v0.19.3 or later, pass --tag ci --tag release-validation to either command to tag session spans.Configure the tracing status display
Configure the tracing status display
show_ui to false in the global or project-local tracing file. To hide only the trace link, set show_trace_link to false. BRAINTRUST_SHOW_UI and BRAINTRUST_SHOW_TRACE_LINK override those settings.Stop tracing pi sessions
Stop tracing pi sessions
bt trace disable pi to uninstall the global tracing extension and remove its global tracing configuration. Saved bt profiles and credentials are preserved. Restart pi afterward.Project-local extension installations and tracing files are separate. Remove any project-local installation too if you want to stop tracing there.Update the tracing extension
To update the extension, follow these steps:pi list shows @braintrust/pi-extension earlier than v2.0.0, or you cannot determine its version, follow Migrate from an older extension version.Update bt
bt to the latest version and complete the applicable migrations.Update the tracing extension
bt trace update updates the installed extension without changing your saved tracing configuration.Restart and verify pi
Migrate from an older extension version
To migrate to the latest version of the@braintrust/pi-extension extension, follow these steps:
Inspect your pi extensions
@braintrust/pi-extension is installed:.pi/braintrust.json.Install or update bt
bt v0.19.3 or later. Check whether bt is installed:- If the command succeeds, migrate to the latest version (unless you’ve already done so).
- Otherwise, install
bt, authenticate, and set organization and project context.
Complete version-specific migration steps
@braintrust/pi-extension version, beginning with the oldest. If no sections apply, continue to the next step.@braintrust/pi-extension v1.0.0
@braintrust/pi-extension v1.0.0
bt handles both, and the tracing files store settings rather than credentials.Record project, org_name, and additional_metadata from ~/.pi/agent/braintrust.json and your project’s .pi/braintrust.json. Environment variables took precedence over these files. If the project was not configured, the default was pi.If the old configuration contains api_key, api_url, or app_url, use the corresponding credentials and deployment when you authenticate with bt. Keep credentials private and retain any settings needed by other integrations.@braintrust/pi-extension v2.0.0
@braintrust/pi-extension v2.0.0
TRACE_TO_BRAINTRUST: Whether tracing was enabled.BRAINTRUST_PROFILEandBRAINTRUST_ORG_NAME: The tracing account and organization.BRAINTRUST_PROJECT: The project that received traces.BRAINTRUST_ADDITIONAL_METADATA: Extra root-span metadata.
--project, account and organization with --profile and --org, and metadata with --additional-metadata '<JSON>'. This preserves values that previously overrode your saved configuration.braintrust.json are resolved:- Profile, organization, and project values in the
routeobject now take precedence over their legacy top-level equivalents. Before v2.0.0, the top-level values took precedence. - Metadata is unchanged: top-level
additional_metadatacan still overrideroute.additional_metadata.
route object so you do not leave conflicting copies. Environment variables accepted by bt commands are separate from these extension changes. See bt trace.Apply your tracing settings
--profile <profile> and --org <organization> if needed to preserve your tracing account and organization. Otherwise, the command uses your active bt context, not your saved tracing settings.The command updates your global tracing file, normally ~/.pi/agent/braintrust.json. Check the following settings in that file:- Existing
route.additional_metadatais preserved unless you pass--additional-metadata. If it is absent,btmigrates top-leveladditional_metadatainstead. - Existing
route.tagsis preserved unless you pass--tagor setBRAINTRUST_TAGS. route.flush_moderesets tofire_and_forget. Restore its previous value if you customized it.- Restore any other custom tracing settings you recorded before updating.
route object in the generated global file as a template while preserving that project’s intended destination, authentication, metadata, and tags. A project-level route object containing a destination replaces the entire global route object. After moving any legacy values under route, remove their duplicate top-level keys so they cannot override it.Restart and verify pi
Remove obsolete settings
Settings used before @braintrust/pi-extension v2.0.0
Settings used before @braintrust/pi-extension v2.0.0
- Your shell configuration
- The global tracing file and your project’s
.pi/braintrust.json
bt commands, MCP connections, or integrations still need:TRACE_TO_BRAINTRUST,BRAINTRUST_PROFILE,BRAINTRUST_ORG_NAME,BRAINTRUST_PROJECT, andBRAINTRUST_ADDITIONAL_METADATAin the agent environmentBRAINTRUST_API_KEY,BRAINTRUST_API_URL, andBRAINTRUST_APP_URLused by pre-v1.0.0 tracing- Top-level
profile,org_name,project, andadditional_metadataafter preserving their values underroute - Pre-v1.0.0
api_key,api_url,app_url,debug,log_file,state_dir,parent_span_id, androot_span_idkeys - Pre-v1.0.0
BRAINTRUST_DEBUG,BRAINTRUST_LOG_FILE,BRAINTRUST_STATE_DIR,PI_PARENT_SPAN_ID, andPI_ROOT_SPAN_IDenvironment variables
BRAINTRUST_SHOW_UI and BRAINTRUST_SHOW_TRACE_LINK if you use them to control the tracing display.Troubleshooting tracing
First, runbt trace doctor pi. Then, review the following:
The tracing extension is missing or disabled
The tracing extension is missing or disabled
pi list and confirm that @braintrust/pi-extension is installed. If it is missing or broken, run:Traces do not appear after setup
Traces do not appear after setup
bt trace doctor pi and confirm that tracing is enabled and routed to the intended project. Also inspect any project-local tracing file, which can override the global settings.If authentication succeeds but traces do not appear, confirm that your account has permission to write logs to the selected project.For authentication, tracing destination, or endpoint problems, see bt trace troubleshooting and the CLI migration troubleshooting guide.Tracing failures do not interrupt the pi session.pi uses an unexpected configuration directory
pi uses an unexpected configuration directory
~/.pi/agent/braintrust.json. The project-local file is normally .pi/braintrust.json. Its directory follows piConfig.configDir in the installed pi package’s metadata, with .pi as the fallback.Traces use unexpected settings
Traces use unexpected settings
bt trace run take precedence over the saved tracing configuration.For normal sessions, project-local .pi/braintrust.json settings override global settings. A project-level route object containing a destination replaces the entire global route object, so include complete authentication settings too.The extension does not use TRACE_TO_BRAINTRUST, BRAINTRUST_PROFILE, BRAINTRUST_ORG_NAME, BRAINTRUST_PROJECT, or BRAINTRUST_ADDITIONAL_METADATA from the agent’s environment to override the saved tracing settings.If an older file still has top-level additional_metadata, migrate it to route.additional_metadata and remove the old key so it cannot override your intended metadata.For environment variables accepted by the bt commands themselves, see bt trace.Connect to Braintrust MCP
pi does not include built-in MCP support. If you add MCP through a third-party adapter, follow the Braintrust MCP client setup instructions.Next steps
- Learn the CLI: See the full
bt tracereference. - Run evaluations: Follow the evaluation guide.
- Explore MCP tools: See the Braintrust MCP tool reference.
- Browse the source: View the coding-agent plugins repository.