GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Feature Request: Retain current model and agent selection when switching sessions · Issue #4930 · anomalyco/opencode

Feature Request: Retain current model and agent selection when switching sessions #4930

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Feature Request: Retain current model and agent selection when switching sessions#4930
Copy link
Assignees
jlongster

Description

@JosXa
JosXa
opened on Dec 1, 2025
Issue body actions

Feature Request: Retain current model and agent selection when switching sessions

Problem Description

When switching between sessions using Ctrl+X l, the session loads with whatever model and agent we were currently using. This forces users to manually reselect their preferred model and agent every time they switch sessions, which disrupts workflow continuity.

Current Behavior

  • User has Session A open with Model X and Agent Y
  • User switches to Session B using Ctrl+X l
  • Session B loads with whatever model and agent it was last using (e.g., Model Z and Agent W)
  • User must manually change model and agent back to their preferred selection

Desired Behavior

  • User has Session A open with Model X and Agent Y
  • User switches to Session B using Ctrl+X l
  • Session B loads but retains the session's last model and agent selection (Model X and Agent Y)
  • User can continue working without manual reconfiguration

Rationale

Users choose the best model and agent for a specific task. Each session serves a specific task, so the current model and agent selection should follow the user as they switch between sessions, rather than being locked to whatever a session was previously configured with.

Implementation Suggestion

Add a setting or default behavior where the current model and agent selection persists across session switches, rather than being tied to the global opencode CLI.

Additional Context

This is different from issue #4344 (model selection not sticking between agent alternation) - this is specifically about session switching via Ctrl+X l retaining the current user's model and agent preferences.

Reacted by Dan Brown, kaanmertkoc, Erwin Kroon, Art Shendrik, a2k and Kevin Cox

Activity

