thedotmack/claude-mem · error · HostObserverUnavailableError

CLAUDE_MEM_HOST_OBSERVER_PORT=

Error message

CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.

What it means

Host observer mode connects to an OpenAI-compatible server you already run, identified by CLAUDE_MEM_HOST_OBSERVER_PORT. resolveHostObserverPort parses that env var as a TCP port; if it is non-empty but not a valid port number (e.g. non-numeric, out of range), it throws HostObserverUnavailableError. The library refuses to guess which port you meant.

Solutions

  1. Set CLAUDE_MEM_HOST_OBSERVER_PORT to a plain integer between 1 and 65535, e.g. export CLAUDE_MEM_HOST_OBSERVER_PORT=4141.
  2. Verify the value with `echo "$CLAUDE_MEM_HOST_OBSERVER_PORT"` and unset it if you don't need an explicit port (auto-discovery will then run).
  3. Check where it is exported (shell rc, .env, launchd/systemd unit) and correct it there.

Example fix

// before
export CLAUDE_MEM_HOST_OBSERVER_PORT=http://localhost:8080
// after
export CLAUDE_MEM_HOST_OBSERVER_PORT=8080
Defensive patterns

Strategy: validation

Validate before calling

const raw = process.env.CLAUDE_MEM_HOST_OBSERVER_PORT;
if (raw && !/^(\d{1,5})$/.test(raw.trim())) throw new Error(`CLAUDE_MEM_HOST_OBSERVER_PORT=${raw} is not a valid port`);
if (raw) { const n = Number(raw); if (!(n >= 1 && n <= 65535)) throw new Error(`port ${raw} out of range`); }

Type guard

const isPort = (v: unknown): v is number => typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535;

Try / catch

try { const port = resolveHostObserverPort(workerPort); } catch (e) { if (e instanceof HostObserverUnavailableError && /not a valid port/.test(e.message)) { delete process.env.CLAUDE_MEM_HOST_OBSERVER_PORT; /* retry with discovery */ } else throw e; }

Prevention

When it happens

Trigger: Running `cmem memory` / install with --provider host while CLAUDE_MEM_HOST_OBSERVER_PORT is set to something parsePort() rejects: e.g. 'abc', 'http://localhost:8080', '99999', or a value with whitespace.

Common situations: Typos in shell profiles; pasting a full URL into a port variable; setting a port above 65535; exporting the variable with a trailing comment or unit suffix.

Understand the failure class

Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.

Related errors


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

Appendix: source

Thrown at src/npx-cli/cmem-memory-credentials.ts:237

    };
  }

  return null;
}

/** Atomically move staged/current credentials into the active provider slot. */

export function resolveHostObserverPort(
  workerPort: string | number | undefined,
  env: NodeJS.ProcessEnv = process.env,
  probe: HostObserverPortProbe = probeHostObserverPortSync,
): string {
  const worker = parsePort(typeof workerPort === 'number' ? workerPort : nonEmptyString(workerPort));
  const configuredRaw = nonEmptyString(env.CLAUDE_MEM_HOST_OBSERVER_PORT);
  if (configuredRaw) {
    const configured = parsePort(configuredRaw);
    if (configured == null) {
      throw new HostObserverUnavailableError(
        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.`,
      );
    }
    if (worker != null && configured === worker) {
      throw new HostObserverUnavailableError(
        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} is the claude-mem worker port. Point it at your OpenAI-compatible observer instead.`,
      );
    }
    const status = probe(configured);
    if (status === 'observer') return String(configured);
    if (status === 'occupied') {
      throw new HostObserverUnavailableError(
        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} is occupied by a process that is not an OpenAI-compatible observer. Stop that process or point CLAUDE_MEM_HOST_OBSERVER_PORT at your observer.`,
      );
    }
    throw new HostObserverUnavailableError(
      `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} has nothing listening. Start your OpenAI-compatible observer on that port, then rerun with --provider host.`,
    );

View on GitHub (pinned to d8bc9755e7)