jackwener/OpenCLI · error · CommandExecutionError

Could not switch to ${wantModel} model

Error message

Could not switch to ${wantModel} model

What it means

selectModel() failed for a non-upgrade reason: the model menu could not be opened or the target option was not clickable within retry limits. The library throws CommandExecutionError naming the model it tried to switch to.

Source

Thrown at clis/claude/ask.js:94

        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.
        }

        const thinkResult = await withRetry(() => setAdaptiveThinking(page, wantThink));
        if (!thinkResult?.ok && wantThink) {
            throw new CommandExecutionError('Could not enable Adaptive thinking');
        }
        // Post-toggle settle dropped — the next CDP eval (sendMessage / sendWithFile)
        // gives React enough time to flush aria-checked updates.

        if (kwargs.file) {
            const baseline = await withRetry(() => getBubbleCount(page));
            try {
                const fileResult = await sendWithFile(page, kwargs.file, prompt);
                if (fileResult && !fileResult.ok) {
                    throw new CommandExecutionError(fileResult.reason || 'Failed to attach file');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command; withRetry may succeed once the page fully loads.
  2. Reload claude.ai/new and dismiss any overlay dialogs before retrying.
  3. Update opencli if the Claude UI changed and selectors are stale.
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check the model picker is reachable before invoking ask
await page.goto('https://claude.ai/new');
await page.wait({ selector: '[data-testid="model-selector"]', timeout: 10 });

Try / catch

try {
  return await opencli.claude.ask(prompt, { model: 'opus', new: true });
} catch (e) {
  if (/Could not switch to .* model/.test(e.message)) {
    await sleep(3000); // let the page fully render, then retry
    return await opencli.claude.ask(prompt, { model: 'opus', new: true });
  }
  throw e;
}

Prevention

When it happens

Trigger: withRetry(selectModel) returns {ok:false} without upgrade flag — e.g. the model picker DOM changed, the selector didn't load in time, or a modal/banner covers the menu.

Common situations: Claude UI redesign changing menu markup; slow page load so the picker isn't rendered when clicked; overlay dialogs (cookie banners, release notes) intercepting clicks.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/66b7d8317a1e03ae. Report an issue: GitHub.