{"record":{"id":"57b6c5c9a5a4c501","repo":"thedotmack/claude-mem","slug":"cannot-bootstrap-server-api-key-claude-mem-server","errorCode":null,"errorMessage":"Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set.","messagePattern":"Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/services/hooks/server-bootstrap.ts","lineNumber":225,"sourceCode":"    `SELECT id FROM projects WHERE team_id = $1 AND name = $2 LIMIT 1`,\n    [teamId, LOCAL_HOOK_PROJECT_NAME],\n  );\n  if (existing.rows[0]) {\n    return existing.rows[0].id;\n  }\n  const repo = new PostgresProjectsRepository(pool);\n  const project = await repo.create({\n    teamId,\n    name: LOCAL_HOOK_PROJECT_NAME,\n    metadata: { source: 'local-hook-bootstrap' },\n  });\n  return project.id;\n}\n\nfunction buildPoolFromEnv(): PostgresPool {\n  const config = parsePostgresConfig({ requireDatabaseUrl: true });\n  if (!config) {\n    throw new Error(\n      'Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set.',\n    );\n  }\n  return createPostgresPool(config);\n}\n","sourceCodeStart":207,"sourceCodeEnd":231,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/hooks/server-bootstrap.ts#L207-L231","documentation":"Thrown by buildPoolFromEnv() in server-bootstrap.ts when parsePostgresConfig({ requireDatabaseUrl: true }) returns null, i.e. CLAUDE_MEM_SERVER_DATABASE_URL (or the equivalent PG env) is not set. The bootstrap cannot create a Postgres pool without a connection string, so it cannot provision the local team/project/API key.","triggerScenarios":"Running the server API-key bootstrap flow (which creates the local hook team/project and writes credentials) without CLAUDE_MEM_SERVER_DATABASE_URL in env. parsePostgresConfig yields null and the guard throws.","commonSituations":"First-time server-mode setup where the DATABASE_URL was never exported; .env file not loaded by the bootstrap process; URL was set in a different shell; migrating hosts and forgetting to copy the DB env.","solutions":["Set CLAUDE_MEM_SERVER_DATABASE_URL to a valid Postgres connection string and re-run the bootstrap.","If using a .env file, ensure the bootstrap process actually loads it (or export the var in the same shell).","Confirm the Postgres instance is reachable from the bootstrap process before re-running.","If you did not intend server-mode persistence, switch back to worker runtime instead of bootstrapping."],"exampleFix":"# before — bootstrap run with no DB url\n$ claude-mem bootstrap\n// throws 'Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set.'\n\n# after\nexport CLAUDE_MEM_SERVER_DATABASE_URL='postgres://user:pass@localhost:5432/claude_mem'\nclaude-mem bootstrap","handlingStrategy":"validation","validationCode":"if (!process.env.CLAUDE_MEM_SERVER_DATABASE_URL) {\n  throw new Error('CLAUDE_MEM_SERVER_DATABASE_URL must be set before running server bootstrap');\n}","typeGuard":"function hasDatabaseUrl(): boolean {\n  return typeof process.env.CLAUDE_MEM_SERVER_DATABASE_URL === 'string'\n      && process.env.CLAUDE_MEM_SERVER_DATABASE_URL.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Set CLAUDE_MEM_SERVER_DATABASE_URL in the bootstrap process env (or a loaded .env) before running.","Confirm Postgres reachability before bootstrap to avoid a later pool-creation failure.","If you do not need server-mode persistence, stay on worker runtime instead of bootstrapping."],"tags":["server-mode","config","database","bootstrap"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}