Yeachan-Heo/oh-my-codex · error · Error

codex login exited with code ${result.status ?? 1}

Error message

codex login exited with code ${result.status ?? 1}

What it means

The codex login child process launched successfully but exited with a non-zero status; omx propagates that exit code as an error. The underlying cause is whatever made codex login fail (cancelled device flow, invalid API key, network error), and codex's own output (inherited stdio) appears above this error.

Source

Thrown at src/cli/auth.ts:55

}

function runCodexLogin(cwd: string, env: NodeJS.ProcessEnv, loginArgs: string[] = []): void {
  validateCodexLoginArgs(loginArgs);
  const { result } = spawnPlatformCommandSync("codex", ["login", ...loginArgs], {
    cwd,
    env,
    stdio: "inherit",
    encoding: "utf-8",
  });
  if (result.error) {
    const error = result.error as NodeJS.ErrnoException;
    const kind = classifySpawnError(error);
    if (kind === "missing") throw new Error("failed to launch codex login: executable not found in PATH");
    if (kind === "blocked") throw new Error(`failed to launch codex login: executable is blocked (${error.code || "blocked"})`);
    throw error;
  }
  if (result.status !== 0) {
    throw new Error(`codex login exited with code ${result.status ?? 1}`);
  }
}
async function fileExists(path: string): Promise<boolean> {
  try {
    await readFile(path);
    return true;
  } catch (error) {
    if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
    throw error;
  }
}

async function createIsolatedLoginCodexHome(home: string | undefined): Promise<string> {
  const base = join(home || homedir(), ".omx");
  await mkdir(base, { recursive: true, mode: 0o700 });
  return await mkdtemp(join(base, "auth-login-"));
}

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Read the codex output printed before the error — it names the actual failure
  2. Retry the login and complete the device-auth flow within the time limit
  3. For --with-api-key/--with-access-token, verify the credential is valid and not expired
  4. Check network/proxy access to the codex auth endpoints
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate credentials where possible before login
if (mode === '--with-api-key' && !/^(sk-)?[A-Za-z0-9_-]{20,}$/.test(key)) throw new Error('key looks invalid');

Try / catch

catch (e) { const m = /codex login exited with code (\d+)/.exec(String(e)); if (m) { reportAuthFailure(+m[1]); } else throw e; }

Prevention

When it happens

Trigger: Completing/aborting `codex login` interactively and choosing failure, passing an invalid key via --with-api-key, codex hitting network/auth-server errors, or the user pressing Ctrl+C during the device-auth flow.

Common situations: Expired or mistyped API keys; device-auth timeout; corporate proxies breaking codex's auth endpoints; user cancelling the browser flow.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/7423bf1a6c385495. Report an issue: GitHub.