Next
  1. github-actions commented on Dec 1, 2025

    @github-actions
    github-actionsBot
    on Dec 1, 2025 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of existing issues. Please check:

    • Selected model for agent in TUI doesn't stick between Agent Alternation #4344: Selected model for agent in TUI doesn't stick between Agent Alternation (related model persistence issue)
    • In Home screen, models stick across agents switching. #4742: In Home screen, models stick across agents switching (related inconsistency with model selection persistence)
    • Switching to a child session doesn't send subsequent messages to that session but to the parent one #2390: Switching to a child session doesn't send subsequent messages to that session but to the parent one (related session switching behavior issue)

    Feel free to ignore if none of these address your specific case.

  2. rekram1-node
    self-assigned this
    on Dec 2, 2025
  3. rekram1-node
    added
    good first issueGood for newcomers
    on Dec 2, 2025
  4. rekram1-node
    removed their assignment
    on Dec 2, 2025
  5. rekram1-node commented on Dec 2, 2025

    @rekram1-node
    rekram1-node
    on Dec 2, 2025
    Member
    More actions

    Yeah that makes sense

    Reacted by Joscha Götzer and Art Shendrik
  6. rekram1-node
    added
    help-wanted
    on Dec 2, 2025
  7. phongndo commented on Dec 3, 2025

    @phongndo
    phongndo
    on Dec 3, 2025
    More actions

    I’d like to take this. Sessions in opencode don’t currently persist model/agent;
    they’re tracked as global TUI state.

    I see two approaches:

    • A: Derive model/agent from the session’s last user message (good for existing data, but undefined for empty/new sessions).
    • B: Add defaultModel / defaultAgent to Session.Info and have the TUI (and other clients) respect those as the per-session defaults.

    What approach is best? I'm leaning toward B, it fits the "sessions serve specific tasks" rationale better.
    Would love to contribute once there is a clear direction!

  8. JosXa commented on Dec 3, 2025

    @JosXa
    JosXa
    on Dec 3, 2025
    ContributorAuthor
    More actions

    Thanks @ph8n! 😊

    Both aporoaches would be functionally equivalent.
    B feels cleaner to me, but I'm not very familiar with the codebase. Both of them could serve a getSessionAgent and getSessionProvider API to expose these things also for other use cases.

    Arguably, a "default" for a session is kinda meaningless, right? Like, it's always what you last used - so the term "current" may just aswell be used to not confuse it with global defaults?

  9. phongndo commented on Dec 4, 2025

    @phongndo
    phongndo
    on Dec 4, 2025
    More actions

    @JosXa Good point, "currentModel"/"currentAgent" is much clearer than "default" since it's always what you last used.

    @rekram1-node Noticed you labeled this as a good first issue. If the Option B approach sounds good, I'll proceed with extending Session.Info, updating on changes, exposing getters, and reading on switch.

    Does this plan cover everything, or am I missing something?

  10. rekram1-node commented on Dec 4, 2025

    @rekram1-node
    rekram1-node
    on Dec 4, 2025
    Member
    More actions

    Hm I think I'm realizing i may have misunderstood op

    So is the expectation that whenever you switch sessions it switches to whatever model was last used in that session?

    Hmmm

  11. phongndo commented on Dec 4, 2025

    @phongndo
    phongndo
    on Dec 4, 2025
    More actions

    @JosXa can you clarify the wanted behavior?

  12. JosXa commented on Dec 4, 2025

    @JosXa
    JosXa
    on Dec 4, 2025
    ContributorAuthor
    More actions

    Hm I think I'm realizing i may have misunderstood op

    So is the expectation that whenever you switch sessions it switches to whatever model was last used in that session?

    Hmmm

    Yes, exactly.

    I wanna be able to work on sessions in parallel, not have to reconfigure models and the agent every.single.time I switch between them.

    Not a fan?

  13. rekram1-node commented on Dec 4, 2025

    @rekram1-node
    rekram1-node
    on Dec 4, 2025
    Member
    More actions

    The more i think about it I actually do think i like it? initially i didnt but lemme ask

  14. ry2009 commented on Dec 9, 2025

    @ry2009
    ry2009
    on Dec 9, 2025
    Contributor
    More actions

    @JosXa check out this PR and lmk what you think it should be solved lmk if any errors pop up or any additional requests: #5264

  15. jdanbrown commented on Dec 9, 2025

    @jdanbrown
    jdanbrown
    on Dec 9, 2025
    Contributor
    More actions

    +1 I found this issue because I was just surprised when resuming a past session didn't restore the agent I was using in that session.

    I agree with the rationale at top that sessions represent a user's task, and the user already made a meaningful choice of model and agent for that task. Currently, it's jarring when I run opencode -s <session> and see my old task with the wrong agent and/or model — usually what happens is I send my first message, and only then notice that the agent/model aren't what I expected, and then I have to undo and switch agent/model and then submit it again.

    Making agent/model sticky to the session seems like the least surprising UX to me.

    Reacted by Joscha Götzer, Phong Do, Ayush Walekar, kaanmertkoc and bhargav-nexie
  16. 4 remaining items

  17. ShpetimA commented on Dec 29, 2025

    @ShpetimA
    ShpetimA
    on Dec 29, 2025
    Contributor
    More actions

    @snaselj A session creation doesn't have an agent attached only when you send a message for that session will the tui change the default selection to the latest message created with model/agent.
    Though i saw your pr in regards to server side sending with /session/:sessionID/message and not specifiying agent I agree it should set to the last agent aswell so I will add that to the pr

  18. snaselj commented on Dec 29, 2025

    @snaselj
    snaselj
    on Dec 29, 2025
    More actions

    @ShpetimA Right, I created the session and then sent the API request prompt specifying agent, sorry for confusion. I was unable to fix it in the PR, so I rather closed it.

  19. JosXa commented on Jan 16, 2026

    @JosXa
    JosXa
    on Jan 16, 2026
    ContributorAuthor
    More actions

    Hi! I'd like to take a crack at this. My approach: add an effect in local.tsx that watches for session route changes and restores the model/agent from the last user message. This follows Option A discussed above - no schema changes needed since user messages already store model and agent. Let me know if this sounds good before I open a PR.

    @ShpetimA already had a PR open, check if you can review and improve upon it first please :)

  20. deadcoder0904 commented on Feb 21, 2026

    @deadcoder0904
    deadcoder0904
    on Feb 21, 2026
    More actions

    #12582

    This PR got merged but it still switches agents, at least custom agents in my case.

    I have a custom agent called architect under .opencode/agents/architect.md which is what I set in the cycle through command:

    Image

    And when I click new session it automatically switches. Did the merged PR get released in desktop? Because I don't see it actually fixed.

  21. ShpetimA commented on Feb 22, 2026

    @ShpetimA
    ShpetimA
    on Feb 22, 2026
    Contributor
    More actions

    I'm closing the pr I had for this since it's old now, if there is interest by the team in future I can open it again

  22. AJIredale
    added a commit that references this issue on Feb 22, 2026

    fix(tui): retain model and agent selection when switching sessions

    This issue will close once commit b6cea61 is merged into the 'dev' branch.
    b6cea61
  23. alfredocristofano commented on Apr 26, 2026

    @alfredocristofano
    alfredocristofano
    on Apr 26, 2026
    More actions

    @Jah-yee Your analysis of session/prompt.ts is accurate. The model resolution chain is indeed:

    const model = input.model ?? ag.model ?? (yield* lastModel(input.sessionID))

    where lastModel walks back through the session's user messages to find the last used model.

    However, I want to add some technical context that might help refine the approach before you open a PR.

    Current TUI architecture

    The TUI already maintains global model/agent selection in local.tsx:

    • local.agent.current() — returns the currently selected agent (stored in agentStore.current)
    • local.model.current() — returns the currently selected model (stored per-agent in modelStore.model[a.name])

    When the user sends a message from the TUI, the prompt component explicitly passes local.model.current() to the server (line 672, 776-777 in prompt/index.tsx). So the server always receives the user's explicit choice.

    The actual gap

    The issue isn't that the server ignores the user's selection — it's that when you navigate to a different session, the TUI doesn't restore the model/agent that were used in that session's last message.

    Your "global state" approach (Option A) would work for the TUI, but has a limitation: it wouldn't help for opencode attach or API-created sessions, as @snaselj noted. The server is headless — it has no concept of a "user's current global selection".

    Why Option B (per-session) is more robust

    Looking at the feedback from @jdanbrown and the implementation @ShpetimA attempted, the consensus leans toward making model/agent sticky to the session itself:

    "Making agent/model sticky to the session seems like the least surprising UX"

    This means:

    1. When navigating to a session, the TUI reads lastModel(sessionID) and lastAgent(sessionID) and sets them as the current selection
    2. This works for TUI, attach, and API because it derives from session data, not ephemeral TUI state

    Concrete implementation suggestion

    Instead of adding global state, add an effect in routes/session/index.tsx that reacts to route.sessionID changes:

    // When navigating to a session, restore its last used model/agent
    createEffect(on(() => route.sessionID, (sessionID) => {
      // Derive last model from session messages
      const lastMsg = sync.data.message[sessionID]?.findLast(m => m.info.role === "user" && m.info.model)
      if (lastMsg?.info.model) {
        local.model.set(lastMsg.info.model)
      }
      // Derive last agent from session messages  
      if (lastMsg?.info.agent) {
        local.agent.set(lastMsg.info.agent)
      }
    }))

    This is a minimal TUI-only change that leverages existing data structures. The server side is already correct — lastModel() and user message storage handle the persistence.

    Caveat

    As @ShpetimA discovered, there's edge cases with empty sessions (no user messages yet) and custom agents. You'd need to handle:

    • Session with no messages → keep current global selection (don't override)
    • Model/agent no longer valid (provider removed) → fallback gracefully

    Would love to hear thoughts from @rekram1-node on whether this direction aligns with the team's view.

  24. alfredocristofano commented on Apr 26, 2026

    @alfredocristofano
    alfredocristofano
    on Apr 26, 2026
    More actions

    Opened PR #24508 with a minimal approach: a KV toggle that controls whether model/agent get restored from the session's last message when you switch. Default is on (current behavior), so nothing changes unless you opt out via the command palette. This keeps it backward-compatible while giving users who want sticky selection a way to get it.

  25. thdxr
    assigned
    jlongster
    on May 3, 2026
  26. thdxr
    removed
    good first issueGood for newcomers
    help-wanted
    on May 3, 2026
  27. github-actions commented on Jul 3, 2026

    @github-actions
    github-actionsBot
    on Jul 3, 2026 – with GitHub Actions
    Contributor
    More actions

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  28. github-actions
    closed this as not plannedon Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @jlongster
    jlongster

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.