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

@langchain/langsmith-opencode

v0.0.3

Published

OpenCode plugin for tracing to LangSmith

Readme

@langchain/langsmith-opencode

Trace OpenCode sessions to LangSmith so you can inspect agent turns, tool calls, model metadata, token usage, and subagent activity within LangSmith.

What It Does

@langchain/langsmith-opencode is an OpenCode plugin that listens to OpenCode chat and event hooks, aggregates each user turn, and posts it to LangSmith as a run tree:

  • opencode.session root runs for each completed user turn.
  • opencode.assistant.turn child runs for assistant/model responses.
  • Tool calls as nested tool runs with inputs, outputs, errors, timing, and attachments when available.
  • Subagent sessions as nested traces under the parent tool call.
  • LangSmith metadata for model name, provider, invocation parameters, token usage, and thread/session ID.

Quick Start

Add the plugin to your OpenCode configuration file. You can configure it locally in opencode.json or globally in ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "plugins": ["@langchain/langsmith-opencode"]
}

Set your LangSmith credentials before starting OpenCode:

export LANGSMITH_API_KEY="lsv2_pt_..."
export TRACE_TO_LANGSMITH="true"

Then run OpenCode as usual. Completed turns will appear in the configured LangSmith project.

LangSmith API keys

To create an API key:

  1. Go to smith.langchain.com.
  2. Sign in or create an account.
  3. Open Settings -> API Keys.
  4. Click Create API Key.
  5. Copy the key and set it as LANGSMITH_API_KEY, LANGSMITH_OPENCODE_API_KEY, or api_key in a local config file.

Configuration

Tracing is disabled by default. Enable it with TRACE_TO_LANGSMITH=true or with a config file.

Environment Variables

The plugin accepts OpenCode-specific LangSmith variables first, then falls back to the generic LangSmith SDK variables when available:

| Variable | Required | Default | Description | | ----------------------------------- | -------- | --------------------- | ------------------------------------------------------------------------------------------------------------- | | TRACE_TO_LANGSMITH | Yes | false | Set to "true" to enable tracing. | | LANGSMITH_OPENCODE_API_KEY | No* | - | LangSmith API key. Falls back to LANGSMITH_API_KEY. Required unless every replica provides its own API key. | | LANGSMITH_OPENCODE_ENDPOINT | No | LangSmith SDK default | LangSmith API URL. Falls back to LANGSMITH_ENDPOINT. | | LANGSMITH_OPENCODE_PROJECT | No | opencode | LangSmith project name. Falls back to LANGSMITH_PROJECT. | | LANGSMITH_OPENCODE_METADATA | No | - | JSON object merged into root trace metadata. | | LANGSMITH_OPENCODE_RUNS_ENDPOINTS | No | - | JSON array of replica destinations. |

Example:

export TRACE_TO_LANGSMITH="true"
export LANGSMITH_API_KEY="lsv2_pt_..."
export LANGSMITH_PROJECT="opencode"
export LANGSMITH_OPENCODE_METADATA='{"team":"agents","environment":"dev"}'

Config Files

Use .opencode/langsmith.json in your project for per-project settings, or ~/.config/opencode/langsmith.json for global defaults.

| Field | Required | Default | Description | | ---------- | -------- | --------------------- | -------------------------------------------------------------------------------- | | enabled | Yes | false | Set to true to enable tracing from the config file. | | api_key | No* | - | LangSmith API key. Required unless provided by environment variable or replicas. | | api_url | No | LangSmith SDK default | LangSmith API URL, usually https://api.smith.langchain.com. | | project | No | opencode | LangSmith project name. | | metadata | No | - | Object merged into root trace metadata. | | replicas | No | - | Array of additional LangSmith destinations to replicate traces to. |

{
  "enabled": true,
  "api_key": "lsv2_pt_...",
  "api_url": "https://api.smith.langchain.com",
  "project": "opencode",
  "metadata": {
    "team": "agents",
    "environment": "dev"
  },
  "replicas": [
    {
      "api_url": "https://api.smith.langchain.com",
      "api_key": "lsv2_pt_...",
      "project": "opencode-replica",
      "updates": {
        "metadata": {
          "replica": true
        }
      }
    }
  ]
}

api_key is required unless the API key is provided by environment variable. Keep config files with API keys out of version control.

Replica objects support both snake_case and LangSmith SDK-style camelCase field names. Snake_case is recommended in config files.

| Field | Required | Description | | ------------------------- | -------- | --------------------------------------------------------------------------- | | api_url / apiUrl | No | LangSmith API URL for the replica destination. | | api_key / apiKey | No | API key for the destination workspace. | | project / projectName | No | Project name in the destination workspace. | | updates | No | Optional run fields to override on replicated runs, such as extra metadata. |

What Gets Traced

The plugin captures OpenCode session events and converts them into LangSmith-compatible chat messages and run metadata.

Captured content includes:

  • User messages, assistant messages, reasoning blocks, and file parts.
  • Tool calls, tool results, tool errors, and tool attachments.
  • System prompts associated with assistant turns.
  • Model and provider metadata from OpenCode.
  • Token usage from completed model steps when OpenCode provides it.
  • Session history so each assistant turn has the relevant chat context.

Trace completion is based on OpenCode step-finish events. When OpenCode disposes the server instance, the plugin flushes pending LangSmith trace batches.

Troubleshooting

If traces do not appear in LangSmith:

  • Confirm tracing is enabled with TRACE_TO_LANGSMITH=true or "enabled": true in config.
  • Confirm an API key is set in the same shell, project config, or global config used by OpenCode.
  • Confirm the plugin package is installed where OpenCode can resolve it.
  • Check the project selected in LangSmith. If no project is configured, traces go to opencode.
  • Restart OpenCode after changing opencode.json, langsmith.json, or environment variables.
  • Make sure a user turn completes; incomplete turns are not submitted as complete traces.