{"record":{"id":"0686b95a0ba31377","repo":"thedotmack/claude-mem","slug":"failed-to-locate-codex-via-where-falling-back-to","errorCode":null,"errorMessage":"Failed to locate codex via where; falling back to codex.cmd","messagePattern":"Failed to locate codex via where; falling back to codex\\.cmd","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/integrations/CodexCliInstaller.ts","lineNumber":100,"sourceCode":"  for (const candidate of candidates) {\n    const resolved = findAncestorWithCodexMarketplace(candidate);\n    if (resolved && missingMarketplaceFiles(resolved).length === 0) return resolved;\n  }\n\n  throw new Error('Could not locate a Codex marketplace root with .agents/plugins/marketplace.json and plugin/.codex-plugin/plugin.json. Run npx claude-mem@latest install from the package or repo root.');\n}\n\nfunction lookupCodexOnWindows(): string | null {\n  let stdout: string;\n  try {\n    stdout = execFileSync('where.exe', ['codex'], {\n      encoding: 'utf-8',\n      stdio: ['ignore', 'pipe', 'ignore'],\n      windowsHide: true,\n    });\n  } catch (error) {\n    const err = error instanceof Error ? error : new Error(String(error));\n    logger.warn('WORKER', 'Failed to locate codex via where; falling back to codex.cmd', { command: 'where codex' }, err);\n    return null;\n  }\n\n  const candidates = stdout\n    .split(/\\r?\\n/)\n    .map((line) => line.trim())\n    .filter(Boolean);\n  return candidates.find((candidate) => WINDOWS_CODEX_EXTENSIONS.has(path.extname(candidate).toLowerCase()))\n    ?? candidates[0]\n    ?? null;\n}\n\nexport function resolveCodexCommand(\n  platform: NodeJS.Platform = process.platform,\n  windowsLookup: () => string | null = lookupCodexOnWindows,\n): string {\n  if (platform !== 'win32') return 'codex';\n  return windowsLookup() ?? 'codex.cmd';","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/integrations/CodexCliInstaller.ts#L82-L118","documentation":"On Windows, the Codex CLI installer locates the codex binary with `where.exe codex`. When that fails — codex not installed or not on the PATH inherited by claude-mem (where.exe exits nonzero), or where.exe itself unavailable — this warning is logged and null is returned. The caller then falls back to a hardcoded codex.cmd path, which may or may not match the real install location.","triggerScenarios":"execFileSync('where.exe', ['codex']) throws: codex is not installed, codex's directory is missing from the process PATH (shell-only PATH changes from nvm/volta/scoop), or where.exe is absent from System32.","commonSituations":"Installing claude-mem's codex integration before installing codex; PATH configured only in the interactive shell so spawned processes never see it; running under a service or scheduled task with a minimal environment.","solutions":["Verify codex is installed and `where codex` succeeds in a fresh terminal.","Install codex globally (e.g. npm i -g @openai/codex) or add its directory to the user PATH, then restart the worker.","If PATH is correct only in your shell, set it system-wide (setx or System Properties) so spawned processes inherit it.","Confirm the codex.cmd fallback path actually points at your install before relying on it."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// verify codex is resolvable before running the installer step\nimport { spawnSync } from 'node:child_process';\nconst probe = spawnSync('where.exe', ['codex'], { encoding: 'utf8', windowsHide: true });\nif (probe.status !== 0) {\n  throw new Error('codex not on PATH; install it or fix PATH before continuing');\n}","typeGuard":null,"tryCatchPattern":"let codexPath = lookupCodexOnWindows();\nif (!codexPath) codexPath = 'codex.cmd'; // explicit fallback, logged once","preventionTips":["Install codex before enabling its claude-mem integration.","Prefer system-wide PATH changes (setx) over shell-profile-only edits for spawned processes.","Restart the worker after PATH changes so it inherits the new environment."],"tags":["windows","path-lookup","codex","integration"],"backgroundTag":"executable-not-on-path","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","contentChangedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}