Feature Request: Retain current model and agent selection when switching sessions
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.
This issue might be a duplicate of existing issues. Please check:
- #4344: Selected model for agent in TUI doesn't stick between Agent Alternation (related model persistence issue)
- #4742: In Home screen, models stick across agents switching (related inconsistency with model selection persistence)
- #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.
Yeah that makes sense
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!
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?
@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?
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
@JosXa can you clarify the wanted behavior?
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?
The more i think about it I actually do think i like it? initially i didnt but lemme ask
@JosXa check out this PR and lmk what you think it should be solved lmk if any errors pop up or any additional requests: https://github.com/sst/opencode/pull/5264
+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.
Another motivating example: I was just exploring the same question against two differernt models in parallel, but then something went wonky with my vscode so I had to restart it, and then when I went to resume my two sessions with opencode -s I couldn't remember which model I used for which session. 🙃
I'm in agreement here. I'd like for sessions to continue running in background when I create new ones.