Skip to content

fix(plan-mode): deny bash and scope subagent permission inheritance#33967

Open
kiltro-dev wants to merge 1 commit into
anomalyco:devfrom
kiltro-dev:fix/plan-mode-bash-enforcement
Open

fix(plan-mode): deny bash and scope subagent permission inheritance#33967
kiltro-dev wants to merge 1 commit into
anomalyco:devfrom
kiltro-dev:fix/plan-mode-bash-enforcement

Conversation

@kiltro-dev

@kiltro-dev kiltro-dev commented Jun 25, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #22641
Addresses #26700

Type of change

  • Bug fix

What does this PR do?

Plan mode blocks edit tools via the permission system, but bash is unrestricted because the plan agent config only denies the "edit" permission. The bash tool follows the default "*": "allow" rule, so the model can run arbitrary shell commands including writes.

Fix 1 — agent/agent.ts: Added bash: { "*": "deny" } to the plan agent permission config. Hides bash from the LLM tool list and throws DeniedError if called.

Fix 2 — agent/subagent-permissions.ts: The deriveSubagentSessionPermission function (from #26597) inherited ALL parent deny rules into subagent sessions, overriding subagents like explore that explicitly allow bash for read-only operations. Changed to only inherit denies for write-capable permissions (edit, write, apply_patch, bash) plus external_directory rules.

How did you verify your code works?

All 95 existing tests pass including the plan-mode-subagent-bypass test suite. The bash: deny from parent IS still inherited (bash is in WRITE_PERMISSIONS), while unrelated denies are not.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…n 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
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs that address similar permission inheritance and subagent permission issues:

  1. fix(task): respect subagent explicit edit:allow over inherited parent edit:deny #29235 - fix(task): respect subagent explicit edit:allow over inherited parent edit:deny

    • Directly addresses subagent permission inheritance conflicts, similar to the permission scoping issue in this PR
  2. fix(opencode): granular subagent edit permission inheritance #29778 - fix(opencode): granular subagent edit permission inheritance

    • Focuses on refining how edit permissions are inherited in subagent sessions
  3. fix(opencode): inherit MCP tool allow permissions in subagent sessions #30288 - fix(opencode): inherit MCP tool allow permissions in subagent sessions

    • Related to selective inheritance of permissions in subagents, addressing similar concerns about inherited deny rules

These PRs tackle related aspects of the permission inheritance problem that this PR addresses. While they're not exact duplicates of PR #33967, they share the same domain (subagent permission inheritance and scope management). You may want to review them to ensure consistency in approach and avoid redundant work.

@kiltro-dev kiltro-dev changed the title fix(plan-mode): enforce bash restriction via permission config and scope subagent deny inheritance fix(plan-mode): deny bash and scope subagent permission inheritance Jun 25, 2026
@github-actions github-actions Bot removed needs:issue needs:compliance This means the issue will auto-close after 2 hours. labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan mode does not prevent write operations via Bash tool

1 participant