OpenCode
OpenCode plugin
A plugin's tools, with OpenCode's permission rules checked before every write.
- name
- text_slug
- permission
- none, it's a read
- input
- text, separator
- failure
- thrown
Access
- Import
import { registerOpencodeTools } from "@agntn/tools/opencode" - Peer
@opencode/plugin >=2.3.0 <3 - Fails
thrown
Call registerOpencodeTools(ctx, tools) from @agntn/tools/opencode inside your plugin's setup, and await it there. The plugin's default export is { id, setup }. @opencode/plugin is only needed for its types. OpenCode hands over everything else at runtime.
import { registerOpencodeTools } from "@agntn/tools/opencode";
import { tools } from "./dist/tools.mjs";
export default {
id: "mypackage",
async setup(ctx) {
await registerOpencodeTools(ctx, tools);
},
};
Writes don't ask by default
A write doesn't mean a question. In OpenCode 2.3.2, the default rules let it run without asking anybody. That's a reckless default for a tool that writes.
Any tool whose effect isn't read meets the permission rules under its own name, just like an MCP tool. Want OpenCode to ask every time? Add an ask rule for that name:
{
"plugin": ["/path/to/mypackage"],
"permission": {
"notes_write": "ask"
}
}
A read never asks. And deny removes the tool from what the model can see.
In a non-interactive opencode run, ask means rejection:
permission requested: notes_write (*); auto-rejecting
With --auto, the call is approved instead.
Tools live in Code Mode
In OpenCode 2.3.2, plugin tools land in Code Mode by default. They aren't separate tools in the model's view. The model calls them as tools.<name>(...) from OpenCode's own execute tool.
Failures don't look like success
Duplicate names aren't welcome. Two tools with the same name throw a ToolDefinitionError at registration.
Arguments are checked against the schema before the permission question. Nobody has to approve a typo. Bad input throws the same lines as every host.
When execute returns isError: true, its text is thrown. OpenCode records a failed call. Thrown errors also carry the same caused by: lines as MCP in their message.
What the model reads
Text stays text. Images go out as file parts with a data: URI.
An empty result needs a little help. With no content blocks, the result is an empty string "". Otherwise OpenCode shows the model an empty list as "undefined". That's not much of an answer.
details becomes the call's metadata. An object goes as is. Anything else, including an array or string, goes under a details key.
Progress, cancellation and questions
Progress goes where OpenCode expects it. progress?.(message, { progress, total }) reaches OpenCode's context.progress. OpenCode's call signal becomes the tool's signal.
host is OpenCode's own call context, handed over untouched. It contains sessionID, agent and messageID.
There's no ask on OpenCode. It's undefined, just like on the CLI and AI SDK. See ask for the tool's question interface. OpenCode's permission question is a separate thing.