Skip to content

[FEATURE]: keep the tab's model when switching between plan and build #54375

Open

Description

@cleardevice

Feature hasn't been suggested before.

  • 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.

Reference implementation, without the setting yet, on top of #54367: https://github.com/cleardevice/opencode/tree/feat/tui-shared-agent-model

Activity

  1. opencode-agent commented on Oct 10, 2026

    @opencode-agent
    Contributor

    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.

    Related issues:

    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.

  2. lainwir3d commented on Oct 12, 2026

    @lainwir3d

    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

  3. cleardevice commented on Oct 12, 2026

    @cleardevice
    Author

    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.

  4. soda92 commented on Oct 15, 2026

    @soda92

    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.

  5. lainwir3d commented on Oct 15, 2026

    @lainwir3d

    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:

    • 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

  6. cleardevice commented on Oct 15, 2026

    @cleardevice
    Author

    @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.

  7. Caleb9 commented on Oct 16, 2026

    @Caleb9

    Hello!

    Confirmed the same behavior on stable 2.0.31 (also traced through the source at dev 0a03b4b). 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):

    1. In a session with agent build, switch to plan (Tab) and select model B via /models.
    2. Switch back to build and select model A.
    3. 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.

    Thanks!

  8. Lyapnev commented on Nov 8, 2026

    @Lyapnev

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions