{"record":{"id":"8355edf293275e05","repo":"thedotmack/claude-mem","slug":"claude-mem-host-observer-port-configuredraw-is","errorCode":null,"errorMessage":"CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.","messagePattern":"CLAUDE_MEM_HOST_OBSERVER_PORT=(.+?) is not a valid port\\. Set it to the port your OpenAI-compatible observer already listens on\\.","errorType":"exception","errorClass":"HostObserverUnavailableError","httpStatus":null,"severity":"error","filePath":"src/npx-cli/cmem-memory-credentials.ts","lineNumber":237,"sourceCode":"    };\n  }\n\n  return null;\n}\n\n/** Atomically move staged/current credentials into the active provider slot. */\n\nexport function resolveHostObserverPort(\n  workerPort: string | number | undefined,\n  env: NodeJS.ProcessEnv = process.env,\n  probe: HostObserverPortProbe = probeHostObserverPortSync,\n): string {\n  const worker = parsePort(typeof workerPort === 'number' ? workerPort : nonEmptyString(workerPort));\n  const configuredRaw = nonEmptyString(env.CLAUDE_MEM_HOST_OBSERVER_PORT);\n  if (configuredRaw) {\n    const configured = parsePort(configuredRaw);\n    if (configured == null) {\n      throw new HostObserverUnavailableError(\n        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configuredRaw} is not a valid port. Set it to the port your OpenAI-compatible observer already listens on.`,\n      );\n    }\n    if (worker != null && configured === worker) {\n      throw new HostObserverUnavailableError(\n        `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} is the claude-mem worker port. Point it at your OpenAI-compatible observer instead.`,\n      );\n    }\n    const status = probe(configured);\n    if (status === 'observer') return String(configured);\n    if (status === 'occupied') {\n      throw new HostObserverUnavailableError(\n        `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.`,\n      );\n    }\n    throw new HostObserverUnavailableError(\n      `CLAUDE_MEM_HOST_OBSERVER_PORT=${configured} has nothing listening. Start your OpenAI-compatible observer on that port, then rerun with --provider host.`,\n    );","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/8bc631a71a487424b866756e43a6efa4574cc66b/src/npx-cli/cmem-memory-credentials.ts#L219-L255","documentation":"Host observer mode reuses an OpenAI-compatible HTTP server already running on your machine; you point it there via CLAUDE_MEM_HOST_OBSERVER_PORT. Before probing, resolveHostObserverPort parses the variable with parsePort, and any value that is not a plain valid port number (1-65535) makes the install fail fast with this HostObserverUnavailableError so a typo'd URL, protocol prefix, or empty string never gets probed.","triggerScenarios":"Running `npx claude-mem install --provider host` (or any code path calling resolveHostObserverPort / buildHostObserverSettings) with CLAUDE_MEM_HOST_OBSERVER_PORT set to something parsePort rejects — e.g. 'http://127.0.0.1:4141', '4141/', '0', '99999', 'abc', or whitespace.","commonSituations":"Copy-pasting a full base URL instead of the bare port from an observer's docs; setting the variable in shell rc with quotes/newline; typos like '414l'; setting it to 0 or a 6-digit out-of-range port.","solutions":["Set CLAUDE_MEM_HOST_OBSERVER_PORT to the bare integer port your observer listens on, e.g. export CLAUDE_MEM_HOST_OBSERVER_PORT=4141","Unset the variable entirely (unset CLAUDE_MEM_HOST_OBSERVER_PORT) to let claude-mem auto-probe default ports 37777/37778","Verify the value is a decimal number in 1-65535 with no scheme, slashes, or spaces, then rerun the install with --provider host"],"exampleFix":"// before\nexport CLAUDE_MEM_HOST_OBSERVER_PORT=http://127.0.0.1:4141\n// after\nexport CLAUDE_MEM_HOST_OBSERVER_PORT=4141","handlingStrategy":"validation","validationCode":"const raw = process.env.CLAUDE_MEM_HOST_OBSERVER_PORT;\nif (raw) {\n  const port = Number(raw);\n  if (!Number.isInteger(port) || port < 1 || port > 65535) {\n    throw new Error(`CLAUDE_MEM_HOST_OBSERVER_PORT=${raw} is not a valid port (1-65535)`);\n  }\n}","typeGuard":"const isValidPort = (v: unknown): v is number =>\n  typeof v === 'number' && Number.isInteger(v) && v >= 1 && v <= 65535;","tryCatchPattern":"try {\n  const port = resolveHostObserverPort(workerPort, env);\n} catch (e) {\n  if (e instanceof HostObserverUnavailableError && e.message.includes('is not a valid port')) {\n    delete process.env.CLAUDE_MEM_HOST_OBSERVER_PORT; // fall back to auto-discovery\n  } else throw e;\n}","preventionTips":["Store only the bare integer port in CLAUDE_MEM_HOST_OBSERVER_PORT — no scheme, slashes, or quotes","Add a shell-profile check that validates the value with a 1-65535 range test","Prefer unsetting the variable and letting auto-discovery probe 37777/37778"],"tags":["configuration","env-var","port-validation","host-observer"],"backgroundTag":"invalid-env-var-value","analyzedSha":"8bc631a71a487424b866756e43a6efa4574cc66b","analyzedAt":"2026-09-09T10:47:06.009Z","contentChangedAt":"2026-09-09T10:47:06.009Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}