[PR #4514] Fixed TUI agent switching to respect configured models #11000

Closed
opened 2026-02-16 18:15:46 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4514

State: closed
Merged: No


Perfect! I've successfully fixed the TUI agent switching issue. Here's a summary of what I implemented:

Fix Summary

Problem: When switching between agents in the TUI, the model selection didn't respect each agent's configured default model. The model would either stick to the previous agent's model or require manual changes.

Root Cause: The automatic model update effect was outside the model function where modelStore wasn't accessible, and it always tried to update to the agent's configured model, overriding user manual selections.

Solution:

  1. Moved the logic inside the model function where modelStore is accessible
  2. Added agent switch detection by tracking the previous agent name
  3. Made the update conditional - only update to the agent's configured model when:
    • The agent actually switches (not just re-renders)
    • The agent has a configured model
    • The user hasn't manually set a model for this agent
  4. Preserved the priority order for model selection:
    • User's manual selection for the agent (highest priority)
    • Agent's configured default model
    • Global fallback model

Key Changes in packages/opencode/src/cli/cmd/tui/context/local.tsx:156-178:

  • Added previousAgentName tracking to detect actual agent switches
  • Only update model when previousAgentName !== agentName
  • Only update if agent has configured model AND no user manual selection exists
  • Moved the effect inside the model function where modelStore is accessible

This fix ensures that:

  • Agents with configured models automatically switch to their configured model when selected
  • User manual model selections are preserved and respected
  • Built-in agents without configured models fall back to global defaults
  • The model selection "sticks" properly when switching between agents

The fix addresses the exact issue described in #4344 where switching between Builder mode and Plan mode didn't respect each agent's configured model.

Closes #4344

New%20session%20-%202025-11-19T23%3A19%3A47.294Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4514 **State:** closed **Merged:** No --- Perfect! I've successfully fixed the TUI agent switching issue. Here's a summary of what I implemented: ## Fix Summary **Problem**: When switching between agents in the TUI, the model selection didn't respect each agent's configured default model. The model would either stick to the previous agent's model or require manual changes. **Root Cause**: The automatic model update effect was outside the model function where `modelStore` wasn't accessible, and it always tried to update to the agent's configured model, overriding user manual selections. **Solution**: 1. **Moved the logic inside the model function** where `modelStore` is accessible 2. **Added agent switch detection** by tracking the previous agent name 3. **Made the update conditional** - only update to the agent's configured model when: - The agent actually switches (not just re-renders) - The agent has a configured model - The user hasn't manually set a model for this agent 4. **Preserved the priority order** for model selection: - User's manual selection for the agent (highest priority) - Agent's configured default model - Global fallback model **Key Changes in `packages/opencode/src/cli/cmd/tui/context/local.tsx:156-178`**: - Added `previousAgentName` tracking to detect actual agent switches - Only update model when `previousAgentName !== agentName` - Only update if agent has configured model AND no user manual selection exists - Moved the effect inside the model function where `modelStore` is accessible This fix ensures that: - ✅ Agents with configured models automatically switch to their configured model when selected - ✅ User manual model selections are preserved and respected - ✅ Built-in agents without configured models fall back to global defaults - ✅ The model selection "sticks" properly when switching between agents The fix addresses the exact issue described in #4344 where switching between Builder mode and Plan mode didn't respect each agent's configured model. Closes #4344 <a href="https://opencode.ai/s/eDX1Nomd"><img width="200" alt="New%20session%20-%202025-11-19T23%3A19%3A47.294Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI1LTExLTE5VDIzOjE5OjQ3LjI5NFo=.png?model=opencode/glm-4.6&version=1.0.78&id=eDX1Nomd" /></a> [opencode session](https://opencode.ai/s/eDX1Nomd)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/sst/opencode/actions/runs/19519318807)
yindo added the pull-request label 2026-02-16 18:15:46 -05:00
yindo closed this issue 2026-02-16 18:15:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11000