{"record":{"id":"8fc2dc9e6ca900a2","repo":"jackwener/OpenCLI","slug":"cannot-switch-to-wantmodel-model-inside-an-exis","errorCode":null,"errorMessage":"Cannot switch to ${wantModel} model inside an existing conversation.","messagePattern":"Cannot switch to (.+?) model inside an existing conversation\\.","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/claude/ask.js","lineNumber":80,"sourceCode":"                }\n            }\n        }\n\n        // ensureClaudeComposer reads composer presence directly via getPageState,\n        // so the previous standalone 2 s settle is redundant.\n        await withRetry(() => ensureClaudeComposer(page, 'Claude ask requires a visible composer on the current page.'));\n\n        // Model selector is only available on the new-chat page, not inside\n        // an existing conversation. Also avoid changing the user's current\n        // UI selection unless --model was explicitly passed.\n        const currentUrl = await page.evaluate('window.location.href') || '';\n        const inConversation = currentUrl.includes('/chat/');\n        const modelExplicit = kwargs.__opencliOptionSources?.model === 'cli';\n\n        const wantModel = kwargs.model || 'sonnet';\n        if (modelExplicit) {\n            if (inConversation) {\n                throw new ArgumentError(\n                    `Cannot switch to ${wantModel} model inside an existing conversation.`,\n                    'Re-run with --new to start a fresh chat before selecting a model.',\n                );\n            }\n\n            const modelResult = await withRetry(() => selectModel(page, wantModel));\n            if (!modelResult?.ok) {\n                if (modelResult?.upgrade) {\n                    throw new ArgumentError(\n                        `${wantModel} model requires a paid Claude plan.`,\n                        'Pick --model sonnet or --model haiku, or upgrade your account.',\n                    );\n                }\n                throw new CommandExecutionError(`Could not switch to ${wantModel} model`);\n            }\n            // Post-toggle settle dropped — the next CDP eval (setAdaptiveThinking) gives\n            // React enough time to flush aria-checked updates between rountrips.\n        }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/claude/ask.js#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nopencli claude ask \"explain\" --model opus\n// after\nopencli claude ask \"explain\" --model opus --new","handlingStrategy":"validation","validationCode":"// Start a new chat whenever --model is used\nconst url = await page.evaluate('window.location.href') || '';\nif (opts.model && url.includes('/chat/')) opts.new = true;","typeGuard":null,"tryCatchPattern":"try {\n  await opencli.claude.ask(prompt, { model: 'opus' });\n} catch (e) {\n  if (/inside an existing conversation/.test(e.message)) {\n    await opencli.claude.ask(prompt, { model: 'opus', new: true });\n  } else throw e;\n}","preventionTips":["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."],"tags":["argument","model-selection","browser-automation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}