{"record":{"id":"d6d618291ec44350","repo":"thedotmack/claude-mem","slug":"server-commandlabel-is-a-server-runtime-comma","errorCode":null,"errorMessage":"`server ${commandLabel}` is a server runtime command, but CLAUDE_MEM_RUNTIME=${runtime}. Set CLAUDE_MEM_RUNTIME=server (and CLAUDE_MEM_SERVER_DATABASE_URL) to run server operations, or use the worker CLI (`worker-service ...`) for the worker runtime.","messagePattern":"`server (.+?)` is a server runtime command, but CLAUDE_MEM_RUNTIME=(.+?)\\. Set CLAUDE_MEM_RUNTIME=server \\(and CLAUDE_MEM_SERVER_DATABASE_URL\\) to run server operations, or use the worker CLI \\(`worker-service \\.\\.\\.`\\) for the worker runtime\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/server/runtime/ServerService.ts","lineNumber":453,"sourceCode":"// is invisible to the server runtime, which reads keys from Postgres. Use\n// this entrypoint inside Docker / Compose.\n// #2572 — wrong-runtime guard.\n//\n// The server operability commands (`api-key`, `keys`, `jobs`) only make\n// sense in the server runtime, whose canonical store is Postgres. If they\n// are invoked in a worker-only context — `CLAUDE_MEM_RUNTIME` set to `worker`,\n// 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 {","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/server/runtime/ServerService.ts#L435-L471","documentation":"Thrown by assertServerRuntimeForCli() when a `server <command>` CLI operation is invoked but CLAUDE_MEM_RUNTIME is set to something other than 'server' or the legacy 'server-beta' (case-insensitive). It is a fast-fail guard so server-runtime commands don't run in a worker-only context and crash later with an opaque pool error. The message tells the operator to either switch the runtime or use the worker CLI.","triggerScenarios":"CLAUDE_MEM_RUNTIME=worker (or any non-server value) is set in the environment and the user runs `claude-mem server <command>` (e.g. server api-key ...). The message captures the offending runtime value.","commonSituations":"A worker-only container/terminal also has the server CLI on PATH. An operator copied env from a worker setup. The runtime variable was set to a deprecated literal.","solutions":["Set CLAUDE_MEM_RUNTIME=server (and CLAUDE_MEM_SERVER_DATABASE_URL) in the environment before running server commands.","If you actually intended worker operations, use the worker CLI (`worker-service ...`) instead of `server ...`.","Unset CLAUDE_MEM_RUNTIME if this shell should be able to run server commands (the guard only fires when it is non-empty and wrong)."],"exampleFix":"// before: CLAUDE_MEM_RUNTIME=worker; running server api-key create\n// after: export CLAUDE_MEM_RUNTIME=server\n//        export CLAUDE_MEM_SERVER_DATABASE_URL=postgres://...\n//        claude-mem server api-key create","handlingStrategy":"validation","validationCode":"function assertServerRuntime(commandLabel: string, env: NodeJS.ProcessEnv = process.env): void {\n  const runtime = (env.CLAUDE_MEM_RUNTIME ?? '').trim().toLowerCase();\n  if (runtime && runtime !== 'server' && runtime !== 'server-beta') {\n    throw new Error(`Set CLAUDE_MEM_RUNTIME=server to run \\`server ${commandLabel}\\`, or unset it.`);\n  }\n}","typeGuard":"function isServerRuntime(env: NodeJS.ProcessEnv): boolean {\n  const r = (env.CLAUDE_MEM_RUNTIME ?? '').trim().toLowerCase();\n  return r === '' || r === 'server' || r === 'server-beta';\n}","tryCatchPattern":"try {\n  assertServerRuntimeForCli('api-key');\n} catch (error) {\n  console.error((error as Error).message);\n  // guide the operator: export CLAUDE_MEM_RUNTIME=server, or use worker-service\n  process.exit(1);\n}","preventionTips":["Keep server-runtime shells and worker-runtime shells in separate env profiles.","Use CLAUDE_MEM_RUNTIME=server consistently for any shell that runs `server ...` commands.","For worker operations, prefer the worker-service CLI explicitly."],"tags":["config","runtime","env","cli"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}