Permissions

OpenCode v2 replaces V1’s tool-grouped permission map with one ordered permissions array. Each rule specifies an action, a resource pattern, and an effect.

Rule Format

{
  "permissions": [
    { "action": "shell", "resource": "git push *", "effect": "ask" },
    { "action": "edit", "resource": "*", "effect": "allow" },
    { "action": "websearch", "resource": "*", "effect": "deny" }
  ]
}

Rules are evaluated in order. The last matching rule wins. Put catch-all "*" rules first and specific rules after.

Effects

EffectBehavior
allowRun without approval
askPrompt for approval
denyBlock the action

Actions

V2 renames several V1 permission keys:

V1 KeyV2 ActionWhat it gates
bashshellShell commands (matches parsed commands)
tasksubagentLaunching subagents
write / patcheditAll file modifications
-readReading files
-globFile globbing
-grepContent search
-listDirectory listing
-external_directoryPaths outside working directory
-webfetchURL fetching
-websearchWeb search
-lspLSP queries
-skillLoading skills
-questionAsking the user questions
-doom_loopRecovery when agent repeats tool calls

V1 to V2 Migration

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

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

Gotcha: V2 also accepts the V1 permission map format for backwards compatibility. Valid native V2 values take precedence when both forms set the same canonical value.

Auto Mode

Start with --auto to auto-approve requests that aren’t explicitly denied:

opencode2 --auto

Explicit deny rules still apply. Auto mode only changes ask to allow.

Defaults

If you don’t configure permissions:

  • Most permissions default to allow
  • doom_loop and external_directory default to ask
  • read is allow, but .env files are denied by default
{
  "permission": {
    "read": {
      "*": "allow",
      "*.env": "deny",
      "*.env.*": "deny",
      "*.env.example": "allow"
    }
  }
}

Per-Agent Overrides

Agents can override global permissions. Agent rules merge with global config, with agent rules taking precedence:

{
  "permissions": [
    { "action": "shell", "resource": "*", "effect": "ask" },
    { "action": "shell", "resource": "git *", "effect": "allow" }
  ],
  "agents": {
    "reviewer": {
      "mode": "subagent",
      "permissions": [
        { "action": "edit", "resource": "*", "effect": "deny" },
        { "action": "subagent", "resource": "*", "effect": "deny" },
        { "action": "subagent", "resource": "explore", "effect": "allow" }
      ]
    }
  }
}

What “Ask” Does

When OpenCode prompts for approval, you get three choices:

  • once - approve just this request
  • always - approve future matching requests for the rest of the session
  • reject - deny the request