{"record":{"id":"695e246792e32c6e","repo":"thedotmack/claude-mem","slug":"api-key-prompt-cancelled-falling-back-to-claude","errorCode":null,"errorMessage":"API key prompt cancelled — falling back to Claude provider.","messagePattern":"API key prompt cancelled — falling back to Claude provider\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/npx-cli/commands/install.ts","lineNumber":1268,"sourceCode":"  const keyEnvName = selectedProvider === 'gemini'\n    ? 'CLAUDE_MEM_GEMINI_API_KEY'\n    : 'CLAUDE_MEM_OPENROUTER_API_KEY';\n\n  const existingKey = getSetting(keyEnvName as keyof SettingsDefaults) as string | undefined;\n  if (existingKey && existingKey.trim().length > 0) {\n    const wrote = mergeSettings({ CLAUDE_MEM_PROVIDER: selectedProvider });\n    if (wrote) log.info(`Saved provider=${selectedProvider} to ~/.claude-mem/settings.json`);\n    return selectedProvider;\n  }\n\n  const apiKeyResult = await p.password({\n    message: `Paste your ${providerLabel} API key:`,\n    mask: '*',\n    validate: (v?: string) => (!v || v.trim().length === 0) ? 'API key required' : undefined,\n  });\n\n  if (p.isCancel(apiKeyResult)) {\n    log.warn(`API key prompt cancelled — falling back to Claude provider.`);\n    persistClaudeProvider();\n    return 'claude';\n  }\n\n  const apiKey = String(apiKeyResult).trim();\n  const wrote = mergeSettings({\n    CLAUDE_MEM_PROVIDER: selectedProvider,\n    [keyEnvName]: apiKey,\n  });\n  if (wrote) {\n    log.info(`Saved provider=${selectedProvider} to ~/.claude-mem/settings.json`);\n  }\n  return selectedProvider;\n}\n\nasync function promptClaudeModel(options: InstallOptions): Promise<void> {\n  const allowed = new Set([\n    'claude-haiku-4-5-20251001',","sourceCodeStart":1250,"sourceCodeEnd":1286,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/npx-cli/commands/install.ts#L1250-L1286","documentation":"In the interactive provider flow for a non-Claude provider, cancelling the masked 'Paste your <provider> API key' prompt (Esc/Ctrl-C) hits this branch: the installer warns, persists the Claude provider instead, and returns 'claude'. Note CLAUDE_MEM_PROVIDER was already written as the selected provider just before the prompt, so this branch rewrites it back to claude — deliberate fallback, not data loss.","triggerScenarios":"User cancels the p.password prompt for a third-party provider key after selecting that provider. persistClaudeProvider() then restores claude as the active provider so memory generation still has credentials.","commonSituations":"User has no third-party key yet; key lives in a vault not accessible; user changes mind mid-flow and wants the default Claude path.","solutions":["Nothing to fix if Claude fallback was intended — generation uses the Claude provider.","To retry the third-party provider, rerun `npx claude-mem install` and paste the key when prompted.","To set it non-interactively: merge CLAUDE_MEM_<PROVIDER>_API_KEY + CLAUDE_MEM_PROVIDER into settings.json or env."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Pre-set the third-party key so the prompt (and its cancel path) never happens:\n// settings.json: { \"env\": { \"CLAUDE_MEM_PROVIDER\": \"openrouter\", \"CLAUDE_MEM_OPENROUTER_API_KEY\": \"sk-or-...\" } }","typeGuard":"const isCancelled = (r: unknown): r is symbol => p.isCancel(r);\n// cancel => provider falls back to 'claude'; verify which provider actually won:","tryCatchPattern":null,"preventionTips":["After any cancelled key prompt, verify CLAUDE_MEM_PROVIDER in settings.json reflects the fallback you expect.","Provide keys upfront in automation to avoid the fallback path entirely.","The fallback is intentional: Claude credentials keep generation working while you obtain the other key."],"tags":["install","prompt-cancelled","provider","fallback"],"backgroundTag":"cli-prompt-cancelled","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-21T08:17:14.275Z"}