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.
Add the plugin to your OpenCode configuration:
{
"plugin": ["@thecto/opencode-debug-plugin@latest"]
}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
- 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
| 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 |
When you ask the agent to debug an issue, it will:
debug_start
This starts the debug server and provides the agent with instructions on how to instrument your code.
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
After you reproduce the issue:
debug_read
debug_read tail=20
The agent analyzes the captured data to identify:
- Execution flow
- Unexpected values
- Error locations
- State discrepancies
debug_stop
The agent will also remove the fetch calls it inserted.
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.
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
MIT