Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,26 +241,32 @@ export function Prompt(props: PromptProps) {
),
)

// Initialize agent/model/variant from last user message when session changes
// Initialize agent/model/variant from the session's last user message on the
// first session that loads. On subsequent session switches, preserve the
// user's current agent/model selection rather than reverting to the session's
// historical configuration.
let syncedSessionID: string | undefined
let initialized = false
createEffect(() => {
const sessionID = props.sessionID
const msg = lastUserMessage()

if (sessionID !== syncedSessionID) {
if (!sessionID || !msg) return
if (sessionID === syncedSessionID) return
if (!sessionID || !msg) return

syncedSessionID = sessionID
syncedSessionID = sessionID

// Only set agent if it's a primary agent (not a subagent)
const isPrimaryAgent = local.agent.list().some((x) => x.name === msg.agent)
if (msg.agent && isPrimaryAgent) {
// Keep command line --agent if specified.
if (!args.agent) local.agent.set(msg.agent)
if (msg.model) {
local.model.set(msg.model)
local.model.variant.set(msg.model.variant)
}
if (initialized) return
initialized = true

// Only set agent if it's a primary agent (not a subagent)
const isPrimaryAgent = local.agent.list().some((x) => x.name === msg.agent)
if (msg.agent && isPrimaryAgent) {
// Keep command line --agent if specified.
if (!args.agent) local.agent.set(msg.agent)
if (msg.model) {
local.model.set(msg.model)
local.model.variant.set(msg.model.variant)
}
}
})
Expand Down
Loading