import type { Metadata } from "next"; import { CodeBlock } from "@/components/code-block"; export const metadata: Metadata = { title: "OpenCode Plugin", description: "Capture OpenCode sessions including tool calls, LLM calls, file edits, and git diffs with the AgentLens OpenCode plugin.", }; export default function OpenCodePluginPage() { return (
The AgentLens OpenCode plugin captures everything that happens during an OpenCode coding session and sends it as structured traces to your AgentLens instance.
Add the plugin to your opencode.json configuration file:
Set the required environment variables:
You can also add these to a .env file in your project root.
Every OpenCode session becomes a trace with nested spans and events for each action taken during the session:
Each OpenCode session is captured as a top-level AGENT span. Includes session ID, start time, end time, and overall status.
Every call to an LLM provider (Claude, GPT, etc.) is recorded with the full prompt, response, token counts, and cost.
Tool invocations including file reads, writes, shell commands, search operations, and MCP tool calls. Captures input arguments and outputs.
Permission requests and grants are captured as decision points, showing what the agent asked to do and whether it was allowed.
Every file creation, modification, and deletion is tracked with before/after content diffs.
Git operations (commits, diffs, branch changes) are captured as events with the full diff content.
A typical OpenCode session trace looks like this:
| Variable | Required | Description |
|---|---|---|
| AGENTLENS_API_KEY | Yes | API key for authentication |
| AGENTLENS_ENDPOINT | Yes | AgentLens server URL |
| AGENTLENS_ENABLED | No | Set to "false" to disable (default: "true") |
| AGENTLENS_SESSION_TAGS | No | Comma-separated tags to add to all session traces |
By default, the plugin captures full file contents and command outputs.
To filter sensitive data, set the AGENTLENS_REDACT_PATTERNS environment variable with a comma-separated list of regex patterns:
Matched content is replaced with [REDACTED] before
being sent to the server.