# OpenCode Permissions and Hooks Reference

How opencode's permission block resolves allow, ask and deny, how the acp-opencode plugin's two hooks use it, what you lose without the block, and what happens when ACP is unreachable.

<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> Add the plugin and a <code>permission</code> block to <code>opencode.json</code>. The block is what sends tool calls to the plugin's main hook:</p>
  <pre data-track="OpenCodeHooks: 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",
  "plugin": ["acp-opencode"],
  "permission": {
    "bash": "ask",
    "edit": "ask",
    "webfetch": "ask"
  }
}</code></pre>
  <p style="margin:0;font-size:13px;color:var(--acp-text-dim);"><a href="/integrations/opencode" data-track="OpenCodeHooks: Install Guide" style="font-weight:600;">Full opencode install guide →</a> &nbsp;·&nbsp; <a href="/controls/opencode" data-track="OpenCodeHooks: Controls Page">the controls reference →</a></p>
</div>

<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 this 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 still describes 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>

Opencode has a permission system with allow, ask and deny verdicts. It also has plugins that run inside the process. That lets ACP sit directly on top of the permission system instead of beside it. This page covers how a verdict gets resolved, what each of the plugin's two hooks sees, what you lose if you skip the config, and what runs with no credential. For every key in the `permission` block, see the [opencode permissions reference](/blog/opencode-permissions-reference).

## The permission block resolves first

Opencode checks every tool call against the `permission` block in `opencode.json` before anything else. The verdicts are `allow`, `deny` and `ask`. The last matching rule wins. So a broad `"bash": "ask"` followed by a narrower `"git status*": "allow"` quiets the safe case and keeps the prompt for everything else.

Most tools default to `allow`. Two default to `ask`: `external_directory` (paths outside the project) and `doom_loop` (the same call three times with identical input).

This matters for plugins. Opencode gives a plugin one way to step into the approval itself, the `permission.ask` hook. It only fires for a call that already resolved to `"ask"`. A tool set to `allow` never reaches it.

## The two hooks that decide

`acp-opencode` registers four hooks. Two make decisions.

| Hook | What it does |
|---|---|
| `permission.ask` | Sends the call to `/govern/tool-use`. If ACP says `allow`, the permission is set to allow and the native prompt is skipped. If ACP says `deny`, the call is blocked. If ACP says `ask`, the plugin leaves it alone, so opencode's own **once / always / reject** prompt appears as it would with no plugin. |
| `tool.execute.before` | A deny-only backstop for calls that never reach `permission.ask`, meaning anything set to `allow`. An ACP `deny` here throws `[ACP] Denied by policy: <reason>`, which is how opencode blocks a call from this hook. It also stores the call's arguments and start time by `callID` for the audit row. |

The other two don't decide anything. `tool.execute.after` posts the tool's output to `/govern/tool-output` for the audit trail (capped at 200 KB, sent without waiting for a reply). `chat.headers` stamps `X-GS-Session` and `X-GS-Client` on every model request, which ties a session's tool calls to its model spend in the cost view.

If both `tool.execute.before` and `permission.ask` fire for the same `callID`, which happens whenever a tool is set to `ask`, the plugin fetches the decision once and uses it for both.

## Why you need the permission block

Leave a tool at its default `allow` and `permission.ask` never fires for it. There is no native prompt to step into. What's left is the `tool.execute.before` backstop, which can only deny. An ACP `allow` has no prompt to skip. An ACP `ask` has nowhere to go, because only `permission.ask` can open opencode's prompt.

So without the block you still get the audit and policy denies. You lose pre-approval and the ask prompt. The [installer](/integrations/opencode) fills in `bash`, `edit` and `webfetch` entries if they're missing, and it never overrides a choice you made yourself.

## The native prompt, and what `--auto` does to it

When a tool resolves to `ask`, you get three answers. The middle one, **always**, approves that kind of call for the rest of the session. It's handy, and it quietly turns `ask` into `allow` with no record outside opencode. The ACP audit row for the call that triggered it is the more durable record.

Opencode's full-auto flag, `--auto`, skips the `ask` prompts. Explicit `deny` rules, from your `permission` block or from the plugin, still hold. So anything gated only by `ask` acts like `allow` under `--auto`, because nobody is there to answer. If a rule has to hold while you're away, make it a `deny`. That goes for rules routed through the plugin too.

## With no credential

With no `ACP_BEARER_TOKEN` and no `~/.acp/credentials`, the published plugin (`acp-opencode` 0.2.1) makes no policy decisions. Both hooks return early and opencode behaves as if the plugin weren't installed. There is no on-device decision mode for opencode today. The installer's `--local` flag detects opencode and skips it, and says so.

Metering does run with no credentials. The plugin listens to opencode's event bus and records every model call's tokens and cost, and every tool result, to SQLite at `~/.acp/opencode-local.db`. Read it with `npx acp-opencode report`. It never needs an account and never leaves the machine. The [cost tracking reference](/blog/opencode-cost-tracking) covers it.

## When ACP is unreachable

For the cloud path, network errors, timeouts over 2 seconds, non-2xx responses and malformed bodies all fail open by default. The tool call goes ahead, with one loud warning per session. To fail closed instead, set `export ACP_FAIL_MODE=closed`.

Don't assume that setting covers every harness. The shared hook that Cursor, Codex and other installer-based harnesses use reads `ACP_FAIL_MODE` too (or a `~/.acp/failmode` file). So does the Claude Code plugin from 0.30.1. Without the setting it fails open with an UNGOVERNED banner in interactive sessions and fails closed for subagent, background and API sessions.

A policy `deny` always blocks, whatever the fail mode. A machine with no credentials does nothing either way.

## Related links

- [opencode permissions reference](/blog/opencode-permissions-reference): every key in the `permission` block, defaults, config layers, auto-approve, worked examples
- [/controls/opencode](/controls/opencode): the rule language, the native prompt and the plugin surface
- [/integrations/opencode](/integrations/opencode): install guide, local metering and troubleshooting
- [Claude Code hooks reference](/blog/claude-code-hooks-reference): the shell-hook shape, for comparison
- [Codex hooks reference](/blog/codex-cli-hooks-reference): a narrower hook surface that is still changing
- [DeepSeek Harness (dsh) hooks reference](/blog/deepseek-harness-hooks-reference): the other in-process plugin model
- [OpenCode cost tracking](/blog/opencode-cost-tracking): the local SQLite path and the proxy path for priced spend

## Frequently asked questions



<!-- Sources: https://opencode.ai/docs/plugins/ (opencode plugin system docs); https://opencode.ai (opencode project); agenticcontrolplane.com/controls/opencode and agenticcontrolplane.com/integrations/opencode (this site's own reference and install pages); https://github.com/agentic-control-plane/opencode-acp-plugin (plugin source and README, cross-checked against the above) -->
