opencode-lens
MCP server that enables inspecting, controlling, and safely automating live opencode TUI sessions.
README
opencode-lens
opencode-lens is a local automation bridge for live opencode TUI sessions. It combines an opencode TUI plugin, a Unix-socket HTTP API, an MCP server, a Hermes skill, and optional watchdog scripts so local agents can inspect and safely control running opencode instances without screen scraping.
Recommended GitHub description:
opencode TUI bridge and MCP toolkit for inspecting, controlling, and safely automating live opencode sessions
What It Does
- Discover active opencode TUI instances.
- Read the visible TUI session and status.
- Send prompts to a specific session in the background or switch the visible TUI session.
- Run a single prompt on a specific model with per-message
providerID+modelID. - Read recent messages, diffs, and todo state.
- Bridge opencode interactive questions to Hermes users.
- Approve or deny opencode permission prompts with explicit user intent.
- Close accidentally opened TUI overlays such as the model selector.
- Monitor instances for pending permissions, questions, and completion events.
Repository Layout
opencode-lens/
├── packages/
│ ├── plugin/ # opencode TUI plugin; exposes the lens Unix socket API
│ ├── mcp/ # stdio MCP server for Hermes and other MCP clients
│ └── shared/ # shared registry/types/discovery helpers
├── scripts/ # optional watchdog scripts
├── skill/ # Hermes/OpenClaw skill instructions
├── docs/ # HTTP API notes
├── package.json # Bun workspace
├── tsconfig.json
├── bun.lock
└── LICENSE
Architecture
Hermes / MCP client
└─ opencode-lens-mcp (stdio MCP server)
├─ discovers active lens registry files
├─ talks HTTP over per-user Unix sockets
└─ exposes tools such as instances_list, tui_status, prompt_send
opencode TUI process
└─ opencode-lens plugin
├─ writes an instance registry file
├─ serves HTTP over a Unix Domain Socket
├─ reads live TUI/session state through the opencode plugin API
├─ forwards selected operations through the opencode SDK
└─ publishes status events for automation clients
The plugin does not open a TCP port. Registry files are written under:
~/.local/share/opencode-lens/instances/
Sockets prefer:
$XDG_RUNTIME_DIR/opencode-lens/
and fall back to:
~/.local/share/opencode-lens/sockets/
Requirements
- Bun 1.3+
- opencode with TUI plugin support
- Hermes or another MCP client if you want MCP automation
Install From npm
There are two separate install surfaces:
opencode-lensis an opencode TUI plugin. opencode can install/cache it automatically from npm when it sees the package name in the TUI config.opencode-lens-mcpis a stdio MCP server. Install or run it from the environment where Hermes starts MCP servers.
opencode TUI plugin
Add the npm package name to ~/.config/opencode/tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["opencode-lens"]
}
Restart opencode. opencode will resolve and cache the npm plugin package for the TUI runtime.
You can also install the plugin manually, but this is usually unnecessary for normal opencode plugin usage:
npm install -g opencode-lens
Hermes MCP server
For Hermes, either run the MCP server through npx:
mcp_servers:
opencode-lens:
command: npx
args:
- -y
- opencode-lens-mcp
enabled: true
timeout: 30
connect_timeout: 10
or install it globally:
npm install -g opencode-lens-mcp
and configure Hermes with the installed binary:
mcp_servers:
opencode-lens:
command: opencode-lens-mcp
enabled: true
timeout: 30
connect_timeout: 10
Restart Hermes after installing or updating the MCP package so the tool list is reloaded.
If you want both npm packages installed globally for local development, use:
npm install -g opencode-lens opencode-lens-mcp
The opencode TUI plugin still needs to be registered in tui.json even when globally installed:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["opencode-lens"]
}
Verify npm Packages
Check the published package metadata:
npm view opencode-lens version dist.tarball --registry=https://registry.npmjs.org/
npm view opencode-lens-mcp version bin dist.tarball --registry=https://registry.npmjs.org/
Smoke-test in a clean temporary directory:
mkdir /tmp/opencode-lens-npm-verify
cd /tmp/opencode-lens-npm-verify
npm init -y
npm install opencode-lens opencode-lens-mcp --registry=https://registry.npmjs.org/
The plugin bundle depends on Bun runtime features used by opencode, so validate import with Bun rather than Node:
bun --eval 'const plugin = await import("opencode-lens"); console.log(Object.keys(plugin).join(","));'
Validate the MCP server by asking it for its tool list:
printf '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"verify","version":"0.0.0"}}}\n{"jsonrpc":"2.0","method":"notifications/initialized","params":{}}\n{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}\n' | npx opencode-lens-mcp
Development
bun install
bun run typecheck
bun test
bun run build
Build standalone MCP binaries when needed:
bun run build:mcp:binaries
Install The TUI Plugin From Source
Build the plugin:
bun run --cwd packages/plugin build
Install the built plugin into opencode's TUI plugin directory:
mkdir -p ~/.config/opencode/plugins
cp packages/plugin/dist/index.js ~/.config/opencode/plugins/opencode-lens.js
Register it in ~/.config/opencode/tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["./plugins/opencode-lens.js"]
}
Restart opencode after changing the plugin bundle. Already-running opencode TUI processes keep the old plugin code loaded.
Configure Hermes MCP
If you installed from npm, use command: opencode-lens-mcp as shown above. For source checkouts, build the MCP server:
bun run --cwd packages/mcp build
Example Hermes MCP configuration:
mcp_servers:
opencode-lens:
command: /path/to/bun
args:
- /path/to/opencode-lens/packages/mcp/dist/opencode-lens-mcp.js
enabled: true
timeout: 30
connect_timeout: 10
Restart Hermes after changing MCP tools. MCP tools are registered when Hermes starts.
Install The Hermes Skill
Copy the skill into Hermes:
mkdir -p ~/.hermes/skills/opencode-lens
cp skill/SKILL.md ~/.hermes/skills/opencode-lens/SKILL.md
rm -f ~/.hermes/.skills_prompt_snapshot.json
The skill tells Hermes agents how to use the MCP tools safely. In particular, it requires concise status tables, explicit permission choices, per-message model selection, and safe handling of interactive questions.
Optional Watchdog Scripts
Copy the watchdog scripts if you want polling-based notifications:
mkdir -p ~/.hermes/scripts
cp scripts/opencode-watch.py ~/.hermes/scripts/opencode-watch.py
cp scripts/opencode-watch-loop.sh ~/.hermes/scripts/opencode-watch-loop.sh
chmod +x ~/.hermes/scripts/opencode-watch.py ~/.hermes/scripts/opencode-watch-loop.sh
Run one poll:
~/.hermes/scripts/opencode-watch.py
Run a simple polling loop:
~/.hermes/scripts/opencode-watch-loop.sh
Useful environment variables:
OPENCODE_LENS_SOCKET_DIR defaults to $XDG_RUNTIME_DIR/opencode-lens or /run/user/$UID/opencode-lens
OPENCODE_WATCH_STATE_FILE defaults to ~/.hermes/opencode-watch-state.json
OPENCODE_WATCH_LIST_FILE defaults to ~/.hermes/opencode-watch-list.json
OPENCODE_WATCH_LOCK_FILE defaults to ~/.hermes/opencode-watch.lock
OPENCODE_WATCH_SCRIPT used by opencode-watch-loop.sh
MCP Tool Highlights
instances_list: list active opencode lens instances.tui_status: read the visible TUI session/status for an instance.prompt_send: send a prompt to a target session; supports per-message model parameters.messages_read: read recent messages for a session.tui_session_switch: switch the visible TUI session.question_respond/question_reject: answer or dismiss opencode interactive questions.permission_respond: reply to permission prompts withallow,always, ordeny.model_selector_close: close the currently open TUI overlay/dialog when the runtime exposesapi.ui.dialog.clear().
Model Selection
opencode 1.17.x chooses the model per message. The reliable workflow is:
- Call
models_list. - Match the desired provider/model IDs.
- Send the prompt with
prompt_sendandproviderID+modelID.
Do not rely on moving the TUI's visible model indicator. The plugin API does not provide a stable way to set that indicator to an arbitrary model by ID.
Permission And Question Safety
Permission replies are high-risk. Always show the user the requested operation and ask for one of three choices:
allow onceallow alwaysdeny
Interactive questions are separate from permissions. They must be answered with question_respond; sending normal prompt text does not select an option.
Troubleshooting
- No instances: confirm
~/.config/opencode/tui.jsonloads./plugins/opencode-lens.js, then restart opencode. - MCP tool missing: rebuild
packages/mcp, then restart Hermes. - Plugin behavior did not change: restart the target opencode TUI process.
- Prompt returns
409 session_busy: inspecttui_status; the session may be running, waiting for a question, or waiting for permission. - Permission prompt does not appear: the target opencode permission rules may be configured as auto-allow instead of ask.
- Status reads time out: the plugin caps slow opencode SDK calls and returns structured timeout errors instead of Bun's default 10-second server timeout.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.