thedotmack/claude-mem · critical

Cannot bootstrap server API key…

Error message

Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set.

What it means

Thrown by buildPoolFromEnv when bootstrap of the server API key requires a Postgres connection but the CLAUDE_MEM_SERVER_DATABASE_URL environment variable is not set. The library refuses to create a connection pool without a database URL because it has nowhere to store or look up the API key. This is a fail-fast configuration guard.

Solutions

  1. Set CLAUDE_MEM_SERVER_DATABASE_URL to a valid Postgres connection string in the environment before bootstrapping.
  2. If using a .env file, confirm it is loaded by the process (dotenv/bun auto-load) and lives in the working directory.
  3. Check deployment config (docker-compose, k8s secret, CI secrets) that the variable is injected under the exact name.
  4. Verify the value is non-empty and parses as a postgres:// or postgresql:// URL.

Example fix

// before
bun run bootstrap
// Error: Cannot bootstrap server API key...

// after
export CLAUDE_MEM_SERVER_DATABASE_URL='postgres://user:pass@localhost:5432/claude_mem'
bun run bootstrap
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.CLAUDE_MEM_SERVER_DATABASE_URL?.trim()) {
  throw new Error('CLAUDE_MEM_SERVER_DATABASE_URL must be set before bootstrapping the server API key');
}

Prevention

When it happens

Trigger: Calling buildPoolFromEnv (directly or via the pool/bootstrap-server-key path) when the process environment has no CLAUDE_MEM_SERVER_DATABASE_URL, or when parsePostgresConfig with requireDatabaseUrl:true returns null because the variable is empty or whitespace.

Common situations: Running the server bootstrap in a fresh environment where .env was not loaded, deploying without the env var in the deployment manifest, or typo-ing the variable name (e.g. DATABASE_URL instead of CLAUDE_MEM_SERVER_DATABASE_URL).

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/57b6c5c9a5a4c501. Report an issue: GitHub.

Appendix: source

Thrown at src/services/hooks/server-bootstrap.ts:225

    `SELECT id FROM projects WHERE team_id = $1 AND name = $2 LIMIT 1`,
    [teamId, LOCAL_HOOK_PROJECT_NAME],
  );
  if (existing.rows[0]) {
    return existing.rows[0].id;
  }
  const repo = new PostgresProjectsRepository(pool);
  const project = await repo.create({
    teamId,
    name: LOCAL_HOOK_PROJECT_NAME,
    metadata: { source: 'local-hook-bootstrap' },
  });
  return project.id;
}

function buildPoolFromEnv(): PostgresPool {
  const config = parsePostgresConfig({ requireDatabaseUrl: true });
  if (!config) {
    throw new Error(
      'Cannot bootstrap server API key: CLAUDE_MEM_SERVER_DATABASE_URL is not set.',
    );
  }
  return createPostgresPool(config);
}

View on GitHub (pinned to d8bc9755e7)