- Trace OpenCode sessions: Log OpenCode sessions to Braintrust. The same plugin can also register built-in Braintrust tools that call
bt. - Connect to the Braintrust MCP server: Configure OpenCode’s MCP client for Braintrust data access. This is separate from the plugin’s built-in tools.
Trace OpenCode sessions
The@braintrust/trace-opencode plugin traces OpenCode sessions to Braintrust by observing OpenCode, not by proxying it:
- OpenCode talks to its model provider directly.
- Native events notify the plugin when sessions start, turns run, models respond, and tools execute.
- The plugin uses the
btCLI to build and send traces to Braintrust. - Authentication happens through
bt login. The plugin never handles credentials. - If the plugin or
bthas a problem, OpenCode keeps working. However, you won’t see traces until the setup is fixed.
Set up tracing
Upgrading from
@braintrust/trace-opencode before v1.0.0? See Upgrade.1
Install OpenCode
If you haven’t already, install OpenCode.
2
Install bt and authenticate
Tracing runs through You can also install with mise or npm, or with PowerShell on Windows.
bt, and the OpenCode plugin does not install it for you. Install the CLI and authenticate:3
Configure the plugin
After This command:
bt is installed and authenticated, run the following command:- Adds
@braintrust/trace-opencode@^1to your OpenCode configuration file. - Selects a project.
- Enables tracing.
To learn what this command writes and how to change it later, see Settings.
4
Restart OpenCode
Restart OpenCode so it loads the plugin and tracing settings.
5
Log a test trace
Start a short OpenCode session and ask it to do something simple. When the session finishes, open your Braintrust project and check that the trace appears in Logs.
What gets traced
OpenCode traces in Braintrust include:- Session spans with
session_id,source, Git repository metadata, and parent session fields for subagents. - Turn spans with prompts, model names, 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 OpenCode runs the
skilltool, the span is namedskill: <name>. - Subagent session spans nested under their parent session.
braintrust.plugin.opencode.
Settings
bt trace setup opencode saves your tracing configuration to ~/.config/opencode/braintrust.json. These saved settings control where traces go during normal OpenCode sessions.
Notes:
- For OpenCode tracing, environment variables override saved settings. The project config (
.opencode/braintrust.json) overrides the global config (~/.config/opencode/braintrust.json). - 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.
Common workflows
Use custom settings for one run
Use custom settings for one run
To apply custom settings to a single OpenCode run, launch OpenCode with This command can send one run to a different project, profile, or organization without changing the saved settings in
bt trace run:~/.config/opencode/braintrust.json.Built-in Braintrust tools
In addition to tracing sessions,@braintrust/trace-opencode can register built-in Braintrust tools in OpenCode. These tools let OpenCode query Braintrust data through bt during a session, without a separate MCP server configuration.
The plugin registers the tools by default (enable_tools is true). bt owns authentication and API access. To trace sessions without giving OpenCode access to these tools, set enable_tools to false.
braintrust_query_logs- Execute SQL queries against Braintrust logs.braintrust_list_projects- View organization projects.braintrust_get_experiments- Access recent experiments.
- “Can you show me the last 10 logs from Braintrust?”
- “List my Braintrust projects”
- “Query logs where
scores.Factuality < 0.5” - “Show me my recent experiments”
Upgrade
To get the latestbt and @braintrust/trace-opencode, follow these steps. If you are upgrading from @braintrust/trace-opencode before v1.0.0, the steps also cover the required migration.
1
Update bt
Update
bt before updating @braintrust/trace-opencode.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/trace-opencode 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 OpenCode traces. This updates OpenCode’s plugin pin and writes the latest tracing settings.
Before v1.0.0, the plugin read the destination project from the top-level
project key in ~/.config/opencode/braintrust.json or your project’s .opencode/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 this value automatically.4
Migrate settings from a plugin version before v1.0.0
If you are upgrading from a plugin version before v1.0.0, use this table to migrate environment variables and settings from
~/.config/opencode/braintrust.json or your project’s .opencode/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 plugin is listed in your OpenCode configuration file.
- Verify tracing is enabled: in
~/.config/opencode/braintrust.jsonand any project-level.opencode/braintrust.json, confirm thattrace_to_braintrustistrueandroute.destinationnames the intended project. - Restart OpenCode after any configuration change.
- Enable debug mode with
BRAINTRUST_DEBUG=trueand check the OpenCode logs.
Plugin does not load
Plugin does not load
- Check the OpenCode config documentation for config file locations.
- Confirm the
pluginfield is an array and includes@braintrust/trace-opencode@^1. - Restart OpenCode after changing configuration.
Connect to the Braintrust MCP server
OpenCode can use Braintrust’s MCP server to access your projects, experiments, and logs. This is separate from the plugin’s built-in tools.Set up the MCP server
1
Install OpenCode
If you haven’t already, install OpenCode.
2
Add the Braintrust MCP server
Edit your OpenCode configuration file and add the Braintrust MCP server:Replace
YOUR_BRAINTRUST_API_KEY with your actual API key.3
Restart OpenCode
Restart OpenCode to apply the configuration changes.
The example uses
https://api.braintrust.dev/mcp (US data plane). If your organization is on the EU data plane, use https://api-eu.braintrust.dev/mcp.Use MCP tools
Once configured, OpenCode can access Braintrust data through the MCP server. You can fetch experiment results, query logs, log data, and more. See MCP documentation for details. Example prompts in OpenCode:- “Show me my recent Braintrust experiments”
- “Query the last 10 logged requests with errors”
- “What’s the average latency for the summarizer prompt today?”
- “Compare accuracy scores between my two latest experiments”
Troubleshooting
MCP server does not appear
MCP server does not appear
- Verify the JSON syntax in your OpenCode configuration file.
- Verify the URL is
https://api.braintrust.dev/mcporhttps://api-eu.braintrust.dev/mcp, with no trailing slash. - Restart OpenCode after configuration changes.
MCP authentication fails
MCP authentication fails
- Verify your API key is correct and has access to Braintrust.
- Check the authorization header format:
"Authorization": "Bearer YOUR_BRAINTRUST_API_KEY".
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 plugin source code.