OpenCode

Make OpenCode wait for a person's yes before every shell command, file change, web fetch and MCP tool call: a plugin set up in one command, verified in OpenCode 1.19.6.

With no permission settings, OpenCode runs shell commands and edits files without asking. In our runs, opencode run wrote a file with echo and nobody was asked. You can set a tool to ask, but opencode run answers every ask with a no, and --dangerously-skip-permissions answers every ask with a yes. Neither is a person deciding. The VariantGate plugin puts one in: every shell command, file change, web fetch and MCP tool call waits for a yes from the inbox, a phone notification, Slack or email. Rules answer the routine ones, and every answer lands on the same record as your other agents.

The quick way: one command

With Node.js on the computer it runs on, this does both steps for you. It opens the browser to sign in (or to make your free account), saves an agent key on this computer, and adds the approval hook to ~/.config/opencode/plugins/variantgate.js, keeping the old file beside it:

npx -y https://variantgate.com/sdk/variantgate-agent-0.15.0.tgz setup opencode

Restart OpenCode and ask it to run echo hello: the command waits until you approve it in the inbox, and so does every file change, web fetch and MCP tool call. A no blocks that one call. A file it cannot change safely, such as one with comments or one that links elsewhere, is left alone, and the command prints the entry to add yourself. The steps below do the same by hand.

1. Create a key

Sign in, open Agents and create a key for OpenCode. Copy it: it is shown once. Put it in your shell profile, such as ~/.zshrc, as export VARIANTGATE_KEY=….

2. Add the plugin

Install the variantgate command (more on the SDK page):

npm install -g https://variantgate.com/sdk/variantgate-agent-latest.tgz

The hook reads VARIANTGATE_KEY from the environment OpenCode starts in, or a key saved on this computer:

Or run variantgate login once on this computer instead. It opens the browser, you check a code and press Connect, and it saves a new agent key in ~/.config/variantgate/credentials.json, readable only by you. The hook uses that key, with the API address it was made for, whenever VARIANTGATE_KEY is not set. The MCP server still needs the key from step 1.

OpenCode has no hook commands. It has plugins: JavaScript files it loads from ~/.config/opencode/plugins when it starts. The VariantGate plugin is one file with nothing to install. Before each tool call it runs variantgate hook opencode, and anything but a yes blocks the call. This prints the whole file, to save under that folder as variantgate.js:

variantgate setup opencode --print

The part that decides:

const HOOK = "variantgate hook opencode";

export const VariantGate = async ({ client, directory }) => {
  // ...
  return {
    "tool.execute.before": async (input, output) => {
      if (LOOK_ONLY.has(input.tool)) {
        return;
      }
      const answer = await ask({
        args: output.args,
        directory,
        mcpServers: await mcpServers(),
        tool: input.tool,
      });
      if (answer?.decision !== "allow") {
        throw new Error(`VariantGate: ${answer?.reason ?? "not approved."}`);
      }
      freeze(output.args);
    },
  };
};

The plugin lets the tools that only look, plan or talk to you go ahead at once, without a request: read, glob, grep, list, lsp, todoread, todowrite, question, task, invalid. A task starts a subagent, and each of the subagent’s own calls goes through the plugin; in our runs a subagent’s shell command was asked about like any other. Any other tool, including one a later version adds, waits for a yes. The check is by name, so a tool from another plugin that takes one of those names goes ahead too: give a tool that changes things a name of its own. The hook gets the call on stdin:

{
  "opencode": {
    "tool": "bash",
    "args": { "command": "npm test", "description": "Run the tests" },
    "directory": "/home/ada/shop",
    "mcpServers": ["my.shop"]
  }
}

Each call becomes a request with an action name that rules can match:

shell.run
A bash call, with the command and the project folder. The same name the Claude Code, Codex, Gemini CLI, Cursor, Copilot and Cline hooks use, so one rule covers them all.
file.write
A write call, with the file's path and text.
file.edit
An edit, multiedit, patch or apply_patch call.
web.fetch
A webfetch call, with the address.
web.search
A websearch or codesearch call, with the query.
mcp.<server>.<tool>
A call to an MCP tool, named after the server in your OpenCode config: mcp.my%2Eshop.refund_order for OpenCode's my_shop_refund_order.
tool.<name>
Any other tool, such as skill, one a later OpenCode version adds, or one from another plugin.

