- 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 passes your interactions with Codex to bt, which in turn uses a background process to build and deliver the trace to Braintrust.
Codex continues to communicate directly with its model provider, and tracing failures do not stop your Codex session.
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.
bt trace enable.Restart Codex and approve the plugin's hooks
/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, and Git repository metadata.
- Turn spans with prompts and final responses.
- Model call spans reconstructed from the session transcript, with conversation input, response output, and available token metrics.
- Tool spans with inputs, outputs, permission requests, and skill loads.
- 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.
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.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
/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
/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:/hooks.Traces do not appear after setup
Traces do not appear after setup
bt are available to the process that launches Codex, and that you trusted the Braintrust hook through /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 BT_DAEMON_CONFIG 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.Set up the MCP server
Install Codex
Add the Braintrust MCP server
Remove the retired Braintrust MCP plugin (if installed)
Remove the retired Braintrust MCP plugin (if installed)
braintrust plugin. However, the plugin has been retired in favor of Codex’s native MCP configuration. If you installed the plugin, remove it before configuring the direct connection below.Check whether the plugin is still installed:braintrust@braintrust-codex-plugins appears in the installed plugins, remove it:trace-codex tracing plugin.Authenticate
bt login, which authenticates the CLI and tracing integration.Verify the connection
/mcp to confirm that the Braintrust server is connected. Ask Codex to list your recent Braintrust projects and confirm that it uses the Braintrust MCP server.Use MCP tools
Once connected, Codex can query logs, compare experiments, work with datasets, and use other Braintrust tools. For example:- “Show me my recent Braintrust experiments.”
- “Query the last 10 logged requests with errors.”
- “Compare accuracy scores between my two latest experiments.”
Troubleshooting MCP
Braintrust MCP tools do not appear
Braintrust MCP tools do not appear
/mcp and confirm that the Braintrust remote server is registered and connected. Restart Codex after adding or changing the server.MCP authentication or connection fails
MCP authentication or connection fails
codex mcp login braintrust to retry OAuth authentication. If you previously configured API-key authentication, remove bearer_token_env_var from the Braintrust server’s entry in your Codex configuration before switching to OAuth.For authentication methods, regional and self-hosted endpoints, and network requirements, see the Braintrust MCP guide.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.