thedotmack/claude-mem · warning

Failed to locate codex via where; falling back to codex.cmd

Error message

Failed to locate codex via where; falling back to codex.cmd

What it means

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.

Source

Thrown at src/services/integrations/CodexCliInstaller.ts:100

  for (const candidate of candidates) {
    const resolved = findAncestorWithCodexMarketplace(candidate);
    if (resolved && missingMarketplaceFiles(resolved).length === 0) return resolved;
  }

  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.');
}

function lookupCodexOnWindows(): string | null {
  let stdout: string;
  try {
    stdout = execFileSync('where.exe', ['codex'], {
      encoding: 'utf-8',
      stdio: ['ignore', 'pipe', 'ignore'],
      windowsHide: true,
    });
  } catch (error) {
    const err = error instanceof Error ? error : new Error(String(error));
    logger.warn('WORKER', 'Failed to locate codex via where; falling back to codex.cmd', { command: 'where codex' }, err);
    return null;
  }

  const candidates = stdout
    .split(/\r?\n/)
    .map((line) => line.trim())
    .filter(Boolean);
  return candidates.find((candidate) => WINDOWS_CODEX_EXTENSIONS.has(path.extname(candidate).toLowerCase()))
    ?? candidates[0]
    ?? null;
}

export function resolveCodexCommand(
  platform: NodeJS.Platform = process.platform,
  windowsLookup: () => string | null = lookupCodexOnWindows,
): string {
  if (platform !== 'win32') return 'codex';
  return windowsLookup() ?? 'codex.cmd';

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Verify codex is installed and `where codex` succeeds in a fresh terminal.
  2. Install codex globally (e.g. npm i -g @openai/codex) or add its directory to the user PATH, then restart the worker.
  3. If PATH is correct only in your shell, set it system-wide (setx or System Properties) so spawned processes inherit it.
  4. Confirm the codex.cmd fallback path actually points at your install before relying on it.
Defensive patterns

Strategy: fallback

Validate before calling

// verify codex is resolvable before running the installer step
import { spawnSync } from 'node:child_process';
const probe = spawnSync('where.exe', ['codex'], { encoding: 'utf8', windowsHide: true });
if (probe.status !== 0) {
  throw new Error('codex not on PATH; install it or fix PATH before continuing');
}

Try / catch

let codexPath = lookupCodexOnWindows();
if (!codexPath) codexPath = 'codex.cmd'; // explicit fallback, logged once

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of thedotmack/claude-mem@e2d1df569a (2026-08-20). Data as JSON: /api/errors/0686b95a0ba31377. Report an issue: GitHub.