- Trace Codex sessions to record session, turn, model call, tool, and subagent spans in Braintrust.
- Connect to Braintrust MCP to work with Braintrust projects, experiments, logs, and other data from Codex.
Trace Codex sessions
Thetrace-codex plugin uses bt to trace your Codex sessions to Braintrust.
Set up tracing
trace-codex is already installed, follow Update the tracing plugin.Install Codex
Install and authenticate bt
bt CLI quickstart to install bt, authenticate, and set your active context.Enable tracing
- Adds or refreshes the Braintrust plugin marketplace.
- Installs (or updates) and enables
trace-codex. - Writes
~/.codex/braintrust.json, which records whether tracing is enabled and which project receives traces. - With
btv0.27.2 or later, trusts the Braintrust hooks in Codex, so you don’t need to approve them through/hooks. This step runs thecodexcommand, so the Codex CLI must be on yourPATH.
bt trace enable.Restart Codex
bt earlier than v0.27.2, also run /hooks and trust the Braintrust hook definition. Codex does not run plugin hooks until you trust them.Log a test trace
What Braintrust traces
Codex traces in Braintrust include:- Session spans with the working directory, model, permission mode, Git repository metadata, and the final response of the last completed turn.
- Turn spans with prompts, including attached images, and final responses. When you interrupt a turn, the turn and the model call and tool spans still open record
metadata.outcomeasinterruptedandmetadata.termination_reasoninstead of an error. - Model call spans reconstructed from the session transcript, with conversation input, response output, and available token metrics. Images in prompts and tool results stay images in the conversation input.
- Tool spans with inputs, outputs, permission requests, and skill loads. When a tool call runs shell commands, a command that exits with a nonzero code records an error on the tool span, such as
Command exited with code 1, even if the tool call as a whole completes. The span records each command’s result inmetadata.command_outcomes. - Subagent spans nested under the turn that started the subagent.
- Compaction spans for context compactions, with a nested model span for the compaction call.
braintrust.plugin.codex, along with versions in context.span_origin: the plugin version in version, the bt version in bt.version, and the Codex version in codex.version. These versions are captured when each span is created, and unknown versions are null. Each turn span and every span under it, including subagent spans, records the turn’s span ID in metadata.turn_span_id.
Common workflows
Use different tracing settings for one session
Use different tracing settings for one session
bt trace run to trace a single Codex invocation without changing the saved tracing configuration.This workflow launches Codex from the terminal.To change the saved destination, profile, or organization, rerun bt trace enable codex 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.Trace a saved Codex session
Trace a saved Codex session
bt trace import to import a past session, even if tracing was not enabled when it ran. With bt v0.28.0 or later, this includes sessions whose transcripts Codex has compressed into .jsonl.zst files. You can’t follow a compressed session with --attach.You can also attach an imported session to an existing span or experiment.Resume a Codex session
Resume a Codex session
Stop tracing Codex sessions
Stop tracing Codex sessions
bt trace disable codex to uninstall the tracing plugin and remove its tracing configuration. Saved bt profiles and credentials are preserved. Restart Codex afterward.Update the tracing plugin
To update the plugin, follow these steps:codex plugin list --json shows trace-codex earlier than v1.0.1, or bt --version shows a version earlier than v0.19.0, follow Migrate from an older plugin version.Update bt
bt to the latest version and complete the applicable migrations.Update the tracing plugin
bt trace update updates the installed plugin without changing your saved tracing configuration.Restart and verify Codex
bt earlier than v0.27.2, also trust the updated Braintrust hook through /hooks if prompted. Run a short session and confirm that its trace appears on the Logs page in the intended Braintrust project.Migrate from an older plugin version
To migrate to the latest version of thetrace-codex plugin, follow these steps:
Inspect your Codex plugins
trace-codex@braintrust-codex-plugins:Install or update bt
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
trace-codex version, beginning with the oldest. If no sections apply, continue to the next step.trace-codex v1.0.1
trace-codex v1.0.1
config.json and environment variables. Starting in v1.0.1, it reads a dedicated configuration file written by bt trace enable codex, and bt handles authentication.Find the project that received your traces before updating. In v1.0.0, the settings take precedence in this order:projectin~/.codex/plugins/data/trace-codex-braintrust-codex-plugins/config.json.BRAINTRUST_PROJECTin your shell environment.BRAINTRUST_DEFAULT_PROJECTin your shell environment.- The default project,
codex.
BRAINTRUST_EVENT_SERVER_LOG_DIR, look for config.json there instead.Also record settings you want to preserve:- Extra root-span metadata from
additionalMetadatain the old file orBRAINTRUST_ADDITIONAL_METADATA. - Turn-end flushing from
flushOnTurnEndin the old file orBRAINTRUST_FLUSH_ON_TURN_END. - Deployment endpoints from
apiUrlandappUrlin the old file, orBRAINTRUST_API_URLandBRAINTRUST_APP_URL. Configure the appropriate deployment when you authenticate withbt.
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.To preserve metadata from an older plugin’s configuration or BRAINTRUST_ADDITIONAL_METADATA, pass it explicitly with --additional-metadata '<JSON>'. Normal-session hooks do not read metadata from this environment variable.The command updates your tracing file, normally ~/.codex/braintrust.json. Check the following settings in that file:- Existing
route.additional_metadatais preserved unless you pass--additional-metadata. - 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.
Restart and verify Codex
bt earlier than v0.27.2, also trust the updated Braintrust hook through /hooks if prompted. Run a short session and confirm that its trace appears on the Logs page in the intended Braintrust project.Remove obsolete settings
Settings used before trace-codex v1.0.1
Settings used before trace-codex v1.0.1
- Your shell configuration
~/.codex/plugins/data/trace-codex-braintrust-codex-plugins/config.json, or the custom plugin data directory you previously configured
bt commands, MCP connections, or integrations still need:bt trace import instead of the old parent-span settings.Troubleshooting tracing
First, runbt trace doctor codex. Then, review the following:
The tracing plugin is missing or disabled
The tracing plugin is missing or disabled
codex plugin list --json and confirm that trace-codex@braintrust-codex-plugins is installed and enabled. If it is missing or broken, run:bt earlier than v0.27.2, also trust the Braintrust hook through /hooks.Setup reports that hook activation failed
Setup reports that hook activation failed
bt v0.27.2 or later, bt trace enable codex and bt trace update codex install the plugin, then trust its hooks in Codex. If trusting fails, the command exits with an error that starts with Codex plugin installed, but hook activation failed, and the plugin and tracing settings stay in place. Common causes:Codex hooks are disabled in config: Enable hooks in your Codex configuration, then rerun the command.Installed Braintrust hooks differ from this bt version: Updatebt, then rerun the command.Unexpected or disabled Braintrust hook definition: Run/hooksin Codex and check the Braintrust hooks.
PATH. If it reports an unknown method or times out, update Codex and retry.Traces do not appear after setup
Traces do not appear after setup
bt is on the PATH of the process that launches Codex, and that the Braintrust hooks are trusted in /hooks.Run bt trace doctor codex and confirm that tracing is enabled and routed to the intended project.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 Codex session.A temporary tracing run rejects the hook-trust option
A temporary tracing run rejects the hook-trust option
bt trace run codex rejects --dangerously-bypass-hook-trust because it conflicts with the tracing hook managed by bt. Remove the option from the managed command.If an automation requires the option, run Codex directly with the installed tracing plugin instead. Bypass hook trust only when you control and trust every enabled hook.Codex uses an unexpected configuration directory
Codex uses an unexpected configuration directory
~/.codex/braintrust.json even when CODEX_HOME changes Codex’s own configuration directory.An explicit BRAINTRUST_DAEMON_CONFIG (BT_DAEMON_CONFIG in bt v0.25.0 and earlier) override changes the tracing file path. If you use it, supply the same path when enabling tracing and launching Codex.Traces use unexpected settings
Traces use unexpected settings
bt trace run take precedence over the saved tracing configuration. For normal sessions, the integration does not use TRACE_TO_BRAINTRUST, BRAINTRUST_PROJECT, or BRAINTRUST_ADDITIONAL_METADATA from the agent’s environment to override the saved tracing settings.For environment variables accepted by the bt commands themselves, see bt trace.Connect to Braintrust MCP
The Braintrust MCP server lets Codex query and update Braintrust data. MCP is configured independently from the tracing plugin.Remove the retired Braintrust MCP plugin (if installed)
Remove the retired Braintrust MCP plugin (if installed)
braintrust MCP plugin for Codex in favor of Codex’s native MCP configuration. If you installed the plugin, remove it before configuring the direct connection.Check whether the plugin is still installed:braintrust@braintrust-codex-plugins appears in the installed plugins, remove it:trace-codex tracing plugin.Choose authentication
- OAuth (recommended)
- API key
- No Braintrust API key required
- No OAuth client ID or client secret to configure
/.well-known/oauth-authorization-server on the same host as your MCP endpoint (see next step), so a client can register itself.bt login doesn’t authenticate the MCP server.Choose your endpoint
- Self-hosted: Copy the MCP URL from Settings > Data plane. This is your Braintrust API URL with
/mcpappended. - Transport: If your client asks you to choose a transport, choose HTTP (also called streamable HTTP). SSE-only clients can’t connect.
Add the server to Codex
Verify the connection
Start using Braintrust tools
- “Show me my recent Braintrust experiments.”
- “Query the last 10 logged requests with errors.”
- “Compare accuracy scores between my two latest experiments.”
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.