bt trace connects a coding agent to Braintrust so its sessions are traced: every session, conversation turn, model call, and tool use lands in a Braintrust project. It requires bt v0.16.0 or later and supports Claude Code, Codex, OpenCode, and pi.
Tracing works by observation. The agent’s Braintrust plugin doesn’t sit in between your agent and its model provider. Instead, it observes the agent’s hooks or native events and hands trace events to bt, which relays them to a background process (the tracing daemon) that builds the trace and delivers it to Braintrust. The plugin never handles credentials: authentication happens through bt, using the same login or API key as any other bt command, so there is nothing separate to configure for tracing.
Tracing also never gets in your agent’s way. If any part of the chain is missing or broken, the agent keeps working normally. You just don’t see traces until it’s fixed.
bt trace setup
Set up persistent tracing for an agent. One command installs the agent’s Braintrust tracing plugin, selects a project, and turns tracing on:claude, codex, opencode, or pi. What “install” means depends on the agent (see the full setup guides for Claude Code, Codex, OpenCode, and pi):
In every case, setup then writes the agent’s tracing settings file (see Where settings live) and enables tracing.
If you omit
--project, setup uses your configured default project, or prompts you to pick one interactively. In non-interactive environments, pass --project <NAME> or set BRAINTRUST_DEFAULT_PROJECT, or setup fails with an explanatory error.
bt trace run
Use temporary tracing settings for one agent invocation without changing its saved setup:bt trace import
Import a session that already happened. The agent’s own transcript on disk is the source, so this works even if tracing wasn’t set up when the session ran:claude and codex. The session ID is the one your agent shows in its resume or session list. Pass more than one session ID to import multiple sessions, or pass --all to import every locally discoverable session for that agent. The imported trace goes to your configured project by default. To send it somewhere specific, pass --destination with a reference such as project_logs:<project-id> or experiment:<experiment-id>, or use --parent <exported-span> to attach it below the span exported by span.export().
To follow a session that is still running, pass --attach with exactly one session ID. You cannot combine --attach with --all or multiple session IDs. Import keeps reading the transcript and sending new turns until you press Ctrl-C.
Import flags
Where settings live
bt trace setup writes tracing settings to the following global file for each agent:
OpenCode and pi can also read project settings from
.opencode/braintrust.json and .pi/braintrust.json, respectively. bt trace setup does not create or update these project files.
What bt trace setup writes
Runningbt trace setup <agent> --project <name> updates two top-level keys. On Unix-like systems, it sets the file permissions to 0600:
--project, --profile, or --org to choose specific values. Otherwise, setup uses your active bt context or prompts you when necessary.
Settings reference
Credentials are the one thing the file never holds. Authentication happens through
bt, exactly as it does for any other bt command, which also covers self-hosted deployments: the profile you log in with carries your deployment’s URLs, so traces go to the same data plane as the rest of your bt usage.
Precedence
Claude Code and Codex prefer their settings file over environment variables. For OpenCode and pi, project settings override global settings, and environment variables override both.bt trace run overrides these settings for a single invocation.
Troubleshooting
If the agent works normally but no traces appear, check the following, in order:- Is
btinstalled and current? Runbt --version. Tracing requires v0.16.0 or later. - Is
btlogged in? Runbt status --verbose. It shows the active profile and authentication details. If nothing is logged in, runbt login. - Is tracing enabled for this agent? In the agent’s settings file, confirm that
trace_to_braintrustistrueandroute.destinationnames the intended project.
Next steps
- Follow the agent-specific guides for Claude Code, Codex, OpenCode, and pi.
- Migrating from an earlier plugin or CLI version? See the CLI migration guide.
- Learn what else the CLI can do in the CLI overview.