GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing docs.braintrust.dev — OpenCode - Braintrust OpenCode is an open-source AI coding assistant. You can connect it to Braintrust in two ways:
Trace OpenCode sessionsThe@braintrust/trace-opencode plugin uses bt to trace your OpenCode sessions to Braintrust. The plugin also provides built-in Braintrust tools, independently of MCP.
Set up tracingIf @braintrust/trace-opencode is already installed, follow Update the tracing plugin.1 Install OpenCode If you haven’t already, install OpenCode. The plugin requires OpenCode v1.2.25 or later. To trace OpenCode 2 ( @opencode/cli), use plugin v2.2.0 or later with bt v0.31.0 or later. The setup steps are the same for both versions.2 Install and authenticate bt Follow the bt CLI quickstart to install bt v0.19.3 or later, authenticate, and set your active context.3 Enable tracing Before starting OpenCode, run this command in a terminal:
XDG_CONFIG_HOME is set, both configuration files are under $XDG_CONFIG_HOME/opencode/ instead. A repository’s settings can override the global tracing settings. See Share tracing settings in a repository.For more information, see bt trace enable.4 Restart OpenCode Restart OpenCode so it loads the plugin and tracing settings. 5 Log a test trace Ask OpenCode to do something simple. When the session finishes, open your Braintrust project and confirm that the trace appears on the Logs page. What Braintrust tracesOpenCode traces in Braintrust include:
braintrust.plugin.opencode, along with versions in context.span_origin: the plugin version in version, the bt version in bt.version, and the OpenCode version in opencode.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 bt trace run to trace a single OpenCode invocation without changing the saved tracing configuration.This workflow launches OpenCode from the terminal. With bt v0.31.0 or later, bt runs opencode --version first to detect the OpenCode version, and stops if the output isn’t a recognized OpenCode 1 or 2 version. For OpenCode 2, bt adds --standalone so the session runs on its own private server, except for opencode serve, which already starts one. bt rejects --server and --service for OpenCode 2.To change the saved destination, profile, or organization, rerun bt trace enable opencode 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.
Share tracing settings in a repository With plugin v2.3.0 or later, OpenCode reads repository tracing settings from .braintrust.json at the root of the Git repository that contains the session’s working directory. Outside a Git repository, it reads .braintrust.json in the working directory. The coding-agent integrations share this file, so committing it opts the repository into tracing for every supported agent. The file stores settings, not credentials, so each developer still needs the plugin installed and bt authenticated.With bt v0.33.0 or later, create the file from anywhere in the repository:
.opencode/braintrust.json instead, and a project route object replaced the entire global route object. Plugin v2.3.0 doesn’t read .opencode/braintrust.json. Move any settings you still need into .braintrust.json at the repository root.
Resume an OpenCode session With plugin v2.1.1 or later, when you resume an OpenCode session, new turns are added to its existing Braintrust trace. Earlier versions start a new trace each time OpenCode restarts.
Stop tracing OpenCode sessions With bt v0.33.0 or later, bt trace disable opencode pauses tracing and keeps the plugin and its global tracing configuration. Run bt trace enable opencode to resume.To remove the tracing plugin from the global OpenCode configuration and remove its global tracing configuration, use bt trace uninstall opencode. In earlier versions of bt, bt trace disable opencode removes them instead. Saved bt profiles and credentials are preserved. Restart OpenCode after uninstalling.Removing the plugin also removes its built-in Braintrust tools. To stop tracing while keeping those tools, use bt trace disable opencode with bt v0.33.0 or later. In earlier versions, set trace_to_braintrust to false in the effective tracing file instead.If you also registered the plugin in a project configuration, remove that registration to stop tracing there.Built-in Braintrust toolsThe tracing plugin also registers tools that callbt to access Braintrust data, without an MCP connection:
enable_tools to false in the global or repository tracing file. BRAINTRUST_OPENCODE_ENABLE_TOOLS overrides that setting.
The tools run bt from your PATH. To run a different bt executable, set BRAINTRUST_BT_BIN to its path in the environment that launches OpenCode. This variable requires plugin v2.1.1 or later. Earlier versions read BT_EXECUTABLE, which v2.1.1 accepts as a deprecated fallback.
Update the tracing pluginTo update the plugin, follow these steps:If opencode debug config shows @braintrust/trace-opencode earlier than v2.0.0 in the plugin list, or you cannot determine its version, follow Migrate from an older plugin version.1 Update bt Follow the CLI migration guide to update bt to the latest version and complete the applicable migrations.2 Update the tracing plugin bt trace update updates the plugin’s package specification in the global OpenCode configuration without changing your saved tracing configuration.3 Restart and verify OpenCode Restart OpenCode, run a short session, and confirm that its trace appears on the Logs page in the intended Braintrust project. Migrate from an older plugin versionTo migrate to the latest version of the@braintrust/trace-opencode plugin, follow these steps:
1 Inspect your OpenCode plugins Inspect your active OpenCode configuration and find @braintrust/trace-opencode in the plugin list:.opencode/braintrust.json.If the plugin is not installed, follow Set up tracing. If you cannot determine the installed version from its configured version range, complete both migration sections below. 2 Install or update bt These steps require bt v0.19.3 or later. Check whether bt is installed:
3 Complete version-specific migration steps Complete each section for a version newer than your starting @braintrust/trace-opencode version, beginning with the oldest. If no sections apply, continue to the next step.
@braintrust/trace-opencode v1.0.0 Complete this section if you started your migration from a plugin version earlier than v1.0.0. bt handles both, and the tracing files store settings rather than credentials.Record project, org_name, and additional_metadata from ~/.config/opencode/braintrust.json and your project’s .opencode/braintrust.json. Environment variables took precedence over these files. Earlier versions did not use XDG_CONFIG_HOME. If the project was not configured, the default was opencode.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/trace-opencode v2.0.0 Complete this section if you started your migration from a plugin version earlier than v2.0.0.
In the next step, pass the recorded project with --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:
route object so you do not leave conflicting copies. Environment variables accepted by bt commands are separate from these plugin changes. See bt trace.4 Apply your tracing settings Run this command with your intended project, using the project you recorded earlier to preserve your destination: --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 ~/.config/opencode/braintrust.json. Check the following settings in that file:
.braintrust.json at the repository root instead of .opencode/braintrust.json. For each project-local file, move the settings that project still needs into .braintrust.json under route, preserving its intended destination, authentication, metadata, and tags. Repository settings override the global file field by field, so include only the values that differ. After moving any legacy values under route, remove their duplicate top-level keys so they cannot override it. See Share tracing settings in a repository.5 Restart and verify OpenCode Restart OpenCode, run a short session, and confirm that its trace appears on the Logs page in the intended Braintrust project. Check each project where you changed local tracing settings. 6 Remove obsolete settings Complete this step only if you started with a plugin version earlier than v2.0.0 and verified that traces reach the intended project in the previous step.
Settings used before @braintrust/trace-opencode v2.0.0 The plugin now reads tracing settings from its configuration files. Environment variables you previously configured for tracing may no longer be needed.Check these locations for leftover settings:
bt commands, MCP connections, or integrations still need:
BRAINTRUST_OPENCODE_ENABLE_TOOLS if you use it to control the built-in tools.Troubleshooting tracingFirst, runbt trace doctor opencode. Then, review the following:
The tracing plugin is missing or disabled Run opencode debug config and confirm that @braintrust/trace-opencode@^2 is in the plugin list. If it is missing or broken, run:
Traces do not appear after setup If OpenCode was running when its plugin or configuration changed, restart it.Run bt trace doctor opencode 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 OpenCode session.
OpenCode uses an unexpected configuration directory Check whether XDG_CONFIG_HOME is set in the environment that launches OpenCode. When it is set, the global tracing file is $XDG_CONFIG_HOME/opencode/braintrust.json instead of ~/.config/opencode/braintrust.json.
Traces use unexpected settings Invocation settings supplied by bt trace run take precedence over the saved tracing configuration. For normal sessions, a repository’s .braintrust.json overrides global settings field by field. See Share tracing settings in a repository. With plugin versions earlier than v2.3.0, project-local .opencode/braintrust.json settings override global settings instead, and a project-level route object replaces the entire global route object.With plugin v2.3.0 or later, if .braintrust.json exists but can’t be read or isn’t valid, normal OpenCode sessions in that repository aren’t traced. Fix or remove the file to resume tracing.The plugin 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 MCPThe Braintrust MCP server lets OpenCode query and update Braintrust data. MCP is configured independently from the tracing plugin and its built-in tools.1 Choose authentication
Use OAuth when your client supports it. Your client opens a Braintrust authorization page where you sign in and approve access. The server acts with the permissions of the account you sign in with.
/.well-known/oauth-authorization-server on the same host as your MCP endpoint (see next step), so a client can register itself.Use an API key for clients without OAuth support or for programmatic connections. The server acts with the permissions of the account the key belongs to.
Your bt login doesn’t authenticate the MCP server.2 Choose your endpoint Use the endpoint for your organization’s data plane region:
3 Add the server to OpenCode Follow the OpenCode guide to add the remote server. 4 Verify the connection To verify the connection, ask OpenCode to list your recent Braintrust projects. If it can’t connect, see Braintrust MCP troubleshooting. 5 Start using Braintrust tools OpenCode can query logs, compare experiments, work with datasets, and use other Braintrust tools. For example:
Next steps
Was this page helpful? | ||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |