npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@braintrust/trace-opencode

v2.1.0

Published

Automatically trace OpenCode conversations to Braintrust. Captures user messages, assistant responses, and tool calls for observability.

Readme

@braintrust/trace-opencode

Trace OpenCode sessions in Braintrust. The plugin sends events to the local bt daemon, which builds and uploads traces. OpenCode keeps running if tracing fails.

  • Session spans: Root span for each OpenCode session with metadata (workspace, hostname, etc.)
  • Turn spans: Captures each user-assistant interaction
  • LLM spans: Records completed model messages with available inputs, outputs, and usage
  • Tool spans: Records individual tool executions with inputs and outputs

Quickstart

Install OpenCode and the Braintrust CLI, then run:

bt login
bt trace enable opencode --project my-coding-agent
opencode

This registers the npm plugin and saves its configuration. Use --profile or --org to choose a profile or organization. Restart OpenCode if it is already open.

For one invocation without changing global tracing configuration:

bt trace run --project my-coding-agent opencode -- run "summarize this repository"

Historical import and live attach are not supported for OpenCode.

Compatibility

The package declares @opencode-ai/plugin and @opencode-ai/sdk peers at >=1.2.25. CI checks package installation at that minimum and at latest, and runs real-agent integration tests with the latest OpenCode CLI.

Configuration

Settings load from these files, with project settings overriding global settings:

  • Global: $XDG_CONFIG_HOME/opencode/braintrust.json, or ~/.config/opencode/braintrust.json if XDG_CONFIG_HOME is unset
  • Project: .opencode/braintrust.json

bt trace run overrides tracing settings for one invocation. Files are merged at the top level: a project route replaces the global route.

{
  "trace_to_braintrust": true,
  "enable_tools": true,
  "route": {
    "auth": { "profile": "work", "org_name": "acme" },
    "destination": { "type": "project_logs", "project_name": "my-project" }
  },
  "debug": true
}

Settings

| Config key | Default | Purpose | |---|---|---| | trace_to_braintrust | false | Enable tracing | | enable_tools | true | Register Braintrust tools; override with BRAINTRUST_OPENCODE_ENABLE_TOOLS | | route.auth.profile_id | unset | Saved profile ID written by bt setup | | route.auth.profile | current bt profile | Select a profile by name | | route.auth.org_name | profile default | Select an organization | | route.destination | project logs in opencode | Select the trace destination | | route.additional_metadata | unset | Add root-span metadata | | route.flush_mode | fire_and_forget in the default route | Control delivery flushing | | debug | false | Enable debug logging; override with BRAINTRUST_DEBUG |

Older files can still use top-level profile, org_name, project, and additional_metadata. For new files, use bt trace enable or the nested route format above. Include a destination when supplying a route.

Only enable_tools and debug read environment variables directly. Tracing settings come from these files or bt trace run.

Disable Braintrust tools

Set enable_tools to false to trace OpenCode sessions without registering Braintrust-branded tools (braintrust_query_logs, braintrust_list_projects, braintrust_log_data, braintrust_get_experiments):

{
  "trace_to_braintrust": true,
  "enable_tools": false,
  "route": {
    "destination": { "type": "project_logs", "project_name": "my-project" }
  }
}

Or use the environment variable:

BRAINTRUST_OPENCODE_ENABLE_TOOLS=false opencode

Add root metadata

Set route.additional_metadata to add fields to the root span:

For one invocation without changing the persistent configuration, use bt trace run --additional-metadata '{"ci": true, "run_id": "abc-123"}' opencode -- run "do the thing", or set BRAINTRUST_ADDITIONAL_METADATA before that command (bt trace run still accepts it; a plain opencode session's plugin does not).

You can also set it via the config file:

{
  "route": {
    "destination": { "type": "project_logs", "project_name": "my-project" },
    "additional_metadata": { "team": "platform" }
  }
}

The value must be a JSON object. Built-in session metadata wins if keys conflict.

Trace structure

The daemon reconstructs sessions, turns, model messages, and tool executions:

Session (task)
├── Turn 1 (task)
│   ├── Model response (llm)
│   ├── Tool execution (tool)
│   └── Model response (llm)
└── Turn 2 (task)

Model usage and metadata are included when OpenCode provides them. Child sessions are attached to their parent's active turn when that relationship is available to the translator.

Manage tracing

bt trace doctor opencode
bt trace status
bt trace update opencode
bt trace disable opencode

Runtime architecture

Tracing sends events to the local daemon over JSON-RPC. The four optional Braintrust tools call bt commands. Both use bt for credentials and API access.

Development

From the monorepo root, run make validate-opencode to build, check, and test the package. See the contribution guide for development instructions. The npm package contains compiled entrypoints; source changes belong in the monorepo.