Unable to locate Codex CLI binaries. Ensure @openai/codex is installed with optional dependencies.

Resolved 💬 7 comments Opened Apr 1, 2026 by zy445566 Closed Apr 2, 2026
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of Codex CLI is running?

codex-cli 0.118.0

What subscription do you have?

enterprise

Which model were you using?

gpt-5.4

What platform is your computer?

Microsoft Windows NT 10.0.26200.0 x64

What terminal emulator and version are you using (if applicable)?

VSCode

What issue are you seeing?

Unable to locate Codex CLI binaries. Ensure @openai/codex is installed with optional dependencies.

What steps can reproduce the bug?

the project which I use npx create-next-app@latest --all --yes to create

What is the expected behavior?

I debug the node_modules\@openai\codex-sdk\dist\index.js

try {
    const codexPackageJsonPath = moduleRequire.resolve(`${CODEX_NPM_NAME}/package.json`);
    const codexRequire = createRequire(codexPackageJsonPath);
    const platformPackageJsonPath = codexRequire.resolve(`${platformPackage}/package.json`);
    vendorRoot = path2.join(path2.dirname(platformPackageJsonPath), "vendor");
  } catch(error) {
    console.log(error)
    throw new Error(
      `Unable to locate Codex CLI binaries. Ensure ${CODEX_NPM_NAME} is installed with optional dependencies.`
    );
  }

the real error shows

TypeError: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received '[project]/Documents/mynextproject/node_modules/@openai/codex/package.json.[json].cjs [app-route] (ecmascript)'

Additional information

My temporary solution:

let codex;
if(platform==='win32') {
codex = new Codex({
    codexPathOverride: path.resolve(process.cwd(), "node_modules/@openai/codex-win32-x64/vendor/x86_64-pc-windows-msvc/codex/codex.exe)
  });
} else {
codex = new Codex({
    codexPathOverride: path.resolve(process.cwd(), "node_modules/@openai/codex/bin/codex.js")
  });
}

View original on GitHub ↗

7 Comments

github-actions[bot] contributor · 3 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #14844

Powered by Codex Action

etraut-openai contributor · 3 months ago

This doesn't look like a Codex bug, but rather a bug in your code that attempts to launch codex. If I'm misunderstanding the problem, let me know.

zy445566 · 3 months ago
This doesn't look like a Codex bug, but rather a bug in your code that attempts to launch codex. If I'm misunderstanding the problem, let me know.

@etraut-openai

the case happened when I use the npm package "@openai/codex-sdk" in the next.js project

import { Codex } from "@openai/codex-sdk";

const codex = new Codex();
const thread = codex.startThread();
const turn = await thread.run("Diagnose the test failure and propose a fix");

console.log(turn.finalResponse);
console.log(turn.items);
Jian-Mengs · 2 months ago

mine is this <img width="1116" height="306" alt="Image" src="https://github.com/user-attachments/assets/b5bc45c9-1ec9-47da-a220-63e06a5e7a6b" />

aideskdevservice · 1 month ago
mine is this <img alt="Image" width="1116" height="306" src="https://private-user-images.githubusercontent.com/192562055/596127470-b5bc45c9-1ec9-47da-a220-63e06a5e7a6b.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODEzMDY2OTUsIm5iZiI6MTc4MTMwNjM5NSwicGF0aCI6Ii8xOTI1NjIwNTUvNTk2MTI3NDcwLWI1YmM0NWM5LTFlYzktNDdkYS1hMjIwLTYzZTA2YTVlN2E2Yi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjYwNjEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI2MDYxMlQyMzE5NTVaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1lYzI0MWUzODdlYjIyZDZiNzJiYTA4MDNmZDcwNGMwZmIxMzU5OTQ3YWYzZjQxYjIxODFlNGY0NTJkZGMxOGZlJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZyZXNwb25zZS1jb250ZW50LXR5cGU9aW1hZ2UlMkZwbmcifQ.94g-wcZrudsewbiSdGkc9SGD9Myc0iIs4pM9gVP8bsE">

same here, any solution to fix this?

offcharken · 1 month ago

Fixed: I set the Windows user variable:
CODEX_CLI_PATH=C:\Users\offcharken\.codex\packages\standalone\current\bin\codex.exe

black-yt · 1 month ago

更新 Codex App 后出现:

Unable to locate the Codex CLI binary

如果之前在 Codex App 里把 Agent Environment 设置成了 WSL,那么实际上系统里可能同时存在 3 个 Codex:

  1. Windows npm 安装的 Codex
C:\Users\<user>\AppData\Roaming\npm\codex
C:\Users\<user>\AppData\Roaming\npm\codex.cmd

这是在 Windows 终端里执行 codex 用的。

  1. WSL 里自己安装的 Codex

例如:

/home/xwh/.nvm/versions/node/v22.22.2/bin/codex

这是你在 Ubuntu/WSL 终端里执行 codex 用的。

  1. Codex App 自动生成的 WSL Wrapper(真正被 App 调用的)

例如:

C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex

这是 Codex App 为了桥接 Windows 和 WSL 自动生成的启动器。

问题的根源在于:

  • 更新前,Codex App 被设置为使用 WSL 环境。
  • 很多人以为它直接调用第 2 个(WSL 里的 codex)。
  • 实际上它调用的是第 3 个(自己生成的 WSL Wrapper)。
  • 更新后 App 丢失了这个 Wrapper 的定位信息。
  • 因此启动时报:
Unable to locate the Codex CLI binary

很多人会误把环境变量设置到:

AppData\Roaming\npm\codex

或者:

/home/.../codex

结果会出现各种奇怪错误(.cmd 语法错误、node not found 等)。

正确修复方法:

先找到 App 自动生成的 WSL Wrapper,找到类似:

C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex

然后设置:

setx CODEX_CLI_PATH "C:\Users\<user>\.codex\bin\wsl\48731301ce01af57\codex"

验证:

echo %CODEX_CLI_PATH%

重启 Codex App 即可恢复。