Problem
When a custom command specifies an agent field (e.g., /debug with agent: debug), the command executes with that agent but the TUI agent selector reverts to the previously selected agent afterward. This means after running /debug, the user is still on the Build agent for their next message.
Users with multiple primary agents for distinct workflows (/plan, /build, /debug, /research) expect the agent switch to persist — if you invoke the debug command, you likely want to stay in the debug agent for follow-up messages.
Proposal
Add an optional persist field to command definitions that, when true, causes the agent switch from the agent field to persist after command execution.
In opencode.json:
In markdown command frontmatter:
---
description: Debug a bug
agent: debug
persist: true
---
## Workflow
...
Behavior
agent set |
persist |
Result |
| No |
No |
Uses current agent (no change) |
| Yes |
No (default) |
Uses specified agent for this invocation only, reverts after (current behavior) |
| Yes |
Yes |
Uses specified agent and keeps it selected in TUI after completion |
Use Case
Dedicated primary agents for different workflows:
# /plan → agent: plan, persist: true
# /build → agent: build, persist: true
# /debug → agent: debug, persist: true
# /research → agent: research, persist: true
Each command switches the user into the right mode for their task and keeps them there for follow-up.
Alternatives Considered
- Plugin-based agent switching: Not possible — no plugin hook exposes agent mutation (all hooks receive
agent as read-only input, never as mutable output).
- Subagent workaround: Using
subtask: true isolates command execution but does not give the user an interactive primary agent experience.
Problem
When a custom command specifies an
agentfield (e.g.,/debugwithagent: debug), the command executes with that agent but the TUI agent selector reverts to the previously selected agent afterward. This means after running/debug, the user is still on the Build agent for their next message.Users with multiple primary agents for distinct workflows (
/plan,/build,/debug,/research) expect the agent switch to persist — if you invoke the debug command, you likely want to stay in the debug agent for follow-up messages.Proposal
Add an optional
persistfield to command definitions that, whentrue, causes the agent switch from theagentfield to persist after command execution.In
opencode.json:{ "command": { "debug": { "template": "...", "agent": "debug", "persist": true } } }In markdown command frontmatter:
Behavior
agentsetpersistUse Case
Dedicated primary agents for different workflows:
Each command switches the user into the right mode for their task and keeps them there for follow-up.
Alternatives Considered
agentas read-onlyinput, never as mutableoutput).subtask: trueisolates command execution but does not give the user an interactive primary agent experience.