OpenCode: OpenCode Permission System

Last updated: 2026-08-31

--- title: OpenCode Permissions and Formatter Tools description: Learn fine-grained permission control and code formatter configuration order: 15 lang: en

Permission configuration is the core of secure OpenCode usage. Formatter tools ensure consistent code style.

1. What You Will Learn


2. Three-Level Permission System

Value Description Use Case
allow Auto-allow Safe operations like git status
ask Require confirmation Risky operations like file editing
deny Auto-reject Dangerous operations like rm -rf

3. Global Permission Configuration

JSON
{
  "permission": {
    "edit": "ask",
    "bash": {
      "*": "ask",
      "git status *": "allow",
      "npm test": "allow",
      "rm *": "deny",
      "sudo *": "deny"
    }
  }
}

Last matching rule wins. Put * wildcard first, specific rules after.


4. Agent-Level Overrides

JSON
{
  "permission": { "edit": "deny" },
  "agent": {
    "build": { "permission": { "edit": "ask" } },
    "review": { "permission": { "edit": "deny" } }
  }
}

5. Formatter Tools

Configure in opencode.json:

JSON
{
  "formatter": {
    "command": "prettier",
    "args": ["--write"]
  }
}
Tool Language Config
Prettier JS/TS/CSS/HTML "command": "prettier", "args": ["--write"]
Black Python "command": "black"
gofmt Go "command": "gofmt", "args": ["-w"]
rustfmt Rust "command": "rustfmt"

AI modifies files → formatter runs automatically → consistent code style.


6. Security Best Practices

Scenario Recommended Config
Daily development edit: ask, bash: ask, write: ask
Code review edit: deny, write: deny, bash: git read-only
CI/CD edit: allow, bash: allow (restricted)
Beginner mode All permissions set to ask

❓ FAQ

Q Is ask permission too inconvenient?
A Initially yes, but it's the price of safety. For trusted operations, configure allow to reduce confirmations.
Q Formatter execution fails?
A OpenCode continues the task—formatter failure doesn't block the workflow. Run formatting manually afterward.

📖 Summary


📝 Exercises

  1. Basic: Configure global permissions with edit and bash set to ask.

  2. Intermediate: Configure bash Glob rules to allow git operations but deny dangerous commands.

  3. Advanced: Configure Prettier as formatter and have OpenCode auto-format code after modifications.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