jackwener/OpenCLI · error · ArgumentError
Cannot switch to ${wantModel} model inside an existing conve
Error message
Cannot switch to ${wantModel} model inside an existing conversation. What it means
The `claude ask` command throws this ArgumentError when the user explicitly passes --model while the browser session is inside an existing conversation (URL contains /chat/). The Claude UI only exposes the model selector on the new-chat page, so switching models mid-conversation is impossible via the automation. The error carries a hint to re-run with --new.
Source
Thrown at clis/claude/ask.js:80
}
}
}
// ensureClaudeComposer reads composer presence directly via getPageState,
// so the previous standalone 2 s settle is redundant.
await withRetry(() => ensureClaudeComposer(page, 'Claude ask requires a visible composer on the current page.'));
// Model selector is only available on the new-chat page, not inside
// an existing conversation. Also avoid changing the user's current
// UI selection unless --model was explicitly passed.
const currentUrl = await page.evaluate('window.location.href') || '';
const inConversation = currentUrl.includes('/chat/');
const modelExplicit = kwargs.__opencliOptionSources?.model === 'cli';
const wantModel = kwargs.model || 'sonnet';
if (modelExplicit) {
if (inConversation) {
throw new ArgumentError(
`Cannot switch to ${wantModel} model inside an existing conversation.`,
'Re-run with --new to start a fresh chat before selecting a model.',
);
}
const modelResult = await withRetry(() => selectModel(page, wantModel));
if (!modelResult?.ok) {
if (modelResult?.upgrade) {
throw new ArgumentError(
`${wantModel} model requires a paid Claude plan.`,
'Pick --model sonnet or --model haiku, or upgrade your account.',
);
}
throw new CommandExecutionError(`Could not switch to ${wantModel} model`);
}
// Post-toggle settle dropped — the next CDP eval (setAdaptiveThinking) gives
// React enough time to flush aria-checked updates between rountrips.
}View on GitHub (pinned to 49907e53dc)
Solutions
- Re-run with --new to start a fresh chat before selecting a model.
- Omit --model to keep the conversation's current model selection.
- Navigate to a new chat (claude.ai/new) before invoking ask with --model.
Example fix
// before opencli claude ask "explain" --model opus // after opencli claude ask "explain" --model opus --new
Defensive patterns
Strategy: validation
Validate before calling
// Start a new chat whenever --model is used
const url = await page.evaluate('window.location.href') || '';
if (opts.model && url.includes('/chat/')) opts.new = true; Try / catch
try {
await opencli.claude.ask(prompt, { model: 'opus' });
} catch (e) {
if (/inside an existing conversation/.test(e.message)) {
await opencli.claude.ask(prompt, { model: 'opus', new: true });
} else throw e;
} Prevention
- Always pair --model with --new in scripts.
- Omit --model when continuing existing conversations.
- Track whether your session will resume a prior chat before passing --model.
When it happens
Trigger: Running `opencli claude ask ... --model opus` when the persistent session has resumed an existing conversation (currentUrl includes '/chat/') and --new was not passed, so the model selector cannot be clicked.
Common situations: Reusing a persistent session that automatically resumes the last chat; scripted calls that always pass --model but rely on session resumption; running the command a second time in a row without --new.
Understand the failure class
Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.
Related errors
- ${result.reason}
- Codex model switch to "${selected}" was not verified.
- Unexpected 12306 probe: ${JSON.stringify(probe)}
- Waiting for 12306 tk auth cookie
- amazon.com
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/8fc2dc9e6ca900a2.
Report an issue: GitHub.