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
- Create a parent session via SDK with `permission: [{ permission: "external_directory", pattern: "/tmp/foo/*", action: "allow" }]`.
- Send a prompt with a `subtask` part targeting a subagent (e.g. `explore`).
- The subagent attempts to read `/tmp/foo/secret.txt`.
- 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
Description
When a parent session has an explicit
external_directoryallow rule (set via SDKsession.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 inheritedexternal_directoryallow. 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.tsaround line 1228. The task tool callsprompt()for the child session withtools: { task: false, todowrite: false }.SessionPrompt.promptconverts those into per-call permission rules and writes them tosession.permissionviasessions.setPermission, replacing whatever was there instead of merging. The child session is created moments earlier bysessions.createwith the derived rules fromderiveSubagentSessionPermission(including any inheritedexternal_directoryallows), 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.
Plugins
None
OpenCode version
dev (1.15.x, current upstream/dev as of this report)
Steps to reproduce
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