Skip to content

Subagent loses inherited external_directory allow when spawned via task tool #30527

@remorses

Description

@remorses

Description

When a parent session has an explicit external_directory allow rule (set via SDK session.create({ permission }) or via the session permission API), spawning a subtask through the task tool creates a child session whose permission ruleset does not contain the inherited external_directory allow. The subagent then asks the user for permission to read files in a directory the parent had already approved.

Root cause is in packages/opencode/src/session/prompt.ts around line 1228. The task tool calls prompt() for the child session with tools: { task: false, todowrite: false }. SessionPrompt.prompt converts those into per-call permission rules and writes them to session.permission via sessions.setPermission, replacing whatever was there instead of merging. The child session is created moments earlier by sessions.create with the derived rules from deriveSubagentSessionPermission (including any inherited external_directory allows), and the prompt-time write then clobbers them.

The fix is one line: merge the per-call tool rules into the existing `session.permission` instead of replacing it.

if (permissions.length > 0) {
  const merged = Permission.merge(session.permission ?? [], permissions)
  session.permission = merged
  yield* sessions.setPermission({ sessionID: session.id, permission: merged })
}

Plugins

None

OpenCode version

dev (1.15.x, current upstream/dev as of this report)

Steps to reproduce

  1. Create a parent session via SDK with `permission: [{ permission: "external_directory", pattern: "/tmp/foo/*", action: "allow" }]`.
  2. Send a prompt with a `subtask` part targeting a subagent (e.g. `explore`).
  3. The subagent attempts to read `/tmp/foo/secret.txt`.
  4. A pending `external_directory` permission request is emitted instead of the read succeeding.

After the fix the child session permission contains the inherited `external_directory` allow and the subagent reads the file directly.

Related issues

Closed issues that share this code path:

Open issues in the same area but not this exact bug:

Operating System

macOS 26

Terminal

iTerm2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions