{"record":{"id":"3e55a4cd0af1ef8e","repo":"thedotmack/claude-mem","slug":"failed-to-bootstrap-server-api-key-error-instan","errorCode":null,"errorMessage":"Failed to bootstrap server API key: ${error instanceof Error ? error.message : String(error)}. Hooks will fall back to the worker until you run `npx claude-mem server keys rotate`.","messagePattern":"Failed to bootstrap server API key: (.+?)\\. Hooks will fall back to the worker until you run `npx claude-mem server keys rotate`\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/npx-cli/commands/install.ts","lineNumber":1027,"sourceCode":"  await maybeBootstrapServerApiKey();\n}\n\nasync function maybeBootstrapServerApiKey(): Promise<void> {\n  // Only attempt if Postgres is configured. Without DATABASE_URL we cannot\n  // reach the api_keys table — the operator must configure the server first\n  // and rerun `claude-mem server keys rotate`.\n  if (!process.env.CLAUDE_MEM_SERVER_DATABASE_URL) {\n    log.warn(\n      'Skipping local hook API key bootstrap: CLAUDE_MEM_SERVER_DATABASE_URL is not set. '\n        + 'Run `npx claude-mem server keys rotate` after configuring Postgres to provision a key.',\n    );\n    return;\n  }\n  try {\n    await bootstrapAndPersistServerApiKey();\n  } catch (error: unknown) {\n    // [ANTI-PATTERN IGNORED]: the failure is already surfaced to the user via the interactive-aware log.warn wrapper below (p.log.warn in a TTY, console.warn otherwise), including the manual remediation command.\n    log.warn(\n      `Failed to bootstrap server API key: ${error instanceof Error ? error.message : String(error)}. `\n        + 'Hooks will fall back to the worker until you run `npx claude-mem server keys rotate`.',\n    );\n  }\n}\n\nasync function bootstrapAndPersistServerApiKey(): Promise<void> {\n  const { bootstrapServerApiKey, persistServerSettings } = await import(\n    '../../services/hooks/server-bootstrap.js'\n  );\n  const result = await bootstrapServerApiKey();\n  persistServerSettings(USER_SETTINGS_PATH, {\n    apiKey: result.rawKey,\n    projectId: result.projectId,\n  });\n  log.info(\n    `Provisioned local hook API key (project=${result.projectId.slice(0, 8)}…). `\n      + 'Settings saved with mode 0600.',","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/npx-cli/commands/install.ts#L1009-L1045","documentation":"During `claude-mem install`, the CLI tries to bootstrap and persist a server API key (bootstrapAndPersistServerApiKey). If that fails, it logs a warning instead of aborting, telling the user hooks will fall back to the legacy worker path until they rotate keys manually. The library throws/logs this because it prefers a degraded-but-working install over a hard failure.","triggerScenarios":"Running `npx claude-mem install` when bootstrapAndPersistServerApiKey() throws — e.g. the server API is unreachable, key rotation endpoint rejects the request, or persisting the key to settings fails.","commonSituations":"Server not started or unreachable during install; stale/corrupted settings file blocking key persistence; version mismatch between CLI and server API; restricted environment where the server data directory is not writable.","solutions":["Run `npx claude-mem server keys rotate` as the message instructs, then re-run install.","Verify the claude-mem server is running and reachable (`npx claude-mem server status` / start it).","Check settings file (~/.claude/settings.json or claude-mem config) for corruption or permission issues and fix, then retry install.","Re-run `npx claude-mem install` after fixing; the warning is non-fatal so hooks keep working via worker fallback meanwhile."],"exampleFix":"// before: install proceeds without a server key, hooks fall back to worker\nlog.warn(`Failed to bootstrap server API key: ...`);\n// after: ensure server is up first, then rotate keys\nnpx claude-mem server start\nnpx claude-mem server keys rotate\nnpx claude-mem install","handlingStrategy":"try-catch","validationCode":"// Check server reachability and settings writability before install\nimport { existsSync, accessSync, W_OK } from 'node:fs';\naccessSync(settingsPath, W_OK); // throws if settings not writable\n// optionally probe the server health endpoint first","typeGuard":"function isServerError(e: unknown): e is Error { return e instanceof Error && 'code' in e; }","tryCatchPattern":"try {\n  await bootstrapAndPersistServerApiKey();\n} catch (error) {\n  log.warn(`Failed to bootstrap server API key: ${error instanceof Error ? error.message : String(error)}. Run \\`npx claude-mem server keys rotate\\`.`);\n}","preventionTips":["Start the server before running install","Keep settings.json valid and writable by the current user","Rotate keys proactively with `npx claude-mem server keys rotate`","Keep CLI and server versions in sync"],"tags":["install","api-key","server","fallback"],"backgroundTag":"missing-api-key","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}