Skip to content

Feature: persist option on command agent — keep agent selection after command completes #37337

Description

@CDogg99

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:

{
  "command": {
    "debug": {
      "template": "...",
      "agent": "debug",
      "persist": true
    }
  }
}

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions