OpenCode plugins are TypeScript modules that hook into the agent's events, and OpenCode permissions are ordered rules that decide whether an action runs, asks you first, or is denied. Plugins extend what the agent can do; permissions fence what it may do. This post covers a plugin, the hook points around a tool call, the permission rule format, and a guard example built from them — then the check neither of them performs.
a plugin #
A plugin is loaded from the plugins array in opencode.json(c), or discovered automatically under .opencode/plugins/ in the project and ~/.config/opencode/plugins/ globally. The plugins documentation lists the accepted forms: an npm package, a package pinned to a version, a scoped package, or a local directory.
// opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["[email protected]", "./plugins/local"],
}
The CLI manages global packages: opencode plugin add <name> installs one, opencode plugin list shows the plugins list, opencode plugin update updates outdated packages, and opencode plugin remove takes one out. A - prefix in the config disables a plugin by ID or wildcard, so "-acme.reviewer" switches one off without deleting it.
One version note matters before you copy any example. OpenCode 2 renamed the plugin package and the permission fields: the current API is @opencode/plugin with Plugin.define, while OpenCode 1 plugins export a function and import @opencode-ai/plugin. The V1 documentation and the migration guide cover the old form. The examples below use the current API.
The hook points around a tool call #
OpenCode hooks are the places where a plugin can inspect or change what the agent does. The server plugin reference documents three that matter for safety:
ctx.tool.hook("execute.before", ...)runs before a tool executes, with the tool's input.ctx.permission.hook("evaluate", ...)runs after the configured permission rules are evaluated and before the action runs or a prompt is shown. It can change the decision toallow,askordeny, and set the message the agent sees.ctx.tool.hook("execute.after", ...)runs after the tool, with its result or its error.
Two properties of the evaluate hook shape what a guard can do. It runs only for allow and ask decisions — an explicit configured deny is final and never reaches the hook. And its message becomes the denial reason the model reads, so a denied call can explain itself instead of failing silently.
Permission rules #
A permission rule has three fields: an action (what kind of operation), a resource (the path, command or URL it touches) and an effect (allow, deny or ask). The permissions documentation defines the evaluation: rules are combined in order and the last matching rule wins, so specific exceptions follow the broad rule they carve out.
{
"permissions": [
{ "action": "shell", "resource": "*", "effect": "ask" },
{ "action": "shell", "resource": "git status *", "effect": "allow" },
{ "action": "shell", "resource": "git diff *", "effect": "allow" },
{ "action": "shell", "resource": "git push *", "effect": "deny" },
],
}
The built-in actions cover read, edit, shell, glob, grep, webfetch, websearch, subagent and skill, among others; an MCP tool matches as <server>_<tool>. Patterns use whole-value wildcards: * matches any characters including /, and a shell pattern ending in * also matches the command without arguments. When one operation checks several resources, any deny denies it, otherwise any ask asks.
Every agent starts from a base policy that allows everything and asks only for .env reads, with .env.example allowed again. That default is the answer to the question people ask as "opencode dangerously skip permissions": OpenCode has no such flag, because the default already runs most actions without prompting. The work is the opposite of Claude Code's — you add ask and deny rules to tighten a permissive default, rather than allow rules to loosen a prompting one. If you want the fully unattended posture explicit, it is one rule, { "action": "*", "resource": "*", "effect": "allow" }, and it removes the .env guardrail too.
Rules can also sit under agents.<id>.permissions. Agent rules are appended after the global array, not substituted for it, and a custom subagent uses its own permissions rather than a subset of its parent's. OpenCode 1 used different names — permission, bash and task where version 2 uses permissions, shell and subagent — so check which version a config example was written for.
A guard example #
Rules match patterns; a plugin can read the call. This guard denies force-pushes whatever branch they target, using the documented evaluate hook. It is built from the hook contract rather than run against a live install, so treat it as a starting point:
// .opencode/plugins/no-force-push/index.ts
import { Plugin } from "@opencode/plugin"
export default Plugin.define({
id: "no-force-push",
setup(ctx) {
ctx.permission.hook("evaluate", async (event) => {
if (event.action !== "shell") return
const forced = event.resources.some((cmd) =>
/git\s+push\s+.*(--force|-f)(\s|$)/.test(cmd),
)
if (forced) {
event.effect = "deny"
event.message = "Force-push is not allowed in this repository."
}
})
},
})
The directory loads automatically under .opencode/plugins/. A configured deny rule for git push * would stop every push before this hook runs; the hook earns its place where the pattern is narrower than the rule — here, ordinary pushes stay allowed and only forced ones are denied, with a reason the agent can act on.
What rules and hooks cannot check #
A permission rule answers "may this action run". A hook answers whatever its code asks. Neither answers "is this what the developer asked for" — a call can pass every rule and still break a rule you stated in words, such as "do not touch the billing module". That gap is the one our Claude Code benchmark measured: rules from an earlier session were broken 47 times per 100 requests, and 4 times with Besydr.
Besydr (say: besider) is a program that runs beside a coding agent and learns from its sessions. On OpenCode it connects as a plugin: besydr install opencode writes one file that runs Besydr at eight events, repeating your stated rules with each request and checking proposed calls against your words. Two limits are documented honestly in the client table: the plugin targets the OpenCode 1.x plugin interface (checked with 1.19.5) and has not been checked against OpenCode 2, and no OpenCode plugin hook stops a prompt, so Besydr cannot block one there. A one-shot opencode run also ends before the completion check can send the agent back; opencode serve and opencode run --attach do continue. The local program is free with octomind and needs a licence with OpenCode after a trial.
Sources and method #
- Plugin , CLI and version differences: the plugins ,building plugins andV1 plugins pages, read 2026-11-30.
- Hook contract and the guard example: the server plugin reference , read 2026-11-30. The example follows the documented API; it was not executed for this post.
- Rule format, defaults and agent rules: the permissions page , read 2026-11-30.
- Besydr's OpenCode adapter and its limits: the install andclients documentation. The 47-to-4 number comes fromour benchmark , five projects, three runs per setup.
- This post was drafted with AI assistance from these sources.