GuidesHosting choices

OpenCode permissions: allow, ask, deny, v1 and v2

OpenCode's permission rules in version 2 and version 1: actions, shell patterns, last match wins, outside paths, per-agent rules, and --auto in opencode run.

November 23, 2026The Everpod team
The short answer

In OpenCode 2, permissions are a list under permissions (plural) in opencode.json: each rule names an action such as shell, edit or webfetch, a resource pattern, and an effect of allow, ask or deny. The last rule that matches wins, and a call no rule matches asks. Out of the box everything is allowed except reading .env files, which asks, and that includes files outside the project. Version 1 used a permission (singular) object keyed by tool, called the shell action bash, and asked before touching paths outside the project. opencode run --auto approves whatever your rules do not deny.

{
  "$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": "external_directory", "resource": "*", "effect": "ask" }
  ]
}
Copied

That asks before every shell command except git status and git diff, refuses git push outright, and asks before the agent reads or edits anything outside the project. Everything below is about OpenCode 2.4.1, released November 23, 2026, unless it says version 1.

Which version you are configuring

Run opencode --version. The two versions write permissions differently, and a tutorial written for version 1 shows the old shape. Version 2 still reads a version 1 config: the migration page says it “normalizes supported V1 and native V2 fields in memory without rewriting the source file.” The shared schema at https://opencode.ai/config.json lists both keys and marks permission as deprecated.

Version 2Version 1
Key
permissions, an ordered list of rulespermission, an object keyed by tool
Shell commands
shellbash
Starting subagents
subagenttask
Writing files
edit (covers edit, write and patch)edit (covers edit, write and patch)
Paths outside the project
Allowed by defaultAsks by default
Per agent
agents.<name>.permissionsagent.<name>.permission
“Always” at a prompt
Saved as allow rules for the projectLasts for the rest of the session

The migration page’s own conversion, trimmed to two rules, shows the shape change:

// V1
{ "permission": { "bash": { "git push *": "ask" }, "edit": "allow" } }

// V2
{ "permissions": [
  { "action": "shell", "resource": "git push *", "effect": "ask" },
  { "action": "edit", "resource": "*", "effect": "allow" } ] }
Copied

What each action covers in version 2

The resource is what a rule’s pattern is matched against, and it differs by action. From the permissions page:

