[PR #13427] fix: add hard enforcement for plan mode restrictions #14662

Closed
opened 2026-02-16 18:19:26 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13427

State: closed
Merged: No


Fixes #10314

Problem

Plan mode was relying solely on text reminders in the system prompt, allowing models to bypass restrictions and make file changes via destructive bash commands (sed, rm, etc).

Solution

Add runtime validation that blocks destructive operations in plan mode:

  • Block destructive commands: rm, mv, cp, sed, awk, tee, chmod, mkdir, etc.
  • Block package managers: npm install, yarn add, pip install
  • Block git write operations: git commit, git push, git reset
  • Block dangerous characters: backticks, newline injection
  • Allow read-only commands: ls, cat, grep, git status/diff/log

Files Changed

  • src/permission/plan-mode.ts - Command validator
  • src/permission/plan-mode.test.ts - 33 test cases
  • src/tool/bash.ts - Plan mode check before execution
  • src/tool/edit.ts - Block in plan mode
  • src/tool/write.ts - Block in plan mode
  • src/tool/apply_patch.ts - Block in plan mode

Testing

bun test  # 969 pass, 5 skip, 0 fail
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13427 **State:** closed **Merged:** No --- Fixes #10314 ## Problem Plan mode was relying solely on text reminders in the system prompt, allowing models to bypass restrictions and make file changes via destructive bash commands (sed, rm, etc). ## Solution Add runtime validation that blocks destructive operations in plan mode: - Block destructive commands: `rm`, `mv`, `cp`, `sed`, `awk`, `tee`, `chmod`, `mkdir`, etc. - Block package managers: `npm install`, `yarn add`, `pip install` - Block git write operations: `git commit`, `git push`, `git reset` - Block dangerous characters: backticks, newline injection - Allow read-only commands: `ls`, `cat`, `grep`, `git status/diff/log` ## Files Changed - `src/permission/plan-mode.ts` - Command validator - `src/permission/plan-mode.test.ts` - 33 test cases - `src/tool/bash.ts` - Plan mode check before execution - `src/tool/edit.ts` - Block in plan mode - `src/tool/write.ts` - Block in plan mode - `src/tool/apply_patch.ts` - Block in plan mode ## Testing ``` bun test # 969 pass, 5 skip, 0 fail ```
yindo added the pull-request label 2026-02-16 18:19:26 -05:00
yindo closed this issue 2026-02-16 18:19:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14662