@thecto/opencode-debug-plugin
v1.6.3
Published
Debug HTTP server plugin for OpenCode with ngrok tunneling support
Downloads
1,171
Maintainers
Readme
OpenCode Debug Plugin
A debug plugin for OpenCode that enables runtime debugging by capturing data from instrumented code. Similar to Cursor's debug mode, this plugin allows the agent to insert fetch calls into your codebase, capture runtime data, and analyze it to identify issues.
Installation
Add the plugin to your OpenCode configuration:
{
"plugin": ["@thecto/opencode-debug-plugin@latest"]
}How It Works
The debug plugin enables a powerful debugging workflow:
- Start Debug Mode — The agent starts a local HTTP server to receive debug events
- Instrument Code — The agent inserts
fetch()calls at strategic locations in your codebase - Reproduce the Issue — You run your code and reproduce the bug
- Analyze Logs — The agent reads the captured data to identify the problem
- Clean Up — The agent removes the debug fetch calls and stops the server
Features
- Runtime Data Capture — Capture function inputs, outputs, state changes, and errors
- Local Debug Server — HTTP server to receive debug events
- Ngrok Tunneling — Expose your debug server publicly for remote/deployed debugging
- Persistent Logging — All debug events are written to
.opencode/debug.log - Agent-Guided Workflow — The agent knows how to instrument code and analyze results
Tools
| Tool | Description |
| -------------- | ----------------------------------------------------- |
| debug_start | Start debug mode and get instrumentation instructions |
| debug_stop | Stop debug mode (remember to remove fetch calls) |
| debug_read | Read and analyze the captured debug data |
| debug_clear | Clear the debug log for a fresh session |
| debug_status | Check if debug mode is active and get the debug URL |
Usage
Starting a Debug Session
When you ask the agent to debug an issue, it will:
debug_startThis starts the debug server and provides the agent with instructions on how to instrument your code.
Instrumentation
The agent will insert fetch calls like this at key locations:
fetch("http://localhost:PORT/debug", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ label: "function-entry", data: { arg1, arg2 } }),
}).catch(() => {});Common instrumentation points:
- Function entry/exit points
- Before/after async operations
- Inside catch blocks for errors
- State changes and variable mutations
- Conditional branches to trace control flow
Reading Debug Data
After you reproduce the issue:
debug_read
debug_read tail=20The agent analyzes the captured data to identify:
- Execution flow
- Unexpected values
- Error locations
- State discrepancies
Stopping Debug Mode
debug_stopThe agent will also remove the fetch calls it inserted.
Enabling Ngrok (Public URLs)
For debugging deployed applications or remote environments:
- Get an authtoken from ngrok.com
- In OpenCode, run:
opencode auth login - Select Other → ngrok
- Enter your ngrok authtoken
Or set the environment variable:
export NGROK_AUTHTOKEN=your_token_hereOnce configured, debug_start automatically creates a public tunnel.
Example Workflow
You: "The checkout function is returning the wrong total"
Agent:
- Calls
debug_start - Reads the checkout code
- Inserts fetch calls to capture cart items, prices, discounts, and the final total
- Says "I've instrumented the checkout function. Please try checking out now."
You: Reproduce the checkout bug
Agent:
- Calls
debug_read - Sees:
cart-items: [...],discount-applied: 0.15,subtotal: 100,final-total: 80 - Identifies: "The discount is being applied twice. The subtotal shows 100 but the final total is 80 instead of 85."
- Fixes the bug and calls
debug_stop - Removes the debug fetch calls
License
MIT
