{"record":{"id":"79c4b89a3ecc1870","repo":"thedotmack/claude-mem","slug":"claude-mem-server-database-url-is-required-for-se","errorCode":null,"errorMessage":"CLAUDE_MEM_SERVER_DATABASE_URL is required for `server ${commandLabel}`. This command talks to the server Postgres backend; export the connection string before running it.","messagePattern":"CLAUDE_MEM_SERVER_DATABASE_URL is required for `server (.+?)`\\. This command talks to the server Postgres backend; export the connection string before running it\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/server/runtime/ServerService.ts","lineNumber":500,"sourceCode":"// or no `CLAUDE_MEM_SERVER_DATABASE_URL` configured — we fail fast with an\n// actionable message instead of crashing later with an opaque pool error.\n//\n// Phase 1d: dual-accept the persisted runtime literal (`'server'` is the new\n// canonical form; `'server-beta'` remains valid for existing installs).\nexport function assertServerRuntimeForCli(\n  commandLabel: string,\n  env: NodeJS.ProcessEnv = process.env,\n): void {\n  const runtime = (env.CLAUDE_MEM_RUNTIME ?? '').trim().toLowerCase();\n  if (runtime && runtime !== 'server' && runtime !== 'server-beta') {\n    throw new Error(\n      `\\`server ${commandLabel}\\` is a server runtime command, but CLAUDE_MEM_RUNTIME=${runtime}. ` +\n        'Set CLAUDE_MEM_RUNTIME=server (and CLAUDE_MEM_SERVER_DATABASE_URL) to run server operations, ' +\n        'or use the worker CLI (`worker-service ...`) for the worker runtime.',\n    );\n  }\n  if (!(env.CLAUDE_MEM_SERVER_DATABASE_URL ?? '').trim()) {\n    throw new Error(\n      `CLAUDE_MEM_SERVER_DATABASE_URL is required for \\`server ${commandLabel}\\`. ` +\n        'This command talks to the server Postgres backend; export the connection string before running it.',\n    );\n  }\n}\n\nexport async function runServerApiKeyCli(argv: string[]): Promise<void> {\n  const sub = argv[0]?.toLowerCase();\n  const options = parseFlagArgs(argv.slice(1));\n\n  try {\n    assertServerRuntimeForCli('api-key');\n  } catch (error) {\n    console.error(error instanceof Error ? error.message : String(error));\n    process.exit(1);\n  }\n\n  // #2560 — `api-key migrate-scopes <id>` brings a key's scope set up to a","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/8bc631a71a487424b866756e43a6efa4574cc66b/src/server/runtime/ServerService.ts#L482-L518","documentation":"Second guard in assertServerRuntimeForCli(): after the runtime literal check passes, it requires a non-empty CLAUDE_MEM_SERVER_DATABASE_URL because every `server <cmd>` subcommand talks directly to the server's Postgres backend. It fails fast with this message instead of letting a pg Pool fail later with an unreadable connection error.","triggerScenarios":"Running `claude-mem server api-key ...` or another server subcommand with CLAUDE_MEM_RUNTIME=server set but no Postgres connection string exported; the variable present but whitespace-only; the connection string living only in the server's deployment environment rather than the operator's shell.","commonSituations":"First-time server setup where the database was provisioned but the env var never exported locally; running admin commands from a laptop while the URL exists only in the container/compose environment; quoting mistakes that leave the variable empty.","solutions":["Export CLAUDE_MEM_SERVER_DATABASE_URL with the server Postgres connection string before running the command.","Copy the exact value the running server container uses (docker inspect / compose env) so the CLI sees the same database.","Put the export in the shell profile or a dedicated env file sourced before server admin sessions."],"exampleFix":"# before\nexport CLAUDE_MEM_RUNTIME=server\nclaude-mem server api-key create\n# -> CLAUDE_MEM_SERVER_DATABASE_URL is required\n\n# after\nexport CLAUDE_MEM_RUNTIME=server\nexport CLAUDE_MEM_SERVER_DATABASE_URL=postgres://user:pass@host:5432/claude_mem\nclaude-mem server api-key create","handlingStrategy":"validation","validationCode":"if (!(process.env.CLAUDE_MEM_SERVER_DATABASE_URL ?? '').trim()) {\n  throw new Error(\n    'CLAUDE_MEM_SERVER_DATABASE_URL is required for server CLI commands; ' +\n    'export the Postgres connection string first',\n  );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Source a dedicated env file (server admin credentials) before running `server` subcommands.","Copy the exact connection string the running server container uses so CLI and server see the same database.","Add a preflight check in ops scripts that verifies the variable is non-empty."],"tags":["cli","configuration","env-var","postgres","database-url","server"],"backgroundTag":"missing-env-var","analyzedSha":"8bc631a71a487424b866756e43a6efa4574cc66b","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}