thedotmack/claude-mem · warning

Failed to bootstrap server API key

Error message

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`.

What it means

During `claude-mem install`, the CLI tries to bootstrap and persist a server API key (bootstrapAndPersistServerApiKey). If that fails, it logs a warning instead of aborting, telling the user hooks will fall back to the legacy worker path until they rotate keys manually. The library throws/logs this because it prefers a degraded-but-working install over a hard failure.

Solutions

  1. Run `npx claude-mem server keys rotate` as the message instructs, then re-run install.
  2. Verify the claude-mem server is running and reachable (`npx claude-mem server status` / start it).
  3. Check settings file (~/.claude/settings.json or claude-mem config) for corruption or permission issues and fix, then retry install.
  4. Re-run `npx claude-mem install` after fixing; the warning is non-fatal so hooks keep working via worker fallback meanwhile.

Example fix

// before: install proceeds without a server key, hooks fall back to worker
log.warn(`Failed to bootstrap server API key: ...`);
// after: ensure server is up first, then rotate keys
npx claude-mem server start
npx claude-mem server keys rotate
npx claude-mem install
Defensive patterns

Strategy: try-catch

Validate before calling

// Check server reachability and settings writability before install
import { existsSync, accessSync, W_OK } from 'node:fs';
accessSync(settingsPath, W_OK); // throws if settings not writable
// optionally probe the server health endpoint first

Type guard

function isServerError(e: unknown): e is Error { return e instanceof Error && 'code' in e; }

Try / catch

try {
  await bootstrapAndPersistServerApiKey();
} catch (error) {
  log.warn(`Failed to bootstrap server API key: ${error instanceof Error ? error.message : String(error)}. Run \`npx claude-mem server keys rotate\`.`);
}

Prevention

When it happens

Trigger: Running `npx claude-mem install` when bootstrapAndPersistServerApiKey() throws — e.g. the server API is unreachable, key rotation endpoint rejects the request, or persisting the key to settings fails.

Common situations: Server not started or unreachable during install; stale/corrupted settings file blocking key persistence; version mismatch between CLI and server API; restricted environment where the server data directory is not writable.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: source

Thrown at src/npx-cli/commands/install.ts:1027

  await maybeBootstrapServerApiKey();
}

async function maybeBootstrapServerApiKey(): Promise<void> {
  // Only attempt if Postgres is configured. Without DATABASE_URL we cannot
  // reach the api_keys table — the operator must configure the server first
  // and rerun `claude-mem server keys rotate`.
  if (!process.env.CLAUDE_MEM_SERVER_DATABASE_URL) {
    log.warn(
      'Skipping local hook API key bootstrap: CLAUDE_MEM_SERVER_DATABASE_URL is not set. '
        + 'Run `npx claude-mem server keys rotate` after configuring Postgres to provision a key.',
    );
    return;
  }
  try {
    await bootstrapAndPersistServerApiKey();
  } catch (error: unknown) {
    // [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.
    log.warn(
      `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`.',
    );
  }
}

async function bootstrapAndPersistServerApiKey(): Promise<void> {
  const { bootstrapServerApiKey, persistServerSettings } = await import(
    '../../services/hooks/server-bootstrap.js'
  );
  const result = await bootstrapServerApiKey();
  persistServerSettings(USER_SETTINGS_PATH, {
    apiKey: result.rawKey,
    projectId: result.projectId,
  });
  log.info(
    `Provisioned local hook API key (project=${result.projectId.slice(0, 8)}…). `
      + 'Settings saved with mode 0600.',

View on GitHub (pinned to d8bc9755e7)