anomalyco / anomalyco/opencode
[BUG] Agent switches to Plan mode mid-loop between tool calls without user action
@jlongster is already working on this.
Since Sep 8, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
While the agent (custom primary agent prod, model opencode/big-pickle) was executing a single agentic run, it suddenly switched into Plan mode between two tool calls – without any user action (no Tab press, no agent switch, no new user message).
The agent had just successfully completed a write tool call (created an HTML file) and was about to run the next step (weasyprint to convert to PDF). Instead, the next loop step started with the Plan-mode system reminder active, so the agent refused to execute any further tools and only reported that it was in Plan mode.
Evidence from the session database
All 25 messages in the session have agent: "prod" and mode: "prod" – the agent was never switched in the database. There is also no agent.changed / mode event in the event table.
The part timeline shows the switch happened mid-run:
| Time | Part | Event |
|---|---|---|
| 17:00:46 | step-start | Agent: "Weasyprint is available. I'll create the PDF." |
| 17:00:49 | tool (write) | HTML file written successfully |
| 17:01:55 | step-finish | reason: "tool-calls" → loop continues |
| 17:02:00 | step-start | Reasoning: "The user said 'Continue' but I'm in Plan Mode (read-only)" |
| 17:02:03 | text | Agent reports it is in Plan mode and cannot run tools |
The agent's reasoning mentions "The user said 'Continue'", but there is no user message "Continue" in the database – suggesting a synthetic continue mechanism that resumes the last response without storing a user message, and which appears to corrupt the agent state.
Root cause hypothesis
SessionReminders.apply (packages/opencode/src/session/reminders.ts) injects the Plan-mode reminder only when input.agent.name === "plan":
if (input.agent.name === "plan") {
userMessage.parts.push({ text: PROMPT_PLAN, synthetic: true })
}
This runs on every loop step. Since lastUser.agent is prod in the DB, the reminder should never have been injected. It was injected anyway – meaning the agent value used for the loop step diverged from the persisted session state mid-run.
Steps to reproduce (only some times)
- Start opencode TUI with a custom primary agent (e.g.
prod) that has full tool permissions. - Ask the agent to perform a multi-step task (e.g. "create an HTML file and convert it to PDF").
- Let the agent complete the first tool call (e.g.
write). - Observe the next loop step: the agent is suddenly in Plan mode and refuses to run further tools.
Expected behavior
The agent should remain in its current mode (Build/prod) throughout the entire agentic run. Plan mode should only activate when the user explicitly switches to the Plan agent (Tab key).
Actual behavior
The agent switches to Plan mode mid-run between tool calls, without user action, and refuses to execute further tools.
Environment
- OpenCode: 1.18.29 (TUI),
opencode serve1.18.25 running in parallel on port 4100 - OS: Linux (Debian 13)
- Model:
opencode/big-pickle - Agent: custom primary agent
prod(mode: "all")
Related issues
- #42764 – Plan/build mode auto-toggles every turn
- #42439 – Build agent remains in Plan mode after reverting
- #33608 – Switching from Plan mode to Build mode makes Build non-functional
Plugins
opencode-token-monitor@latest opencode-token-usage@latest clipboard.ts moshi-hooks.ts purge.ts
OpenCode version
1.18.29
Steps to reproduce
( Only Sometimes )
- Start opencode TUI with a custom primary agent (e.g.
prod) that has full tool permissions. - Ask the agent to perform a multi-step task (e.g. "create an HTML file and convert it to PDF").
- Let the agent complete the first tool call (e.g.
write). - Observe the next loop step: the agent is suddenly in Plan mode and refuses to run further tools.
Screenshot and/or share link
Operating System
Debian 13
Terminal
OpenSSH over Windows Terminal
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.