{"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":1004,"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":986,"sourceCodeEnd":1022,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/8bc631a71a487424b866756e43a6efa4574cc66b/src/npx-cli/commands/install.ts#L986-L1022","documentation":"A log.warn from the installer's server-key bootstrap: bootstrapAndPersistServerApiKey() rejected. This step provisions an API key for hooks against the claude-mem server, which requires CLAUDE_MEM_SERVER_DATABASE_URL (Postgres) to be set — without it the function isn't even attempted. On failure the installer states the degraded mode explicitly: hooks fall back to talking to the local worker until a key is provisioned via `npx claude-mem server keys rotate`.","triggerScenarios":"Installing with CLAUDE_MEM_SERVER_DATABASE_URL set but Postgres unreachable, credentials wrong, the database not migrated, or the bootstrap HTTP call to the server failing/timeout; partially configured server environments.","commonSituations":"Server-mode adopters who set the env var before the Postgres instance or the claude-mem server itself is running; rotated/dropped database credentials; connecting to a server URL that is behind a proxy returning an error page.","solutions":["Finish setup later with the documented command: npx claude-mem server keys rotate","Verify prerequisites first: CLAUDE_MEM_SERVER_DATABASE_URL is set, Postgres accepts connections, migrations ran","Until the key exists, expect hooks to use the local-worker fallback — data still flows, server-mode features do not"],"exampleFix":"# before\n[warn] Failed to bootstrap server API key: fetch failed. Hooks will fall back…\n\n# after\n$ psql \"$CLAUDE_MEM_SERVER_DATABASE_URL\" -c 'select 1'   # confirm DB reachable\n$ npx claude-mem server keys rotate                        # provision the key","handlingStrategy":"retry","validationCode":"function serverBootstrapPreconditions(): string | null {\n  if (!process.env.CLAUDE_MEM_SERVER_DATABASE_URL)\n    return 'CLAUDE_MEM_SERVER_DATABASE_URL not set — bootstrap is skipped by design';\n  return null;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await bootstrapAndPersistServerApiKey();\n} catch (e) {\n  log.warn(`key bootstrap failed (${msg(e)}); run \\`npx claude-mem server keys rotate\\` after Postgres is up`);\n}","preventionTips":["Bring Postgres up and verified (select 1) before running install with server env vars set","Always finish server-mode setup with `npx claude-mem server keys rotate` if bootstrap warned","Remember the documented fallback: without a key, hooks talk to the local worker — nothing is lost locally"],"tags":["installer","api-key","server-bootstrap","postgres","hooks","fallback"],"backgroundTag":"api-key-provisioning-failed","analyzedSha":"8bc631a71a487424b866756e43a6efa4574cc66b","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}