|
|
@@ -1,27 +1,32 @@
|
|
|
---
|
|
|
title: Permissions
|
|
|
-description: Control what agents can do in your codebase.
|
|
|
+description: Control which actions require approval to run.
|
|
|
---
|
|
|
|
|
|
-By default, opencode **allows all operations** without requiring explicit approval.
|
|
|
+By default, OpenCode **allows all operations** without requiring explicit approval. You can configure this using the `permission` option.
|
|
|
|
|
|
-The permissions system provides granular control to restrict what actions AI agents can perform in your codebase, allowing you to configure explicit approval requirements for sensitive operations like file editing, bash commands, and more.
|
|
|
-
|
|
|
----
|
|
|
+```json title="opencode.json"
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "edit": "allow",
|
|
|
+ "bash": "ask",
|
|
|
+ "webfetch": "deny"
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-## Configure
|
|
|
+This lets you configure granular controls for the `edit`, `bash`, and `webfetch` tools.
|
|
|
|
|
|
-Permissions are configured in your `opencode.json` file under the `permission` key. Here are the available options.
|
|
|
+- `"ask"` — Prompt for approval before running the tool
|
|
|
+- `"allow"` — Allow all operations without approval
|
|
|
+- `"deny"` — Disable the tool
|
|
|
|
|
|
-### Tool Permission Support
|
|
|
+---
|
|
|
|
|
|
-| Tool | Description |
|
|
|
-| ---------- | ------------------------------- |
|
|
|
-| `edit` | Control file editing operations |
|
|
|
-| `bash` | Control bash command execution |
|
|
|
-| `webfetch` | Control web content fetching |
|
|
|
+## Tools
|
|
|
|
|
|
-They can also be configured per agent, see [Agent Configuration](/docs/agents#agent-configuration) for more details.
|
|
|
+Currently, the permissions for the `edit`, `bash`, and `webfetch` tools can be configured through the `permission` option.
|
|
|
|
|
|
---
|
|
|
|
|
|
@@ -29,10 +34,6 @@ They can also be configured per agent, see [Agent Configuration](/docs/agents#ag
|
|
|
|
|
|
Use the `permission.edit` key to control whether file editing operations require user approval.
|
|
|
|
|
|
-- `"ask"` - Prompt for approval before editing files
|
|
|
-- `"allow"` - Allow all file editing operations without approval
|
|
|
-- `"deny"` - Make all file editing tools disabled and unavailable
|
|
|
-
|
|
|
```json title="opencode.json" {4}
|
|
|
{
|
|
|
"$schema": "https://opencode.ai/config.json",
|
|
|
@@ -46,88 +47,144 @@ Use the `permission.edit` key to control whether file editing operations require
|
|
|
|
|
|
### bash
|
|
|
|
|
|
-Controls whether bash commands require user approval.
|
|
|
+You can use the `permission.bash` key to control whether bash commands as a
|
|
|
+whole need user approval.
|
|
|
|
|
|
-:::tip
|
|
|
-You can specify which commands you want to have run without approval.
|
|
|
-:::
|
|
|
-
|
|
|
-This can be configured globally or with specific patterns. Setting this to `"ask"`, requiring approval for all bash commands.
|
|
|
-Setting this to `"deny"` is the strictest option, blocking LLM from running that command or command pattern.
|
|
|
-
|
|
|
-For example.
|
|
|
+```json title="opencode.json" {4}
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "bash": "ask"
|
|
|
+ }
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-- **Ask for approval for all commands**
|
|
|
+Or, you can target specific commands and set it to `allow`, `ask`, or `deny`.
|
|
|
|
|
|
- ```json title="opencode.json"
|
|
|
- {
|
|
|
- "$schema": "https://opencode.ai/config.json",
|
|
|
- "permission": {
|
|
|
- "bash": "ask"
|
|
|
+```json title="opencode.json"
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "bash": {
|
|
|
+ "git push": "ask",
|
|
|
+ "git status": "allow",
|
|
|
+ "git diff": "allow",
|
|
|
+ "npm run build": "allow",
|
|
|
+ "ls": "allow",
|
|
|
+ "pwd": "allow"
|
|
|
}
|
|
|
}
|
|
|
- ```
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-- **Disable all Terraform commands**
|
|
|
+---
|
|
|
|
|
|
- ```json title="opencode.json"
|
|
|
- {
|
|
|
- "$schema": "https://opencode.ai/config.json",
|
|
|
- "permission": {
|
|
|
- "bash": {
|
|
|
- "terraform *": "deny"
|
|
|
- }
|
|
|
+#### Wildcards
|
|
|
+
|
|
|
+You can also use wildcards to manage permissions for specific bash commands.
|
|
|
+
|
|
|
+:::tip
|
|
|
+You can use wildcards to manage permissions for specific bash commands.
|
|
|
+:::
|
|
|
+
|
|
|
+For example, **disable all** Terraform commands.
|
|
|
+
|
|
|
+```json title="opencode.json" {5}
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "bash": {
|
|
|
+ "terraform *": "deny"
|
|
|
}
|
|
|
}
|
|
|
- ```
|
|
|
-
|
|
|
-- **Approve specific commands**
|
|
|
-
|
|
|
- ```json title="opencode.json"
|
|
|
- {
|
|
|
- "$schema": "https://opencode.ai/config.json",
|
|
|
- "permission": {
|
|
|
- "bash": {
|
|
|
- "git status": "allow",
|
|
|
- "git diff": "allow",
|
|
|
- "npm run build": "allow",
|
|
|
- "ls": "allow",
|
|
|
- "pwd": "allow"
|
|
|
- }
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+You can also use the `*` wildcard to manage permissions for all commands. For
|
|
|
+example, **deny all commands** except a couple of specific ones.
|
|
|
+
|
|
|
+```json title="opencode.json" {5}
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "bash": {
|
|
|
+ "*": "deny",
|
|
|
+ "pwd": "allow",
|
|
|
+ "git status": "ask"
|
|
|
}
|
|
|
}
|
|
|
- ```
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-- **Use wildcard patterns to restrict specific commands**
|
|
|
+Here a specific rule can override the `*` wildcard.
|
|
|
|
|
|
- ```json title="opencode.json"
|
|
|
- {
|
|
|
- "$schema": "https://opencode.ai/config.json",
|
|
|
- "permission": {
|
|
|
- "bash": {
|
|
|
- "git push": "ask",
|
|
|
- "*": "allow"
|
|
|
- }
|
|
|
- }
|
|
|
+---
|
|
|
+
|
|
|
+##### Glob patterns
|
|
|
+
|
|
|
+The wildcard uses simple regex globbing patterns.
|
|
|
+
|
|
|
+- `*` matches zero or more of any character
|
|
|
+- `?` matches exactly one character
|
|
|
+- All other characters match literally
|
|
|
+
|
|
|
+---
|
|
|
+
|
|
|
+### webfetch
|
|
|
+
|
|
|
+Use the `permission.webfetch` key to control whether the LLM can fetch web pages.
|
|
|
+
|
|
|
+```json title="opencode.json" {4}
|
|
|
+{
|
|
|
+ "$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "webfetch": "ask"
|
|
|
}
|
|
|
- ```
|
|
|
- This configuration allows all commands by default (`"*": "allow"`) but requires approval for `git push` commands.
|
|
|
+}
|
|
|
+```
|
|
|
|
|
|
-### Agents
|
|
|
+---
|
|
|
|
|
|
-Configure agent specific permissions
|
|
|
+## Agents
|
|
|
|
|
|
-```json
|
|
|
+You can also configure permissions per agent. Where the agent specific config
|
|
|
+overrides the global config. [Learn more](/docs/agents#permissions) about agent permissions.
|
|
|
+
|
|
|
+```json title="opencode.json" {3-7,10-14}
|
|
|
{
|
|
|
"$schema": "https://opencode.ai/config.json",
|
|
|
+ "permission": {
|
|
|
+ "bash": {
|
|
|
+ "git push": "ask"
|
|
|
+ }
|
|
|
+ },
|
|
|
"agent": {
|
|
|
- "plan": {
|
|
|
+ "build": {
|
|
|
"permission": {
|
|
|
"bash": {
|
|
|
- "echo *": "allow"
|
|
|
+ "git push": "allow"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
+
|
|
|
+For example, here the `build` agent overrides the global `bash` permission to
|
|
|
+allow `git push` commands.
|
|
|
+
|
|
|
+You can also configure permissions for agents in Markdown.
|
|
|
+
|
|
|
+```markdown title="~/.config/opencode/agent/review.md"
|
|
|
+---
|
|
|
+description: Code review without edits
|
|
|
+mode: subagent
|
|
|
+permission:
|
|
|
+ edit: deny
|
|
|
+ bash: ask
|
|
|
+ webfetch: deny
|
|
|
+---
|
|
|
+
|
|
|
+Only analyze code and suggest changes.
|
|
|
+```
|
|
|
+
|