Skip to content

Commit 2865124

Browse files
committed
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
1 parent 51fcd04 commit 2865124

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

packages/opencode/src/session/prompt.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,17 +1803,29 @@ NOTE: At any point in time through this workflow you should feel free to ask the
18031803
}
18041804
template = template.trim()
18051805

1806+
const agent = await Agent.get(agentName)
1807+
const isSubtask = (agent?.mode === "subagent" && command.subtask !== false) || command.subtask === true
1808+
18061809
const taskModel = await (async () => {
1807-
if (command.model) {
1808-
return Provider.parseModel(command.model)
1809-
}
1810-
if (command.agent) {
1811-
const cmdAgent = await Agent.get(command.agent)
1812-
if (cmdAgent?.model) {
1813-
return cmdAgent.model
1810+
if (isSubtask) {
1811+
if (command.model) return Provider.parseModel(command.model)
1812+
if (command.agent) {
1813+
const m = command.agent === agentName
1814+
? agent?.model
1815+
: (await Agent.get(command.agent))?.model
1816+
if (m) return m
18141817
}
1818+
if (input.model) return Provider.parseModel(input.model)
1819+
return await lastModel(input.sessionID)
18151820
}
18161821
if (input.model) return Provider.parseModel(input.model)
1822+
if (command.model) return Provider.parseModel(command.model)
1823+
if (command.agent) {
1824+
const m = command.agent === agentName
1825+
? agent?.model
1826+
: (await Agent.get(command.agent))?.model
1827+
if (m) return m
1828+
}
18171829
return await lastModel(input.sessionID)
18181830
})()
18191831

@@ -1830,7 +1842,6 @@ NOTE: At any point in time through this workflow you should feel free to ask the
18301842
}
18311843
throw e
18321844
}
1833-
const agent = await Agent.get(agentName)
18341845
if (!agent) {
18351846
const available = await Agent.list().then((agents) => agents.filter((a) => !a.hidden).map((a) => a.name))
18361847
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
18431854
}
18441855

18451856
const templateParts = await resolvePromptParts(template)
1846-
const isSubtask = (agent.mode === "subagent" && command.subtask !== false) || command.subtask === true
18471857
const parts = isSubtask
18481858
? [
18491859
{

0 commit comments

Comments
 (0)