fix(agent): prevent hidden agents from switching the active mode#382
Merged
sudo-tee merged 2 commits intoMay 20, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_modelrestores 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_commandinworkflow.luachecksconfig_file.get_opencode_agents()before callingswitch_to_mode, silently skipping hidden agents without throwing an errorsend_messageinmessaging.luaonly callsset_modewhen the agent is in the visible agents listinitialize_current_modelinagent_model.luaonly restores a mode from prior messages when it belongs to a visible agentVisible command agents (e.g.
build) continue to switch the mode as expected, matching TUI behavior.