ActionThe resource the pattern is matched against
read
The file path: relative inside the project, absolute outside it
edit
The target path, for edit, write and patch
glob
The glob pattern requested
grep
The regular expression, not the search path
shell
The command text; a compound command can produce several
external_directory
The outside directory, normally ending in /*
webfetch
The URL
websearch
The search query
subagent
The agent’s ID
skill
The skill’s ID
question
* (the agent asking you something)
generate_image
The image model, as provider/model
execute
*; a deny turns off Code Mode
<server>_<tool>
*, for one MCP server’s tool

Action names are plain strings, so a plugin can add its own. Two version 1 names, doom_loop and lsp, are not version 2 actions. Version 2.4.0 renamed the image tool from experimental_image_generate to generate_image; its release notes say rules with the old name are mapped automatically but saved “always allow” approvals are not, so it asks once more. The same release, which added a browser pane to the desktop app, says “A browser deny in your permission rules refuses every agent browser call.”

How a rule is chosen

OpenCode walks the whole list and keeps the last rule whose action and resource both match. In the docs’ words, “The last matching rule wins, so the specific exceptions follow the broad rule.” Put a broad rule first and its exceptions after it; the other way round, the broad rule overrides every exception above it. If nothing matches, the answer is ask.

Claude Code orders its rules differently. Its permissions docs say “Rules are evaluated in order: deny, then ask, then allow,” so “An allow rule can’t carve an exception out of a deny rule.” A list written for one reads differently in the other.

Shell rules that allow only what you meant

Allow named commands and leave everything else at ask, rather than allowing everything and denying the commands you think are dangerous. The permissions page recommends exactly that, a “narrow shell allowlist instead of patterns intended to recognize every dangerous command,” and warns that shell “runs with the host user’s filesystem, process, and network authority.” An allowed command can do whatever your user can.

Watch how wide a pattern is. git * allows git push --force and git config as well as git log; name the subcommands instead. Allowing a test or build command, such as npm test *, lets the agent run whatever the project’s scripts run, which it can also edit. Commands OpenCode’s scanner cannot analyse, such as malformed syntax or eval, have asked for approval since 2.4.0, and a matching shell deny still blocks them.

Files outside the project

In version 2, the agent reads and edits outside the project without asking. The docs: “The default policy allows external_directory, so external paths are not prompted unless you add a rule.” The migration page names the change: “V1 asks before accessing paths outside the project. V2 does not.” On a machine where your home folder holds keys, other repositories or a cloud CLI’s credentials, add the external_directory ask rule from the example at the top. To open one folder for reading and keep it read-only, the docs’ own example:

{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    { "action": "external_directory", "resource": "~/projects/reference/*", "effect": "allow" },
    { "action": "read", "resource": "~/projects/reference/*", "effect": "allow" },
    { "action": "edit", "resource": "~/projects/reference/*", "effect": "deny" }
  ]
}
Copied

Put it after an external_directory * ask rule if you have one, so this folder is the exception and the rest still asks. Where the file goes and which file wins when there are several is OpenCode’s config guide.

Different rules for one agent

An agent’s own rules go under agents.<name>.permissions in opencode.json, or under permissions in the frontmatter of its Markdown file. “Agent rules are appended after global rules; they do not replace the global array,” so where both match, the agent’s rule wins, in either direction. This, from the agents page, makes the built-in Build agent ask before a push while other agents keep the global rules; next to a global rule that denies git push *, as the example at the top does, it would loosen Build from refusing a push to asking:

{
  "agents": {
    "build": {
      "permissions": [
        { "action": "shell", "resource": "git push *", "effect": "ask" }
      ]
    }
  }
}
Copied

A review agent that may look but not change anything, as .opencode/agents/reviewer.md (the agents page’s example, with a subagent rule added):

---
description: Reviews changes for correctness and regressions
mode: subagent
permissions:
  - action: edit
    resource: "*"
    effect: deny
  - action: shell
    resource: "*"
    effect: deny
  - action: subagent
    resource: "*"
    effect: deny
---
Copied

The last rule matters because a custom subagent runs on its own permissions, “not a subset of its parent’s,” so a locked-down agent does not lock down what it starts: without it, the reviewer could hand the work to the built-in General agent, which edits. Use subagent rules to limit which agents any agent may start. The built-in Plan agent already “explores and plans without editing normal project files,” and its shell commands stay under your rules. OpenCode’s agents covers the built-in ones and writing your own.

Answering a prompt

When a rule resolves to ask, you get three answers. Once approves that request only. Always approves it and saves the tool’s proposed patterns as allow rules for the project; the docs say these “never override a configured deny.” Reject refuses it and other pending requests. How far that reaches is described two ways: the permissions page says every other pending request in the session, while the 2.3.1 release notes say a rejection “now rejects only the other pending requests from the same step, not every pending request in the session.” In version 1, “always” lasted only “for the rest of the current OpenCode session.”

Above rules and saved approvals sit policies, which can only remove access: a policy “turns allow or ask into deny and never grants access,” and global and Console-managed policies override a project’s.

Running with no prompts

opencode run has nobody to ask. Without a flag, it rejects every request that reaches ask, prints permission requested: <action> (<resource>); auto-rejecting, and tells the model:

This non-interactive run cannot ask the user for permission, so the request was rejected. Continue without this action.
Copied

The run carries on. With --auto, described as “Auto-approve permissions that are not explicitly denied,” each such request is approved once instead. The interactive opencode command takes the same flag. Two flags that neither the docs nor the help list, --yolo and --dangerously-skip-permissions, are aliases for --auto on both commands in 2.4.1’s source. Deny rules hold either way: “configured deny rules always remain enforced.”

Because the defaults already allow nearly everything, --auto on a default config leaves your deny rules as the only limit. For an unattended job, write the rules the job needs, deny the rest, and leave --auto off, so the only prompt left is the default one for .env reads, which the run refuses; with --auto it would approve that read:

{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    { "action": "shell", "resource": "*", "effect": "deny" },
    { "action": "shell", "resource": "npm test *", "effect": "allow" },
    { "action": "external_directory", "resource": "*", "effect": "deny" },
    { "action": "webfetch", "resource": "*", "effect": "deny" },
    { "action": "websearch", "resource": "*", "effect": "deny" }
  ]
}
Copied

That lets the agent edit inside the project and run the test suite, and nothing else on the shell or the web. MCP servers’ tools are actions of their own, named <server>_<tool>, and with --auto they are approved too, so deny the ones the job does not need. A run that was refused something can still exit 0, so check its output for auto-rejecting; running OpenCode on a schedule covers that and the exit codes.

Version 1 has --auto on both commands with the same description, and its CLI page lists an OPENCODE_PERMISSION environment variable, “Inlined json permissions config.” A version 1 config can also set "permission": "allow", which sets every permission to allow at once.

The same rules in version 1

Version 1 keys rules by tool, with a pattern object for tools that take one, and also lets the last matching pattern win. Its permissions page lists read, edit, glob, grep, bash, task, todowrite, skill, lsp, question, webfetch, websearch, external_directory and doom_loop, which fires when “the same tool call repeats 3 times with identical input.” Most default to allow; doom_loop and external_directory ask, and .env reads ask as in version 2. The example at the top, written for version 1:

{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "bash": {
      "*": "ask",
      "git status *": "allow",
      "git diff *": "allow",
      "git push *": "deny"
    }
  }
}
Copied

Per agent, version 1 uses agent (singular), then the agent’s name, then permission, and “agent rules take precedence.” The older tools switches were folded into permission in version 1.1.1.

Claude Code and Codex, for comparison

Claude Code keeps allow, ask and deny lists in its settings files and checks deny first, so an allow can never punch a hole in a deny; its modes and unattended options are in running Claude Code and Codex without permission prompts. Codex pairs an approval policy with a sandbox the operating system enforces, “typically to the current workspace,” and what it recommends for a version-controlled folder is workspace write with on-request approvals. OpenCode’s rules decide whether a call goes ahead, and the permissions page is plain that an allowed shell command then runs with your user’s full authority.

Run OpenCode on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.