Skip to content

Commit cea0d41

Browse files
committed
fix(plan-mode): enforce bash restriction and scope subagent permission inheritance
Plan mode currently relies solely on a system prompt to prevent write operations via the bash tool. Since the permission system only denies edit-class tools (edit, write, apply_patch), bash remains unrestricted and the model can execute arbitrary shell commands including writes. Changes: 1. agent/agent.ts — Add bash: { "*": "deny" } to the plan agent's permission config. This blocks direct bash tool use in plan mode via the permission evaluation layer and hides bash from the tool list (disabled() correctly maps the 'bash' tool ID to the 'bash' permission via its fallthrough case). 2. agent/subagent-permissions.ts — Restrict parent deny inheritance to write-capable permissions (edit, write, apply_patch, bash) instead of inheriting ALL parent denies. Prior behavior (anomalyco#26597) blindly inherited every deny rule, which overrode subagents' explicit allows for unrelated permissions (e.g., explore's bash: allow was silently neutralized). Fixes anomalyco#22641 Addresses anomalyco#26700
1 parent 5f61d21 commit cea0d41

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎packages/opencode/src/agent/agent.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const layer = Layer.effect(
155155
},
156156
plan: {
157157
name: "plan",
158-
description: "Plan mode. Disallows all edit tools.",
158+
description: "Plan mode. Disallows all edit tools and bash commands.",
159159
options: {},
160160
permission: Permission.merge(
161161
defaults,
@@ -173,6 +173,9 @@ export const layer = Layer.effect(
173173
[path.join(".opencode", "plans", "*.md")]: "allow",
174174
[path.relative(ctx.worktree, path.join(Global.Path.data, path.join("plans", "*.md")))]: "allow",
175175
},
176+
bash: {
177+
"*": "deny",
178+
},
176179
}),
177180
user,
178181
),

‎packages/opencode/src/agent/subagent-permissions.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import type { Agent } from "./agent"
55
* Build the `permission` ruleset for a subagent's session when it's spawned
66
* via the task tool. Combines:
77
*
8-
* 1. The parent session's deny rules and external_directory rules.
9-
* Parent agent restrictions only govern that agent; the subagent's own
10-
* permissions determine its capabilities.
8+
* 1. The parent session's external_directory rules, plus deny rules for
9+
* write-capable permissions (edit, write, apply_patch, bash).
10+
* Broadly inheriting ALL parent denies (as done prior to this fix) breaks
11+
* subagents like `explore` that explicitly allow `bash` for read-only
12+
* operations — their own permission rules are overridden by inherited denies.
1113
* 2. Default `todowrite` and `task` denies if the subagent's own ruleset
1214
* doesn't already permit them.
1315
*/
16+
const WRITE_PERMISSIONS = new Set(["edit", "write", "apply_patch", "bash"])
17+
1418
export function deriveSubagentSessionPermission(input: {
1519
parentSessionPermission: PermissionV1.Ruleset
1620
subagent: Agent.Info
@@ -19,7 +23,9 @@ export function deriveSubagentSessionPermission(input: {
1923
const canTodo = input.subagent.permission.some((rule) => rule.permission === "todowrite")
2024
return [
2125
...input.parentSessionPermission.filter(
22-
(rule) => rule.permission === "external_directory" || rule.action === "deny",
26+
(rule) =>
27+
rule.permission === "external_directory" ||
28+
(rule.action === "deny" && WRITE_PERMISSIONS.has(rule.permission)),
2329
),
2430
...(canTodo ? [] : [{ permission: "todowrite" as const, pattern: "*" as const, action: "deny" as const }]),
2531
...(canTask ? [] : [{ permission: "task" as const, pattern: "*" as const, action: "deny" as const }]),

0 commit comments

Comments
 (0)