You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FEATURE]: keep the tab's model when switching between plan and build #54375
I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Switching agents with Tab restores the model each agent last used in the session (#47260). An agent without a configured model and without an earlier choice in the session falls back to the global default or the shared recent list, which is the model last picked in any tab or client. In practice I pick one model for a task and switch between plan and build several times, and expect that model to stay.
Proposal: agents without a configured model take the tab's current selection (model and variant) when switching. Agents with model in their config keep the current behavior, so a dedicated planning model still works. Since per-agent memory was added on purpose, this could be a TUI setting, for example session.agent_model: "per-agent" | "shared", with per-agent as the default.
Thanks for the detailed proposal and the reference branch!
To restate it: when you switch between primary agents with Tab, agents that have no model in their config would keep the tab's current model and variant instead of the model remembered for that agent or the shared default. Agents with a configured model would keep their current behavior. This could be an opt-in TUI setting such as session.agent_model: "shared". Maintainers will consider it.
Agree. Very irritating when switching between loads of different sessions with different models. Has costed me a lot of tokens because of course cache can't be hit like that. Also cause confidentiality issue when switching between personal projects / models and work related ones.
Well, I choose a different model in Plan, and when I want to build - I press shift_tab - it will switch to prev model, which result in low response time (because of context resend) and even compression (different model have different context limits) - so I think this feature/setting was helpful.
Plan / Build mode models are also shared between tabs so if you use a build model X for on tab A, then switch to tab B that was in Plan mode with model B and switch it to build mode it will use model X silentely.
Workflow:
Tab A - build mode - model X
SWITCH MODE
Tab A - plan mode - model X
CHANGE TAB TO TAB B
Tab B - build mode - model X
SWITCH MODEL
Tab B - build mode - model Y
SWITCH TAB
Tab A - plan mode - model X
SWITCH MODE - Tab A - build mode - model Y
This is approximately what's happening. A silent model switch. Causing loads of slow down, token usage, and privacy concern depending on model
@lainwir3d thanks, reproduced on dev with a test. If build has no model of its own (and no global model is set) and hasn't been used in that tab since the session was opened, e.g. after a restart, it takes the model picked last in any tab. #54367 doesn't fix this; the reference branch above keeps the tab's model in this case.
@soda92 yours is the per-agent memory from #47260 working as designed; the setting proposed here would let you turn it off.
Confirmed the same behavior on stable 2.0.31 (also traced through the source at dev0a03b4b). A couple of concrete data points in support of the proposed session.agent_model: "shared" option:
The re-application is pure TUI client state — the server's model is session-wide and survives agent switches. The session row stores a single model, and POST /api/session/{id}/agent does not touch it. Verified with a scratch session: after switching Plan → Build, the server-side model was unchanged. So after an agent switch the TUI composer and the server model briefly disagree until the user re-selects or submits.
Exact code locations (2.0.31):
packages/tui/src/context/local.tsx — the selectionBySessionAgent map; agent.set() calls model.remember(), which stashes the outgoing agent's model, and the composer then reads the incoming agent's remembered model.
packages/tui/src/component/prompt/index.tsx — the remembered agent/model pair is committed on submit (switchAgent / switchModel).
/data/state/opencode/model.json (TUI state) only holds the global recent-model/variant list, not per-agent state — so the per-agent memory is not persisted anywhere server-side.
Repro on 2.0.31 (single local OpenAI-compatible endpoint, no agents.*.model pinned):
In a session with agent build, switch to plan (Tab) and select model B via /models.
Switch back to build and select model A.
Tab back to plan — the composer shows B again, even though the last explicit selection was A. The session DB shows an agent-switched event immediately followed by a model-switched event with no user message in between.
The shared option (last explicit selection wins across agents) would fix the common single-model case, and keeping per-agent as the default preserves the intentional behavior for anyone relying on it. The proposed knob is exactly the right shape for that.
Same here. I pick a model for a task and then Shift+Tab between plan/build/architect; the first switch to an agent that has no model chosen in that session jumps back to the global default, and the next request re-sends the whole context to a different model (prompt cache miss, sometimes different context limits).
A session.agent_model: "shared" option would cover this exactly: when an agent has no model configured, keep the tab's current selection (model and variant) instead of the per-agent memory or the global default.
Activity
opencode-agent commentedon Oct 10, 2026
Thanks for the detailed proposal and the reference branch!
To restate it: when you switch between primary agents with Tab, agents that have no
modelin their config would keep the tab's current model and variant instead of the model remembered for that agent or the shared default. Agents with a configuredmodelwould keep their current behavior. This could be an opt-in TUI setting such assession.agent_model: "shared". Maintainers will consider it.Related issues:
OPENCODE_AGENTS_SWITCH_SINGLE_MODELenv var). It was closed as stale.A plugin can't do this today: the TUI plugin API can set the variant but not the model, and it has no hook for agent switches.
lainwir3d commentedon Oct 12, 2026
Agree. Very irritating when switching between loads of different sessions with different models. Has costed me a lot of tokens because of course cache can't be hit like that. Also cause confidentiality issue when switching between personal projects / models and work related ones.
It should probably be a setting I guess
cleardevice commentedon Oct 12, 2026
Thanks! If your case is switching between sessions/tabs (not plan ↔ build), that's #54363 — fixed in #54367. A 👍 or your scenario there would help.
soda92 commentedon Oct 15, 2026
Well, I choose a different model in Plan, and when I want to build - I press shift_tab - it will switch to prev model, which result in low response time (because of context resend) and even compression (different model have different context limits) - so I think this feature/setting was helpful.
lainwir3d commentedon Oct 15, 2026
Yeah that's exactly it.
Plan / Build mode models are also shared between tabs so if you use a build model X for on tab A, then switch to tab B that was in Plan mode with model B and switch it to build mode it will use model X silentely.
Workflow:
SWITCH MODE
CHANGE TAB TO TAB B
SWITCH MODEL
SWITCH TAB
SWITCH MODE
- Tab A - build mode - model Y
This is approximately what's happening. A silent model switch. Causing loads of slow down, token usage, and privacy concern depending on model
cleardevice commentedon Oct 15, 2026
@lainwir3d thanks, reproduced on
devwith a test. If build has nomodelof its own (and no globalmodelis set) and hasn't been used in that tab since the session was opened, e.g. after a restart, it takes the model picked last in any tab. #54367 doesn't fix this; the reference branch above keeps the tab's model in this case.@soda92 yours is the per-agent memory from #47260 working as designed; the setting proposed here would let you turn it off.
Caleb9 commentedon Oct 16, 2026
Hello!
Confirmed the same behavior on stable 2.0.31 (also traced through the source at
dev0a03b4b). A couple of concrete data points in support of the proposedsession.agent_model: "shared"option:The re-application is pure TUI client state — the server's model is session-wide and survives agent switches. The
sessionrow stores a singlemodel, andPOST /api/session/{id}/agentdoes not touch it. Verified with a scratch session: after switching Plan → Build, the server-side model was unchanged. So after an agent switch the TUI composer and the server model briefly disagree until the user re-selects or submits.Exact code locations (2.0.31):
packages/tui/src/context/local.tsx— theselectionBySessionAgentmap;agent.set()callsmodel.remember(), which stashes the outgoing agent's model, and the composer then reads the incoming agent's remembered model.packages/tui/src/component/prompt/index.tsx— the remembered agent/model pair is committed on submit (switchAgent/switchModel)./data/state/opencode/model.json(TUI state) only holds the global recent-model/variant list, not per-agent state — so the per-agent memory is not persisted anywhere server-side.Repro on 2.0.31 (single local OpenAI-compatible endpoint, no
agents.*.modelpinned):build, switch toplan(Tab) and select model B via/models.buildand select model A.plan— the composer shows B again, even though the last explicit selection was A. The session DB shows anagent-switchedevent immediately followed by amodel-switchedevent with no user message in between.The
sharedoption (last explicit selection wins across agents) would fix the common single-model case, and keepingper-agentas the default preserves the intentional behavior for anyone relying on it. The proposed knob is exactly the right shape for that.Thanks!
Lyapnev commentedon Nov 8, 2026
Same here. I pick a model for a task and then Shift+Tab between plan/build/architect; the first switch to an agent that has no model chosen in that session jumps back to the global default, and the next request re-sends the whole context to a different model (prompt cache miss, sometimes different context limits).
A
session.agent_model: "shared"option would cover this exactly: when an agent has nomodelconfigured, keep the tab's current selection (model and variant) instead of the per-agent memory or the global default.