Skip to content

Commit 5dd60c1

Browse files
backnotpropclaude
andauthored
fix: replace plan mode prompt instead of stripping it (#341)
Instead of nuking OpenCode's STRICTLY FORBIDDEN plan mode message entirely (which left the model with no prompt-level guardrails, causing it to go rogue and edit code via bash+python), replace it with a tailored version that allows markdown file writing while keeping all other restrictions. Fixes #328 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5e940db commit 5dd60c1

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

apps/opencode-plugin/index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,34 @@ export const PlannotatorPlugin: Plugin = async (ctx) => {
193193
};
194194
},
195195

196-
// Strip OpenCode's "STRICTLY FORBIDDEN" plan mode prompt from synthetic
197-
// user messages. OpenCode injects these to prevent file edits in plan mode,
198-
// but we need the agent to be able to write plan files.
196+
// Replace OpenCode's "STRICTLY FORBIDDEN" plan mode prompt with a version
197+
// that allows markdown file writing. OpenCode's original blocks ALL file edits,
198+
// but we need the agent to write plans, specs, docs, etc.
199199
"experimental.chat.messages.transform": async (input, output) => {
200200
for (const message of output.messages) {
201201
if (message.info.role !== "user") continue;
202-
message.parts = message.parts.filter(
203-
(part: any) => !(part.type === "text" && part.text?.includes("STRICTLY FORBIDDEN"))
204-
);
202+
for (const part of message.parts as any[]) {
203+
if (part.type !== "text" || !part.text?.includes("STRICTLY FORBIDDEN")) continue;
204+
part.text = `<system-reminder>
205+
# Plan Mode - System Reminder
206+
207+
CRITICAL: Plan mode ACTIVE. You are in a PLANNING phase. The ONLY file modifications
208+
allowed are writing or editing markdown files (.md) — plans, specs, documentation, etc.
209+
All other file edits, code modifications, and system changes are STRICTLY FORBIDDEN.
210+
Do NOT use bash commands to manipulate non-markdown files. Commands may ONLY read/inspect.
211+
212+
## Responsibility
213+
214+
Your responsibility is to think, read, search, and delegate explore agents to construct
215+
a well-formed plan. Ask the user clarifying questions and surface tradeoffs rather than
216+
making assumptions about intent. Use submit_plan to submit your plan for user review.
217+
218+
## Important
219+
220+
The user wants a plan, not execution. You MUST NOT edit source code, run non-readonly
221+
tools (except writing markdown files), or otherwise make changes to the system.
222+
</system-reminder>`;
223+
}
205224
}
206225
},
207226

0 commit comments

Comments
 (0)