OpenCode's permissions page puts the whole system in one sentence: the permission config decides "whether a given action should run automatically, prompt you, or be blocked." OpenCode checks it, outside the model. The rest is which keys exist, how patterns match, what the defaults are, and who else can write that config.
One key per tool, last match wins
Permissions are keyed by tool name: read, edit (which covers edit, write and patch), glob, grep, bash, task for subagents, skill, webfetch, websearch and a few more. Two keys are guards instead of tools: external_directory fires when a tool touches a path outside the folder OpenCode started in, and doom_loop fires when the same call repeats three times with identical input.
A key takes one value, "allow", "ask" or "deny", or an object of patterns. "bash": {"*": "ask", "git *": "allow", "rm *": "deny"} asks for most commands, runs git without asking and blocks rm. Patterns are plain wildcards, * and ?, matched against the file path for read and edit and against the parsed command for bash.
Order matters, and it runs the other way from Claude Code. OpenCode takes the last rule that matches, so the catch-all "*" goes first and the narrow rules after it. Claude Code permissions check deny first, whatever the order. A config copied from one agent to the other can mean the opposite of what it says.
The defaults allow almost everything
With no config, most permissions are "allow". external_directory and doom_loop are "ask", and read asks only for *.env and *.env.*, with *.env.example allowed. So the default Build agent edits files and runs shell commands in your project without a question.
The read-only agent is less read-only than it sounds. OpenCode's agents page says Plan denies file edits except its own plan files, and "does not restrict the bash tool." A shell command can still write a file. Plan's defaults are also applied before your top-level config, so a global "*": "allow" reaches Plan too.
What ask, always and auto do
An ask prompt offers three answers: once, always and reject. Always approves future calls that match the patterns the tool suggests, such as git status*, for the rest of the current session.
People search for OpenCode's yolo mode or a dangerously skip permissions flag. Neither exists under that name. The CLI reference has --auto, which approves every request that is not explicitly denied, for the interactive screen and for opencode run. Deny rules still hold. Setting "permission": "allow" in a config does the same for every tool. Like dangerously skip permissions in Claude Code, it turns off the questions and adds no boundary.
The repository can write the rules
OpenCode merges config from several places, and the config page gives the order: a remote config from your provider, your global file in ~/.config/opencode, then the project's opencode.json, then .opencode folders with agents and plugins. Later sources win. A project file overrides your global one, and the docs call it safe to check into Git.
So a repository you clone can arrive with "permission": "allow", or with an agent in .opencode/agents that sets its own rules, which take precedence for that agent. Read those files in a repository you did not write before you start OpenCode in it, the same way you would read a README that says to curl a script.
One layer sits above the project. Managed config in /etc/opencode on Linux or /Library/Application Support/opencode on macOS, or a profile pushed by device management, overrides everything else. That is where a team's rules belong.
What the rules do not do
OpenCode's security policy is plain about it. The permission system is a UX feature that prompts before commands and writes, and it is not designed to isolate the agent. It lists sandbox escapes as out of scope for reports, since the permission system is not a sandbox, and malicious config files too.
OpenCode does not sandbox the agent.OpenCode, SECURITY.md
A rule matches the command OpenCode sees, not what that command does. Allow npm * and every script in package.json runs with it. Allow git * and a commit runs whatever hooks the repository has installed. The program starts as you, with your home folder, your keys and your network, and the rules have nothing to say about what it reads or calls next.
"Bash is set to ask, so nothing runs without me."
Revision 1: nothing starts without you. What an approved command runs next is up to the machine.A setup that holds
Start from ask. Put "*": "ask" first, then allow read, glob, grep and the few commands you run all day, and deny the ones you never want, such as git push *.
Keep auto for a box you would throw away. --auto suits a container or a CI job with nothing worth taking. On your laptop it hands the model your account.
Put team rules in managed config. A file in /etc/opencode or a device management profile is the one layer a project's opencode.json cannot override.
Put a boundary under the rules. The security policy's own advice is a Docker container or a virtual machine. Whatever you pick, ask what the process can reach, not what the model intends: our list of AI agent security risks covers the wrong file and the wrong host, and what agentic AI security means to us comes down to directories, hosts, keys and a person who approves more.
A side note on how we do it
We build Fenzi, which starts OpenCode inside an OpenShell sandbox and leaves its permission rules as you set them: the rules decide what OpenCode asks about, and the sandbox decides which files and hosts any process can reach. The OpenCode section of the agents sheet lists what we set. It is one way to put a boundary under the rules, and a container or a virtual machine can do the same.
So, how do they work?
Each tool call matches a key, the last matching pattern decides, and anything you did not configure starts at allow. The project's config can rewrite your rules, and managed config is the only layer it cannot touch. The rules shape what OpenCode asks you, and OpenCode says itself that they are not a sandbox. Start with its permissions page, and read the threat model beside it before you choose the boundary.