# opencode Permissions Reference: Every Key and Default

Every key in opencode's permission block with its default, the pattern syntax, last-match-wins, per-agent overrides, config paths and auto-approve. Checked on 1.18.4.

opencode permissions live in the `permission` key of `opencode.json`. Each tool maps to `allow`, `ask`, or `deny`, and `bash`, `edit`, `read` and others also take patterns, where the last matching rule wins. Most tools default to `allow`. `doom_loop` and `external_directory` default to `ask`, and `read` denies `.env` files. Every key and default is in the tables below.

<p style="margin:0 0 24px;padding:14px 18px;border-left:3px solid var(--color-accent,#6c5ce7);background:var(--color-surface,#faf9ff);font-size:14px;line-height:1.6;"><strong>OpenCode 2.0 (15 Oct 2026):</strong> the 2.0 train replaces the plugin API. <code>permission.ask</code> and <code>tool.execute.*</code> do not exist in 2.0, and a 1.x plugin loads as nothing while model calls still look priced. Everything below was checked against 1.18.4, and as of 6 November 2026 it still described what ships as <code>latest</code> (1.19.0). The 2.0 contract, the old-to-new hook map and a two-line check are in <a href="/blog/opencode-2-plugin-api-changes">OpenCode 2.0 rewrites the plugin API</a>.</p>

<div style="margin:8px 0 28px;padding:20px 22px;border:1px solid var(--line-2);border-radius:12px;background:var(--color-accent-light,#f0effe);">
  <p style="margin:0 0 12px;font-size:15px;line-height:1.6;color:var(--acp-text);"><strong>Just want the answer?</strong> Here is a complete <code>permission</code> block for <code>~/.config/opencode/opencode.json</code>. Reads and safe git are quiet, edits and the rest of bash ask, and the destructive shapes are denied, even under <code>--auto</code>:</p>
  <pre data-track="OpenCodePerms: Hero Config Copy" style="margin:0 0 12px;background:var(--color-surface,#faf9ff);border:1px solid var(--line-2);border-radius:8px;padding:12px 14px;overflow-x:auto;"><code>{
  "$schema": "https://opencode.ai/config.json",
  "permission": {
    "read": "allow",
    "edit": "ask",
    "webfetch": "ask",
    "bash": {
      "*": "ask",
      "git status *": "allow",
      "git diff *": "allow",
      "git log *": "allow",
      "npm test *": "allow",
      "rm -rf *": "deny",
      "git push --force *": "deny"
    }
  }
}</code></pre>
  <p style="margin:0;font-size:13px;color:var(--acp-text-dim);">Auto-approve: <a href="#auto-approve" style="font-weight:600;">the four ways, ranked</a> &nbsp;·&nbsp; <a href="/controls/opencode" data-track="OpenCodePerms: Controls Page">how opencode's controls work →</a> &nbsp;·&nbsp; <a href="/integrations/opencode" data-track="OpenCodePerms: Install Guide">add workspace rules →</a></p>
</div>