A no blocks one call

When a plugin throws before a tool runs, OpenCode does not run it and hands the model the error as the tool’s result. The session goes on, so the model learns why and can carry on with the rest of the work:

✗ echo ran > marker.txt failed
Error: VariantGate: Not approved: denied (Not this one.). Do not try another way to do this.

The reason the person typed in the inbox is in that message. An approval with changes is a no for the call as it was asked, and the message says what was approved instead, so the model can make that call, which is asked about again.

What OpenCode does when a plugin fails

We ran the plugin in OpenCode 1.19.6 with opencode run, against a scripted model and a local copy of the service:

  • OpenCode waits for a plugin as long as it takes: one that slept for 400 seconds was waited for. So a person gets five minutes by default, and VARIANTGATE_OPENCODE_HOOK_WAIT sets another number of seconds. After the wait the request is withdrawn and the call blocked.
  • If the service cannot be reached, no key is set or saved, or the hook cannot start, prints something else or exits with an error, the plugin blocks the call.
  • --dangerously-skip-permissions does not skip the plugin: it runs before OpenCode’s own permission check.
  • The one gap: OpenCode skips a plugin that throws while it loads, or that does not parse, and then runs every call without it. That is why the plugin imports nothing but Node’s own child_process and does nothing until a call is made. If you edit the file, run one call and check that it is asked about. Running setup opencode again replaces a plugin an earlier version wrote.

OpenCode’s plugin API also has a permission.ask hook. In 1.19.6 OpenCode never called it in our runs, so the plugin does not rely on it.

MCP tool names

OpenCode names an MCP tool after its server and the tool, joined by an underscore, with characters other than letters, digits, _ and - made _: the tool refund_order on a server called my.shop is my_shop_refund_order. That name alone cannot say where the server ends, so the plugin asks OpenCode for the MCP servers in its config and sends their names to the hook. When one server’s name fits the start of the tool’s, that is the server, and the request gets the mcp.<server>.<tool> action the other hooks send, here mcp.my%2Eshop.refund_order (a dot in a name is escaped). The server names are only used for that; they are not sent to the service. When two servers’ names both fit, such as aws and aws_admin for aws_admin_list, the request is asked under the whole name, mcp.aws_admin_list, so no rule written for one server’s tools can approve the other’s. If the plugin cannot read OpenCode’s config, it blocks any tool that is not one of OpenCode’s own, rather than ask about it under a name a rule might mistake. The plugin reads the list once, so restart OpenCode after you add an MCP server. Tools from other plugins share the same names: a plugin tool whose name starts with an MCP server’s, such as github_sync beside a github server, is asked about as that server’s tool.

The plugin puts every call in front of a person, including calls to the approvals MCP server if you add it to OpenCode as well, so use one or the other.

In scripts and CI

opencode run has nobody at the terminal, and with no permission settings it asks nobody, so the plugin is the whole approval step there. Give the run a key, and install the variantgate command on the machine so the hook starts fast:

export VARIANTGATE_KEY=...   # a key for this pipeline
opencode run "Fix the failing test and push a branch"

A run that waits for a person holds the pipeline for up to the wait. Plan for a no: the call is blocked and the model is told why, so the task may finish without doing it. Check the result rather than the exit code, which was 0 in our runs either way.

Project plugins

OpenCode also loads plugins from a project’s .opencode/plugins folder and from $OPENCODE_CONFIG_DIR. A plugin runs with your rights, so treat a project’s plugin folder like a change to your pipeline. Once a call is approved, the VariantGate plugin freezes its arguments, so a plugin that runs after it and tries to change the command makes the call fail instead of running something nobody approved; we checked that with a plugin that rewrote an approved command. A second copy of the VariantGate plugin asks about each call twice; OpenCode reads both a plugins and a plugin folder, and setup opencode warns about a copy in the other one.

The terminal app and Windows

We tested opencode run. The terminal app loads the same plugins and runs tools the same way, but we have not tested this plugin there, nor on Windows, where the plugin starts the hook through the system’s shell.

Check that it works

Restart OpenCode and ask it to run echo hello. A request appears in the inbox; deny it and check that hello was not printed. Then ask again and approve it.