From 28651246e54bd5a1375de0df1c75add47ab9ede5 Mon Sep 17 00:00:00 2001 From: Nainish Rai Date: Mon, 16 Mar 2026 17:30:59 +0530 Subject: [PATCH] fix: prioritize CLI --model argument over command markdown model Fixes #17783 The CLI --model argument should have highest priority according to docs, but it was being overridden by model specified in command/agent markdown. For subtasks (commands with subtask: true or using a subagent), the command/agent model takes precedence as these are specialized operations. Changed the priority order in session/prompt.ts to: 1. For subtasks: command.model -> command.agent.model 2. For regular commands: input.model (CLI) -> command.model -> command.agent.model 3. Last used model as fallback --- packages/opencode/src/session/prompt.ts | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index 5bde2608f0b5..c62c0da1dd27 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -1803,17 +1803,29 @@ NOTE: At any point in time through this workflow you should feel free to ask the } template = template.trim() + const agent = await Agent.get(agentName) + const isSubtask = (agent?.mode === "subagent" && command.subtask !== false) || command.subtask === true + const taskModel = await (async () => { - if (command.model) { - return Provider.parseModel(command.model) - } - if (command.agent) { - const cmdAgent = await Agent.get(command.agent) - if (cmdAgent?.model) { - return cmdAgent.model + if (isSubtask) { + if (command.model) return Provider.parseModel(command.model) + if (command.agent) { + const m = command.agent === agentName + ? agent?.model + : (await Agent.get(command.agent))?.model + if (m) return m } + if (input.model) return Provider.parseModel(input.model) + return await lastModel(input.sessionID) } if (input.model) return Provider.parseModel(input.model) + if (command.model) return Provider.parseModel(command.model) + if (command.agent) { + const m = command.agent === agentName + ? agent?.model + : (await Agent.get(command.agent))?.model + if (m) return m + } return await lastModel(input.sessionID) })() @@ -1830,7 +1842,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the } throw e } - const agent = await Agent.get(agentName) if (!agent) { const available = await Agent.list().then((agents) => agents.filter((a) => !a.hidden).map((a) => a.name)) const hint = available.length ? ` Available agents: ${available.join(", ")}` : "" @@ -1843,7 +1854,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the } const templateParts = await resolvePromptParts(template) - const isSubtask = (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true const parts = isSubtask ? [ {