Error: ENOENT: no such file or directory, lstat '/Users/{$profile}/.pyenv'
Resolved 💬 15 comments Opened Apr 18, 2025 by ecsplendid Closed Aug 7, 2025
💡 Likely answer: A maintainer (jonchurch, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
v0.1.2504172351
Which model were you using?
o4-mini
What platform is your computer?
Darwin 24.2.0 arm64 arm
What steps can reproduce the bug?
Doing anything, it crashes after thinking for a while and after applying changes
What is the expected behavior?
It should work
What do you see instead?
node:fs:2788
const stats = binding.lstat(base, true, undefined, true /* throwIfNoEntry */);
^
Error: ENOENT: no such file or directory, lstat '/Users/timscarfe/.pyenv'
at realpathSync (node:fs:2788:29)
at file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:368:3516
at Array.map (<anonymous>)
at Vee (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:368:3425)
at Wee (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:441:254)
at sN (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:441:5715)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async ate (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:441:4898)
at async T0.handleFunctionCall (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:465:4041)
at async T0.processEventsWithoutStreaming (file:///opt/homebrew/lib/node_modules/@openai/codex/dist/cli.js:466:5829) {
errno: -2,
code: 'ENOENT',
syscall: 'lstat',
path: '/Users/timscarfe/.pyenv'
}
Node.js v23.5.0
https://chatgpt.com/share/68024a22-0c64-8011-9a7e-b92963159c92
What actually happened
- When the Codex CLI boots it tries to discover every Python interpreter on your machine.
- One probe is a hard‑coded call to fs.lstatSync('~/.pyenv', / throwIfNoEntry = / true) that lives in the bundled dist/cli.js (around line 368).
- Because you don’t have pyenv installed (or the directory has a different name), fs.lstatSync throws ENOENT (“file or directory not found”).
- That exception is not caught inside Codex CLI, so Node bubbles it up and the whole process dies before the TTY prompt is even initialised. That’s the stack‑trace you’re seeing.
OpenAI Help Center
Node.js — Run JavaScript Everywhere
This isn’t a Node‑23 problem, and it isn’t your shell. It’s simply a missing guard‑clause in Codex CLI’s pyenv‑detection code.
Additional information
_No response_
15 Comments
Hey can I work on this issue ?
Same, just got this issue:
node:fs:2788
const stats = binding.lstat(base, true, undefined, true / throwIfNoEntry /);
^
Error: ENOENT: no such file or directory, lstat '/Users/ray/.pyenv'
at realpathSync (node:fs:2788:29)
at file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:368:3516
at Array.map (<anonymous>)
at Vee (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:368:3425)
at Wee (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:441:254)
at sN (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:441:5715)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async ate (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:441:4898)
at async T0.handleFunctionCall (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:465:4041)
at async T0.processEventsWithoutStreaming (file:///Users/ray/Desktop/GITHUB/codex/codex-cli/dist/cli.js:466:5829) {
errno: -2,
code: 'ENOENT',
syscall: 'lstat',
path: '/Users/ray/.pyenv'
}
Node.js v23.10.0
Codex is now unuseable
Not a fix, but you can revert back to the previous version as a workaround:
npm i -g @openai/codex@0.1.2504161551Instead it looks like I installed Codex via homebrew, and all that was needed was the .pyenv in my root, and now works properly:
"What We Did (Simple Steps)
Created the missing .pyenv directory that Codex was looking for
Restored the code to the latest version
Successfully launched Codex with the newest version (v0.1.2504180837)
Why This Fixed It
The Codex CLI is checking for Python environments across your system. Creating that empty directory fixed the bug because now when Codex looks for that directory, it finds it and doesn't crash.
Technical Note
This is an example of proper error handling - the application should have checked if that directory existed before trying to access it. This simple directory creation fixed what would have been a one-line code fix in the application itself.
You can now use the Codex CLI as intended with the latest version. The empty .pyenv directory won't affect anything on your system - it's just there so the application doesn't crash when looking for it."
If this didn't work I was going to use the roll back
I got the same error
It looks like this issue was introduced in the last release with this PR https://github.com/openai/codex/pull/275 by @jonchurch
I run into the same issue, it triggers quite fast.
Ah yes, this makes sense.
realpath is likely throwing here, due to the path not existing, I did not consider that possibility
How are you reproducing this? full auto mode or interactive?
I do not have that dir on my system, but have never seen this error
Full auto. Windsurf and API was able to fix it locally via my comment above if that helps.
Revert PR https://github.com/openai/codex/pull/370
cc @fouad-openai @tibo-openai
Sorry for the breakage folks, you can either
mkdir -p ~/.pyenvto unblockor
npm i -g @openai/codex@0.1.2504161551to roll yourself backI'll open a PR that does the same thing but will handle exceptions for non existant writeable roots, falling back to their non resolved paths for consideration
To repro, try full auto mode and ask it to “take a deep look and update the readme”
If we can get #172 merged, it will address this issue
Thanks for the feedback! Please try again on the latest version of Codex CLI. If the issue persists, let us know.
This issue still persists in the
codex-rsversion