opencode has a real rule language: three verdicts, a key per tool, glob patterns over the command or path, a fixed order of precedence, and a config layer an admin can lock. This page covers all of it. It also covers every way to auto-approve and what each leaves gated, and what a plugin can and cannot intercept. It was checked against opencode 1.18.4's own `--help` and [opencode's permissions docs](https://opencode.ai/docs/permissions/). Where the docs and the binary are the only sources, it says so.

## Where the block lives

The `permission` key belongs in `opencode.json` (JSON or JSONC, so comments are fine). opencode reads it from several places and **merges** them. A later layer overrides an earlier one only for the keys it sets. The load order from [opencode's config docs](https://opencode.ai/docs/config/), lowest to highest:

| Layer | Path | Meant for |
|---|---|---|
| Remote | `.well-known/opencode` | organizational defaults |
| Global | `~/.config/opencode/opencode.json` | your preferences |
| Custom path | `OPENCODE_CONFIG=<file>` | one-off overrides |
| Project | `opencode.json` at the repo root | project settings |
| Directories | `.opencode/` (agents, commands, plugins) | project extensions |
| Inline | `OPENCODE_CONFIG_CONTENT='{…}'` | runtime overrides |
| Managed | `/Library/Application Support/opencode/` · `/etc/opencode/` · `%ProgramData%\opencode` | admin-controlled |
| macOS MDM | `/Library/Managed Preferences/ai.opencode.managed.plist` | highest, not user-overridable |

Two things follow. A project `opencode.json` can loosen a rule you set globally, because it loads later. And a `deny` in the managed layer cannot be loosened by anything below it. opencode's docs say managed settings "override everything." That is the layer for a rule the whole team must keep. See [locking a rule](#locking-a-rule) below.

There is also `OPENCODE_PERMISSION`, which the [CLI docs](https://opencode.ai/docs/cli/) describe as "Inlined json permissions config." It holds a whole permission block in an environment variable, which suits a CI job that should not depend on the checkout's config file.

## Three verdicts, three shapes

Every rule resolves to one of three strings:

- **`allow`** runs without approval.
- **`ask`** prompts for approval.
- **`deny`** blocks the action.

The block takes three shapes, from coarsest to finest:

```json
{ "permission": "allow" }
```

One verdict for everything. Then the per-tool object, with `"*"` as the catch-all:

```json
{
  "permission": {
    "*": "ask",
    "bash": "allow",
    "edit": "deny"
  }
}
```

And the granular form, where a tool's value is an object of pattern to verdict:

```json
{
  "permission": {
    "bash": {
      "*": "ask",
      "git *": "allow",
      "npm *": "allow",
      "rm *": "deny"
    },
    "edit": {
      "*": "deny",
      "packages/web/src/content/docs/*.mdx": "allow"
    }
  }
}
```

You can mix them. `"read": "allow"` next to a full `"bash": { … }` object is normal. opencode's agent docs list the keys that accept the object form as `read`, `edit`, `glob`, `grep`, `list`, `bash`, `task`, `external_directory`, `lsp`, and `skill`. The rest take a string.

If you inherit an older config: the boolean `tools` block (`"tools": { "bash": false }`) has been deprecated since v1.1.1 and folded into `permission`. `true` maps to `{"*": "allow"}` and `false` to `{"*": "deny"}`. It still works, but write new rules in `permission`.

## Every key

Keys are tool names plus two guards. What each pattern matches against, per opencode's permissions docs:

| Key | The pattern matches on |
|---|---|
| `read` | the file path |
| `edit` | the file path (one key covers `edit`, `write`, and `patch`) |
| `glob` | the glob pattern the agent asked for |
| `grep` | the regex the agent asked for |
| `bash` | the parsed command, e.g. `git status --porcelain` |
| `task` | the subagent type |
| `skill` | the skill name |
| `lsp` | LSP queries ("currently non-granular") |
| `question` | the agent asking you a question mid-run |
| `webfetch` | the URL |
| `websearch` | the query |
| `external_directory` | a path outside the directory opencode started in |
| `doom_loop` | the same tool call repeated 3 times with identical input |

`external_directory` is a guard, not a tool. It fires for any tool that takes a path (`read`, `edit`, `glob`, `grep`, many `bash` commands) when the path is outside the project. An allowed external directory inherits the workspace defaults, so `read` works there because `read` defaults to allow. To allow reads but block edits, pair an `external_directory` allow with an `edit` deny on the same path. The [example below](#external-directories-reads-yes-edits-no) shows it.

`doom_loop` catches a stuck agent. After three identical calls in a row, opencode asks you before the fourth.

## The defaults

Most permissions default to `allow`. The exceptions, as opencode documents them:

- `doom_loop` defaults to `ask`.
- `external_directory` defaults to `ask`.
- `read` allows everything except `.env` files:

```json
{
  "permission": {
    "read": {
      "*": "allow",
      "*.env": "deny",
      "*.env.*": "deny",
      "*.env.example": "allow"
    }
  }
}
```

That is all the restriction you get out of the box. `bash`, `edit`, and `webfetch` are `allow` until you say otherwise. That is why [the ACP installer](/integrations/opencode) sets those three to `ask`. It only fills gaps, and a value you already wrote is left alone.

## Patterns and precedence

**Wildcards.** `*` matches zero or more of any character. `?` matches exactly one. Everything else matches literally. A leading `~` or `$HOME` expands to your home directory, so `~/projects/*` and `$HOME/projects/*` are the same rule.

**Arguments need the star.** `"grep"` matches the bare command and nothing else. `"grep *"` matches `grep pattern file.txt`. The same goes for `"git status"` versus `"git status *"`. If a rule you wrote seems ignored, check this first.

**Last match wins.** Within one tool's object, rules run in order and the last one that matches takes precedence. That is why the examples put `"*"` first. The catch-all sets the default and the specific rules after it carve out exceptions. Reverse the order and the catch-all overrides everything above it.

**Agent rules beat global rules.** A `permission` block under `agent.<name>` merges with the top-level block and wins on conflict. The built-in `plan` agent uses this to ask on all file edits and all bash. You can do the same for your own:

```json
{
  "permission": {
    "bash": { "*": "ask", "git *": "allow", "git push *": "deny" }
  },
  "agent": {
    "build": {
      "permission": {
        "bash": { "*": "ask", "git *": "allow", "git commit *": "ask", "git push *": "deny" }
      }
    }
  }
}
```

Agents defined as Markdown take the same block as YAML frontmatter:

```markdown
---
description: Code review without edits
mode: subagent
permission:
  edit: deny
  bash: ask
  webfetch: deny
---
Only analyze code and suggest changes.
```

**Config layers beat each other in load order**, per the table above. Project beats global, inline beats project, and managed beats all.

**A pattern only matches text.** A `bash` pattern is a glob over the command text opencode parsed. A different spelling of the same action is a different string. `rm -rf *` catches that spelling, not a deletion routed through another tool or a script. Write the destructive shapes as `deny` to catch the common spellings, and treat the list as a tripwire, not a wall. [Every harness's denylist has the same limit](/blog/what-survives-yolo-mode).

## The prompt: once, always, reject

A call that resolves to `ask` stops and offers three answers:

- **once** approves this request only.
- **always** approves matching requests for the rest of the current session.
- **reject** denies it.

The pattern that *always* covers comes from the tool, not from you. For bash it is usually a safe prefix such as `git status*`. Two things to know about *always*. It lasts only for the session, so restart opencode and it is gone. And it is recorded nowhere you can review. For the rest of that session an `ask` has become an `allow`, and the only trace is your memory. A long session can pile up a lot of these. If you want the change to last, write it as an `allow` pattern in the file, where you can diff it.

<a id="auto-approve"></a>

## Auto-approve: four ways, and what each leaves gated

"Make opencode stop asking me" has four answers with different reach. Narrowest first.

**1. `allow` patterns in the block.** Per command shape, permanent, in a file you can diff and review. This is the right default: approve the shapes you would approve every time and leave the rest at `ask`. The block at the top of this page does this.

**2. `always` at the prompt.** Per shape, for this session, unrecorded. Good for the third identical `npm test` in a long session.

**3. `--auto`.** Everything that is not an explicit `deny` is approved for the run. opencode's own help text for it, verbatim from 1.18.4:

```
--auto  auto-approve permissions that are not explicitly denied (dangerous!)
```

It works on the TUI (`opencode --auto`) and on headless runs (`opencode run --auto "Refactor this module"`). You can also toggle it mid-session from the TUI command palette with *Enable auto-approve permissions* and *Disable auto-approve permissions*. A muted `auto` indicator shows beside the agent name while it is on. Unlike most skip-permission flags, **deny rules stay enforced.** What it removes is the human answer on the ask tier, so everything you relied on the prompt for now runs, including `edit`, `external_directory` and `doom_loop`, unless you wrote a `deny`. A rule that has to hold unattended must be a `deny`.

**4. Workspace rules, with the ACP plugin.** [The plugin](/integrations/opencode) hooks `permission.ask`, which opencode fires for a tool whose permission resolved to `ask`, before the prompt shows. If your workspace rule says allow, the plugin sets the permission to `allow`. There is no prompt, the call runs, and the tool, arguments and session go in the activity log. If the rule says ask, the plugin blocks the call in opencode and holds it for approval on the console Approvals page or from the approval email. Approve it there, then ask opencode to retry. opencode does not show these holds inline. Only Claude Code does. So "git, npm test and reads are fine, edits ask, anything touching production asks" is one rule that behaves the same on every machine with the plugin, instead of one `opencode.json` per laptop. Your `permission` block still matters. A tool set to `allow` in your config never reaches `permission.ask`.

With any of the four, an explicit `deny` in your config holds under *always* and under `--auto`. With the plugin, a workspace deny holds too, because it fires from `tool.execute.before`, which runs on every call whatever the config says.

## Worked examples

### A read-only reviewer agent

An agent that can look but not touch. `edit: deny` covers `write` and `patch` too. `webfetch: deny` keeps it off the network. Bash is allowed for read-only git and denied for everything else.

```json
{
  "agent": {
    "review": {
      "description": "Code review without edits",
      "mode": "subagent",
      "permission": {
        "edit": "deny",
        "webfetch": "deny",
        "bash": {
          "*": "deny",
          "git status *": "allow",
          "git diff *": "allow",
          "git log *": "allow",
          "grep *": "allow"
        }
      }
    }
  }
}
```

### Unattended: `opencode run --auto` with a floor

A CI or cron run has nobody to answer a prompt, so `--auto` is the flag to use. Everything you need to hold has to be a `deny`. The block can travel with the job as an environment variable, so it does not depend on the checkout:

```bash
export OPENCODE_PERMISSION='{
  "edit": { "*": "allow", "*.env*": "deny", ".github/workflows/*": "deny" },
  "bash": {
    "*": "allow",
    "rm -rf *": "deny",
    "git push --force *": "deny",
    "git push * --force": "deny",
    "curl * | sh": "deny"
  }
}'
opencode run --auto "Fix the failing unit tests and commit"
```

With the ACP plugin in that run, also set `ACP_FAIL_MODE=closed`. Then an unreachable gateway blocks the job instead of letting it run unchecked. The [install guide](/integrations/opencode#fail-open-by-default--and-opting-in-to-fail-closed) has the details.

### Edits scoped to one package

Deny edits everywhere, then allow them under one path. Last-match-wins does the work:

```json
{
  "permission": {
    "edit": {
      "*": "deny",
      "packages/web/src/**": "allow"
    }
  }
}
```

### External directories: reads yes, edits no

`external_directory` allows the path and `edit` denies changes to it. You need both, because an allowed external directory inherits the workspace defaults, and `read` defaults to allow:

```json
{
  "permission": {
    "external_directory": { "~/projects/personal/**": "allow" },
    "edit": { "~/projects/personal/**": "deny" }
  }
}
```

<a id="locking-a-rule"></a>

### Locking a rule for a team

A `deny` that must survive whatever a developer puts in their own config goes in the managed layer. opencode loads it last and documents it as not user-overridable. On macOS:

```
/Library/Application Support/opencode/opencode.json
```

Put the same `permission` block inside it (Linux: `/etc/opencode/`, Windows: `%ProgramData%\opencode`). opencode's config docs also show an MDM plist form for macOS fleets, where `permission` is a dict with wildcard and nested `bash` rules such as `rm -rf *: deny`. This is the one place in opencode's own model where a rule can be made to hold against the user. It applies per machine. It gives you no record of what the rule did, and no copy of the rule on the developer's other harnesses.

## What a plugin sees, and what it does not

opencode runs plugins in-process, and two of its hooks sit on the permission system itself. From the plugin package's own types (`@opencode-ai/plugin` 1.18.4):

| Hook | Fires | Can do |
|---|---|---|
| `permission.ask(input: Permission, output: { status })` | when a tool's permission resolved to `ask` | set `output.status` to `allow` (skip the prompt), `deny`, or leave `ask` (the native prompt fires) |
| `tool.execute.before(input: { tool, sessionID, callID }, output: { args })` | before every tool call | change `args`, or `throw` to block |
| `tool.execute.after(input, output: { title, output, metadata })` | after the result exists | observe |

Three consequences for anyone wiring rules through this, all checked against the [ACP plugin's source](https://github.com/agentic-control-plane/opencode-acp-plugin):

- **`permission.ask` only sees the ask tier.** A tool at `allow` never reaches it. So a rule layer needs `tool.execute.before` as the backstop, and that hook can only allow or block. It has no way to ask a person.
- **The `Permission` object carries no arguments.** On 1.18.4 it has `id`, `type` (the tool name), an optional `pattern`, `sessionID`, `messageID`, an optional `callID`, `title`, `metadata`, and `time`. The command text is not on it. The plugin saves `output.args` from `tool.execute.before` by `callID` and attaches them when `permission.ask` fires for the same call. It fetches one decision per `callID` and reuses it across both hooks.
- **The only way to block in `tool.execute.before` is to throw.** The message is what the model sees, so it carries the reason. The plugin's string is `[ACP] Denied by policy: <reason>`. A hit on the always-blocked list, which no workspace setting, approval, *always* or `--auto` can override, reads:

```
[ACP] Denied by policy: hardline floor: recursive delete of the root filesystem, blocked unconditionally; this pattern cannot be allowed by policy or approval
```

The other labels on that list, from the classifier: recursive delete of a system directory or the home directory, `mkfs`, `dd` or a redirect onto a raw block device, a fork bomb, `kill -1`, shutdown, reboot, halt and poweroff, `init 0`/`6`, and `systemctl poweroff`. Commands wrapped in `sh -c '…'` or `eval` are scanned as commands, not as text.

The other safety-floor rules, such as force-push, destructive SQL through a database client, `curl | sh` and deletes outside the project, are asks, not denies. On opencode they hold the call for approval on the console. The [rules page](/docs/rules) lists them.

**Policy keys.** opencode spells its tools in lowercase, and workspace rules use canonical names. The gateway maps the opencode spelling before it classifies the call, so a rule on `Bash.rm` applies to opencode's `bash` calls with no separate opencode rule:

| opencode tool | Policy key |
|---|---|
| `bash` | `Bash` (sub-classified: `Bash.git`, `Bash.rm`, …) |
| `edit`, `patch` | `Edit` |
| `write` | `Write` |
| `read` | `Read` |
| `grep` | `Grep` |
| `webfetch` | `WebFetch` |
| `websearch` | `WebSearch` |
| `task` | `Agent` |

A rule written against the native spelling keeps working. The original name is always tried last.

**What it does not see.** Three limits. `opencode --pure` ("run without external plugins," per the binary's help) starts a process with no config-registered plugin, so ACP is not in that run. It is a flag on the command line and shows up in any process list. `ACP_OPENCODE=off` turns the plugin off without touching your config. And a machine with no workspace credential is a no-op: opencode behaves as if the plugin were not installed. There is no on-device mode for opencode today. The installer's `--local` flag skips it and says so.

## Troubleshooting

**A rule I wrote is ignored.** Check the order. The last matching rule wins, so a `"*"` placed after your specific rules overrides them. Then check for the missing star: `"git status"` does not match `git status --short`.

**opencode still asks for something I allowed.** The prompt may come from a different key. A `bash` allow does not cover `external_directory`, which fires separately when a command touches a path outside the project. `doom_loop` fires on repetition whatever the tool is allowed to do.

**A project loosened my global rule.** That is expected. Project config loads after global and wins for the keys it sets. Put the rule in the managed layer if it must hold.

**`--auto` ran something I meant to block.** It was an `ask`, not a `deny`. Auto mode approves everything that is not explicitly denied.

**The ACP plugin never pre-approves anything.** The tool is at `allow` in your config, so `permission.ask` never fires for it. Set it to `ask` (the installer does this for `bash`, `edit` and `webfetch`) and the plugin can settle the prompt before it shows.

**Every call is being blocked.** That is a `deny` rule, not an outage. When the gateway is unreachable, the plugin lets calls through by default. If you set `ACP_FAIL_MODE=closed` and the gateway is down, the block message says so: `[ACP] gateway unreachable, blocked (fail-closed)`.

## Frequently asked questions



## Where to read more

- [How opencode's controls work](/controls/opencode): the prompt, the escape hatch, the plugin surface, and where the native model ends
- [Install guide](/integrations/opencode): the plugin, the permission block the installer writes, fail mode, troubleshooting
- [opencode hooks reference](/blog/opencode-hooks-reference): the four hooks the plugin registers and what each covers
- [opencode cost tracking](/blog/opencode-cost-tracking): local metering with no account, and priced spend through the proxy
- [Native controls, compared](/controls): opencode's permission model beside Claude Code, Codex CLI, Cursor, and the rest
- [opencode permissions docs](https://opencode.ai/docs/permissions/) · [config docs](https://opencode.ai/docs/config/) · [agents docs](https://opencode.ai/docs/agents/) · [CLI docs](https://opencode.ai/docs/cli/): the upstream sources this page was checked against

<!-- Sources: https://opencode.ai/docs/permissions/ · https://opencode.ai/docs/config/ · https://opencode.ai/docs/agents/ · https://opencode.ai/docs/cli/ · opencode 1.18.4 `opencode --help` and `opencode run --help` · @opencode-ai/plugin 1.18.4 index.d.ts and @opencode-ai/sdk types.gen.d.ts (Permission type) · github.com/agentic-control-plane/opencode-acp-plugin src/index.ts (deny strings, callID cache, fail mode) · gatewaystack-connect apps/tenant-gateway/src/govern/riskClassifier.ts (hardline labels) and hookGovernance.ts (deny reason string, tool-name aliases) -->
