Skip to content

fix(agent): prevent hidden agents from switching the active mode#382

Merged
sudo-tee merged 2 commits into
sudo-tee:mainfrom
hermandavid:fix/prevent-hidden-agent-mode-switch
May 20, 2026
Merged

fix(agent): prevent hidden agents from switching the active mode#382
sudo-tee merged 2 commits into
sudo-tee:mainfrom
hermandavid:fix/prevent-hidden-agent-mode-switch

Conversation

@hermandavid
Copy link
Copy Markdown
Contributor

Problem

When a slash command uses a hidden agent, the plugin switches the active mode to that hidden agent. This causes the mode indicator to show an agent the user cannot manually select, and breaks subsequent messaging since the mode no longer corresponds to a visible agent.

Additionally, when reopening a session where the last message was sent by a hidden agent, initialize_current_model restores that hidden agent as the active mode.

Solution

Guard mode switching so only visible (non-hidden, non-disabled) agents can become the active mode:

  • run_user_command in workflow.lua checks config_file.get_opencode_agents() before calling switch_to_mode, silently skipping hidden agents without throwing an error
  • send_message in messaging.lua only calls set_mode when the agent is in the visible agents list
  • initialize_current_model in agent_model.lua only restores a mode from prior messages when it belongs to a visible agent

Visible command agents (e.g. build) continue to switch the mode as expected, matching TUI behavior.

When a slash command uses a custom hidden agent, the plugin was
switching the global current_mode to that hidden agent. Since hidden
agents are filtered from the mode picker and M-m cycle, the user
would get stuck with no way to switch back.

The OpenCode TUI handles this by only switching mode when the agent
is visible (not hidden). Match that behavior in both code paths that
set the mode:

- messaging.send_message: check agent against visible agents list
  before calling set_mode
- agent_model.initialize_current_model: skip restoring mode from
  messages when the message's agent is hidden
run_user_command sends commands via api_client:send_command which
bypasses messaging.send_message, so the mode was never updated
when a command specified a visible agent. Call switch_to_mode
before sending the command so visible agents switch the mode
(matching TUI behavior), while hidden agents are silently skipped
by switch_to_mode's existing validation.
@sudo-tee sudo-tee merged commit 36d313d into sudo-tee:main May 20, 2026
5 checks passed
@hermandavid hermandavid deleted the fix/prevent-hidden-agent-mode-switch branch May 20, 2026 12:55
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.

2 participants