← GUIDES

GUIDE / SETUP NOTE

Run OpenCode 2 on a Real Repo With Approvals On

OpenCode 2 allows most actions by default. Add ask rules for shell and edits, start in the Plan agent, and review the diff before you commit.

3 Nov 2026Checked 2026-10-28
OpenCode terminal prompt asking the user to approve a shell command, beside a permissions config file

OpenCode by Anomaly and the OpenCode contributors, MIT license, v2.2.0 (commit 1097e26, released 2026-10-27).

OpenCode is an open-source AI coding agent for the terminal, and its version 2 starts with a permissive policy: most actions are allowed without asking. Before you point it at a real repository, add a few permission rules so it asks before running shell commands or editing files, and start sessions in the read-only Plan agent.

This guide shows that setup, step by step.

Based on OpenCode, by Anomaly and the OpenCode contributors, MIT license. We checked v2.2.0, released 2026-10-27, and the V2 docs on 2026-10-28. The repo also still ships V1 releases, so check which docs match your install.

V1 or V2?

The OpenCode docs now point to V2. Per the migration guide, both versions use the opencode command and are not installed side by side by default; the V2 curl installer replaces the V1 binary. V2 reads your existing V1 config from the same locations, but the native V2 permission format uses different names: permissions, shell, and subagent instead of V1's permission, bash, and task. Everything below uses the V2 format.

Install and connect a model

The V2 intro lists several installers, including a curl script, Homebrew (anomalyco/tap/opencode-v2), and npm (@opencode/cli). Windows package managers are not supported; standalone binaries are available. Once installed, open the terminal interface in your project and run /connect to add your model provider's API key.

Know the defaults

The permissions docs spell out the base policy every agent starts with:

  • Allow every action on every resource.
  • Ask before reading .env and .env.* files, but allow .env.example.

The shipped agents add to that. The Plan agent denies edits except OpenCode's own plan files. Build, the default coding agent, can use its tools and access paths outside the workspace without asking. The docs also note that because no default rule asks for external_directory, reads and edits outside your project proceed without a prompt.

So out of the box, Build can edit files and run shell commands without asking. That's fine for a scratch repo. For a real one, add rules.

Step 1: Add ask rules

Create opencode.jsonc in your project root. Rules are evaluated in order and the last match wins, so put broad rules first and exceptions after them:

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "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" },
    { "action": "edit", "resource": "*", "effect": "ask" },
    { "action": "external_directory", "resource": "*", "effect": "ask" },
  ],
}

The first four rules come straight from the docs' suggested setup: ask before shell commands, allow routine Git inspection, and always block pushes. We added the last two so every file change and every path outside the project needs your yes.

One warning from the docs is worth repeating: shell commands run with your user's full filesystem, process, and network authority, and directory detection from command text is best effort. Prefer a short allowlist of safe commands over trying to deny every dangerous one.

Step 2: Start in Plan

Make Plan the default so a new session explores and proposes before it changes anything. The setting applies to new sessions, not ones already open. The agents docs document default_agent:

jsonc
"default_agent": "plan",

Ask Plan to read the code and lay out the change. When you agree with the plan, switch to Build to carry it out, with the ask rules above still in force.

Step 3: Approve each action

When a rule resolves to ask, OpenCode offers three replies:

  • Allow once: approve only this request.
  • Allow always: approve it and save the proposed pattern for the project.
  • Reject: reject this and every other pending request in the session.

"Allow always" saves a durable, project-scoped allow rule. For a shell command it saves a prefix: the docs' example is that choosing Allow always for git status --short may save git status *. Use it for read-only commands you run all the time, and review saved approvals now and then, as the docs advise. Saved approvals never override a configured deny, so git push stays blocked.

Step 4: Review, undo, and commit yourself

OpenCode takes snapshots around each model step inside a Git repository. Type /undo to roll back the last response's file changes and edit your prompt, or /redo to cancel the rollback. The docs are clear about the limits: snapshots are "a convenience, not a transaction or backup." They don't reverse shell side effects such as database changes or Git commits, and they skip ignored files and untracked files over 2 MiB.

So the human approval step at the end is the same as for any teammate's work: run git diff, read it, run your tests, and commit it yourself. Because git push is denied in the config, the agent can't push for you, and any other shell command still waits for your yes.

A read-only reviewer, optionally

The agents docs include an example subagent that denies edits and shell, then reviews current changes and lists findings by severity. Save it as .opencode/agents/reviewer.md and ask your main agent to "use the reviewer subagent to review my current changes" before you commit. It is a second opinion, not a replacement for your own read of the diff.

Next step

Add the opencode.jsonc above to a small repo you know well, start a session in Plan, and walk one change through ask, review, and commit. To compare with another terminal agent's approval model, see our Codex CLI kit, or find an agent for the job.

Good setups, worth keeping. Request email updates on the home page, then confirm by email. No subscription starts until you confirm.

On this site

Part of: Which setup should I use to add human approval to an agent?

Your privacy choices

Choose optional tools. Rejecting them keeps the setup library available. Advertising consent stays off.

Choices stay in this browser for 90 days. You can change them using Privacy settings. Privacy and cookie details