{"record":{"id":"fc1fc044e2307ce3","repo":"thedotmack/claude-mem","slug":"api-key-prompt-cancelled-leaving-existing-config","errorCode":null,"errorMessage":"API key prompt cancelled — leaving existing configuration untouched.","messagePattern":"API key prompt cancelled — leaving existing configuration untouched\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src/npx-cli/commands/install.ts","lineNumber":1039,"sourceCode":"      ANTHROPIC_BASE_URL: '',\n      ANTHROPIC_AUTH_TOKEN: '',\n    });\n    log.info('Configured claude-mem to use your logged-in Claude SDK account.');\n  };\n\n  const configureDirectApiKey = async (): Promise<void> => {\n    const existing = loadClaudeMemEnv().ANTHROPIC_API_KEY || '';\n    if (existing.trim().length > 0) {\n      const choice = await p.select<'keep' | 'replace'>({\n        message: 'An Anthropic API key is already configured. Keep it or enter a new one?',\n        options: [\n          { value: 'keep', label: 'Keep existing key' },\n          { value: 'replace', label: 'Enter a new key (rotate)' },\n        ],\n        initialValue: 'keep',\n      });\n      if (p.isCancel(choice)) {\n        log.warn('API key prompt cancelled — leaving existing configuration untouched.');\n        return;\n      }\n      if (choice === 'keep') {\n        saveClaudeMemEnv({\n          ANTHROPIC_API_KEY: existing.trim(),\n          ANTHROPIC_BASE_URL: '',\n          ANTHROPIC_AUTH_TOKEN: '',\n        });\n        persistClaudeProvider('api-key');\n        return;\n      }\n    }\n\n    const apiKeyResult = await p.password({\n      message: 'Paste your Anthropic API key:',\n      mask: '*',\n      validate: (v?: string) => (!v || v.trim().length === 0) ? 'API key required' : undefined,\n    });","sourceCodeStart":1021,"sourceCodeEnd":1057,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/npx-cli/commands/install.ts#L1021-L1057","documentation":"In the interactive Claude-access flow, when an Anthropic API key is already configured the installer asks keep-or-rotate. Pressing Esc or Ctrl-C at that select prompt (p.isCancel) triggers this warning and the function returns with the existing configuration completely untouched — nothing is read, overwritten, or cleared.","triggerScenarios":"User presses the cancel key (Esc / Ctrl-C in the clack prompt) on the 'Keep existing key / Enter a new key (rotate)' select. This is the designed graceful-exit branch, not an exception.","commonSituations":"Users who entered the provider flow by accident and want out; muscle-memory Esc while tabbing through prompts; CI harnesses that send Ctrl-C bytes to stdin.","solutions":["Nothing is broken — rerun `npx claude-mem install` and make a selection to change the key.","To rotate without prompts, edit ~/.claude-mem/.env directly (ANTHROPIC_API_KEY) or rerun and choose 'replace'.","To keep the current key permanently, no action is needed: cancellation already preserved it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Scripting the installer? Treat cancel as a first-class outcome:\n// (user-facing flows: check p.isCancel on EVERY prompt result before use)","typeGuard":"// clack's own guard — always narrow before using the value:\nimport * as p from '@clack/prompts';\nconst isCancelled = (r: unknown): r is symbol => p.isCancel(r);","tryCatchPattern":null,"preventionTips":["Check p.isCancel immediately after every prompt and return early — never let a cancel symbol flow into string handling.","In automation, pre-set values (env/settings) instead of driving interactive prompts.","Remember cancellation here is safe by design: existing config is never modified."],"tags":["install","prompt-cancelled","cli","api-key"],"backgroundTag":"cli-prompt-cancelled","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-21T08:17:14.275Z"}