thedotmack/claude-mem · error · HostObserverUnavailableError

CLAUDE_MEM_HOST_OBSERVER_PORT=

Error message

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.

What it means

When CLAUDE_MEM_HOST_OBSERVER_PORT is set, resolveHostObserverPort probes that TCP port and classifies the listener. If something is listening but it does not respond like an OpenAI-compatible observer, the library throws rather than sending memory requests to the wrong service. This protects against silently posting embeddings/chat requests to an unrelated process.

Solutions

  1. Stop the non-observer process listening on the configured port (find it with `lsof -i :<port>` or `ss -ltnp`).
  2. Set CLAUDE_MEM_HOST_OBSERVER_PORT to the port your actual OpenAI-compatible observer listens on.
  3. Restart your observer on the configured port and rerun with --provider host.

Example fix

# before
CLAUDE_MEM_HOST_OBSERVER_PORT=3000   # Next.js dev server bound here
# after
CLAUDE_MEM_HOST_OBSERVER_PORT=4141   # observer's real port
lsof -i :3000  # identify and stop the squatter if the port must stay
Defensive patterns

Strategy: validation

Validate before calling

import { createConnection } from 'node:net';
function portInUse(port: number): Promise<boolean> { return new Promise(res => { const s = createConnection(port, '127.0.0.1'); s.once('connect', () => { s.destroy(); res(true); }); s.once('error', () => res(false)); }); }
const p = Number(process.env.CLAUDE_MEM_HOST_OBSERVER_PORT);
if (p && await portInUse(p)) console.warn(`port ${p} occupied — ensure it is your observer`);

Try / catch

try { resolveHostObserverPort(workerPort); } catch (e) { if (e instanceof HostObserverUnavailableError && /occupied/.test(e.message)) { execSync(`lsof -ti :${port}`); /* stop or reconfigure */ } else throw e; }

Prevention

When it happens

Trigger: CLAUDE_MEM_HOST_OBSERVER_PORT is set to a port where another application (dev server, database, UI) is bound, and the probe returns 'occupied' instead of 'observer'.

Common situations: Port reuse: the observer was stopped and another tool grabbed the port; the port belongs to a non-OpenAI HTTP service; a stale observer instance was replaced by something else.

Related errors


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

Appendix: source

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

): 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.`,
    );
  }

  const candidates = hostObserverCandidatePorts(workerPort, env);
  for (const port of candidates) {
    const status = probe(port);
    if (status === 'observer') return String(port);
  }

  throw new HostObserverUnavailableError(
    `No OpenAI-compatible host observer is listening on 127.0.0.1:${candidates.join(' or ') || HOST_OBSERVER_DEFAULT_PORT}. Host mode uses an observer you already run; claude-mem does not start one. Start your observer, then rerun with --provider host. If it uses another port, set CLAUDE_MEM_HOST_OBSERVER_PORT.`,
  );
}

View on GitHub (pinned to d8bc9755e7)