@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.
For example:
Config files
Use.opencode/langsmith.json for project-level settings or ~/.config/opencode/langsmith.json for global defaults.
Keep config files that include API keys out of version control.
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.
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.

