Skip to content
$ shellfirm

OpenCode

An OpenCode plugin that sends shell commands, edits and reads to shellfirm and blocks them unless shellfirm allows them.

Connect

shellfirm connect opencode
Output
shellfirm — connecting OpenCode integration

  /home/dev/.config/opencode/plugins/shellfirm.js:
    - add the OpenCode plugin running `shellfirm check --hook opencode --config-dir /home/dev/.config/shellfirm`
    ✓ written

OpenCode shell commands, file edits and reads are now checked by shellfirm (plugin; dangerous and risky ones are blocked, because the plugin cannot ask). Restart OpenCode.

Restart OpenCode afterwards.

What it installs

A plugin, ~/.config/opencode/plugins/shellfirm.js ($XDG_CONFIG_HOME/opencode/plugins/ when XDG_CONFIG_HOME is set). It starts with // shellfirm-hook: opencode; a file without that line is never replaced.

The plugin's tool.execute.before hook sends bash, write, edit, multiedit, read, apply_patch and patch calls (multiedit and patch are in older OpenCode versions) to shellfirm check --hook opencode as JSON (tool_name, tool_input with the tool's args, session_id, tool_use_id, cwd; a bash workdir is resolved against cwd). multiedit is checked as an edit, and apply_patch and patch file by file: the worst file decides, and the reason names it. The core of it:

~/.config/opencode/plugins/shellfirm.js (excerpt)
const TOOLS = new Set(["bash", "write", "edit", "multiedit", "read", "apply_patch", "patch"])
const TIMEOUT_MS = 30000

export const Shellfirm = async ({ directory, client }) => ({
  "tool.execute.before": async (input, output) => {
    if (!TOOLS.has(input.tool)) return
    // ... run `shellfirm check --hook opencode` with the call as JSON ...
    if (answer && answer.decision === "allow") {
      // An allowed change shellfirm wants reviewed (an agent-instruction edit).
      if (answer.warning) {
        try {
          await client.tui.showToast({ body: { message: answer.warning, variant: "warning" } })
        } catch {}
      }
      return
    }
    if (answer && answer.decision === "deny") {
      throw new Error(answer.reason || "shellfirm blocked this tool call")
    }
    throw new Error(`shellfirm could not check this tool call (...); blocking it. ...`)
  },
})

What OpenCode sees

Only {"decision": "allow"} lets the call run. With a warning (for example the review note of an agent instruction edit such as AGENTS.md), the plugin shows it as a toast. Anything else throws, which blocks the call with shellfirm's reason. The plugin cannot ask, so risky calls are blocked like dangerous ones.

CommandAnswerEffect
No check matches (ls){"decision":"allow"}Runs
Risky (cat ~/.ssh/id_rsa, Medium){"decision":"deny","reason":...}Blocked; the audit log records deny_reason: agent_auto_deny
Dangerous (git push -f origin main, High){"decision":"deny","reason":...}Blocked

Real reason for cat ~/.ssh/id_rsa:

Output
shellfirm BLOCKED this command.
[exfil:read_secret_file] [MEDIUM] This reads a private key or a credentials file. Shown on screen it can leak (screen sharing, terminal logs); run by an AI agent, the secret goes into the conversation and on to the model provider.
BLOCKED: Matched risky pattern(s) (severity MEDIUM, below the auto-deny threshold HIGH); confirm before running (OpenCode cannot ask for confirmation, so shellfirm blocks it; run it yourself if it is intended)
Safe alternative: read only what you need, not the secret itself (An SSH private key: `ssh-keygen -y -f <key>` prints just the public half. A credentials file: a command that hides the secret shows the same, e.g. `aws configure list`, `kubectl config view`, `gh auth status`, `npm config list`.)

The plugin is fail-closed: it also blocks the call when shellfirm cannot run, times out (30 s) or answers something it cannot read. When shellfirm is not on OpenCode's PATH, it runs the binary that connect ran from.

Options

OptionEffect
--scope user (default)~/.config/opencode/plugins/shellfirm.js
--scope project./.opencode/plugins/shellfirm.js
--dry-runShow what would change, write nothing
--uninstallRemove shellfirm's plugin only. A plugin file shellfirm did not write is never removed, and shellfirm status lists it

opencode run --dangerously-skip-permissions started by an agent asks first, like the other hook bypasses (see self-protection).

Check the integration

Output
  Agent integrations:
    opencode (user): hook yes, file tools yes, fail-closed yes, MCP n/a