TheDocumentation Index
Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
Use this file to discover all available pages before exploring further.
@langchain/langsmith-opencode plugin sends OpenCode session traces to LangSmith. Use it to inspect agent turns, model metadata, token usage, tool calls, tool errors, attachments, and subagent activity from your OpenCode workflows.
Prerequisites
Before setting up tracing, ensure you have:- OpenCode installed and configured.
- A LangSmith API key.
- Access to configure the OpenCode
pluginkey inopencode.jsonor~/.config/opencode/opencode.json.
Install and enable the plugin
Add the plugin to your OpenCode configuration file. You can configure it locally inopencode.json or globally in ~/.config/opencode/opencode.json:
Configure tracing
Tracing is disabled by default. WithTRACE_TO_LANGSMITH=true set, the plugin sends traces to LangSmith. You can also enable tracing with a LangSmith config file.
Environment variables
The plugin reads OpenCode-specific 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 | Conditional | - | 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. |
Config files
Use.opencode/langsmith.json for project-level 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 | Conditional | - | 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 | - | Additional LangSmith destinations to replicate traces to. |
Trace to multiple destinations
Setreplicas in langsmith.json or LANGSMITH_OPENCODE_RUNS_ENDPOINTS to send the same trace data to additional LangSmith workspaces or projects.
| Field | Description |
|---|---|
api_url / apiUrl | LangSmith API URL for the replica destination. |
api_key / apiKey | API key for the destination workspace. |
project / projectName | Project name in the destination workspace. |
updates | Optional run fields to override on replicated runs, such as extra metadata. |
What gets traced
The plugin listens to OpenCode chat and event hooks, aggregates each completed user turn, and submits it to LangSmith as a run tree.opencode.sessionroot runs for completed user turns.opencode.assistant.turnchild runs for assistant and model responses.- Nested tool runs for tool calls, including inputs, outputs, errors, timing, and attachments when available.
- Subagent sessions nested under the parent tool call.
- Model name, provider, invocation parameters, token usage, and thread or session ID metadata.
- User messages, assistant messages, reasoning blocks, file parts, and system prompts associated with assistant turns.
step-finish events. The plugin also flushes pending trace batches when the OpenCode server shuts down.
View traces in LangSmith
Open the configured LangSmith project and look for root runs namedopencode.session. Each trace contains the user turn as the root input and assistant responses, tool calls, and subagent traces as child runs. The plugin stores the OpenCode session ID as thread_id metadata, so you can filter or group related OpenCode turns in LangSmith.
Troubleshooting
If traces do not appear in LangSmith:- Confirm tracing is enabled with
TRACE_TO_LANGSMITH=trueor"enabled": truein config. - Confirm the LangSmith 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 selected LangSmith project. 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. The plugin does not send incomplete turns.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

