Skip to content

fix: OpenCode plan mode permissions and prompt conflicts - #329

Merged
backnotprop merged 2 commits into
mainfrom
fix/oc-plan-permissions
Mar 18, 2026
Merged

backnotprop merged 2 commits into
mainfrom
fix/oc-plan-permissions

Conversation

@backnotprop

@backnotprop backnotprop commented Mar 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Fix PermissionDeniedError when the plan agent tries to write .md files — adds per-agent edit permission (*.md: allow) scoped to the plan agent only via opencodeConfig.agent.plan.permission.edit
  • Strip OpenCode's conflicting "STRICTLY FORBIDDEN" plan mode prompt from synthetic user message parts
  • Replace TodoWrite/planning instructions in the base prompt when plan agent is active, so the model follows the plan file workflow instead of creating todos
  • Override todowrite tool description to redirect to submit_plan
  • Enhance submit_plan tool description with planning workflow guidance
  • Add <system-reminder> reinforcing plan mode behavior on every turn
  • Disable validatePlanPath directory restriction so plans can be written anywhere
  • Strengthen planning prompt with explicit anti-TodoWrite language and required workflow summary

Related issues

Fixes #328

Also addresses upstream OpenCode issues:

Test plan

  • Run ./tests/manual/local/sandbox-opencode.sh and enter plan mode
  • Ask the agent to create a plan — verify it writes to the XDG plans dir and calls submit_plan
  • Verify the agent does not use TodoWrite for planning
  • Verify non-plan agents (build, explore) are unaffected
  • Test in a non-git project directory to confirm permission fix

- Add per-agent edit permission (*.md allow) for the plan agent via
  opencodeConfig.agent.plan.permission.edit, fixing the path.relative
  worktree mismatch that caused PermissionDeniedError on plan writes
- Strip OpenCode's "STRICTLY FORBIDDEN" plan mode prompt from synthetic
  user message parts via experimental.chat.messages.transform
- Replace conflicting TodoWrite/planning instructions in the base prompt
  when plan agent is active (surgical replacements + global sweep)
- Override todowrite tool description to redirect to submit_plan
- Enhance submit_plan tool description with planning workflow guidance
- Add system-reminder reinforcing plan mode behavior on every turn
- Disable validatePlanPath directory restriction (plans can be written
  anywhere)
- Strengthen planning prompt with explicit anti-TodoWrite language,
  required workflow summary, and mkdir instruction

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@backnotprop

backnotprop commented Mar 18, 2026 •

Copy link
Copy Markdown
Owner Author

Code review

Found 1 issue:

  1. validatePlanPath directory restriction fully disabled — submit_plan now accepts any absolute path. If the agent hallucinates or is prompt-injected to pass a sensitive file path (e.g. ~/.ssh/id_rsa), it will be read via readFileSync and displayed in the browser review UI. The original containment check existed as a security boundary. Consider adding a minimal guard (e.g. path must end in .md, or must be under $HOME) rather than removing the check entirely.

https://github.com/backnotprop/plannotator/blob/aa6d74d6e6e16b5bbcecde20e2b4e9e4a1dfec9c/apps/opencode-plugin/plan-mode.ts#L34-L56

@backnotprop
backnotprop merged commit 3378269 into main Mar 18, 2026
3 of 5 checks passed
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.

submit_plan not appear after plan is finished

1 participant