Repository navigation
Description
What version of Codex CLI is running?
codex-cli 0.130.0
What subscription do you have?
Pro
Which model were you using?
gpt-5.5
What platform is your computer?
Microsoft Windows NT 10.0.26200.0 x64
What terminal emulator and version are you using (if applicable)?
Windows Terminal 1.24.11321.0 PowerShell 7.6.1 No terminal multiplexer.
Codex doctor report
not available
`codex doctor --json` does not appear to be supported in codex-cli 0.130.0. Running it returns:
error: unexpected argument '--json' foundWhat issue are you seeing?
When running codex update from inside an active Codex CLI session on Windows, Codex updates via npm install -g @openai/codex, but npm then emits cleanup warnings because it cannot remove a temporary install directory containing codex.exe.
Observed output:
npm warn cleanup Failed to remove some directories [
npm warn cleanup [
npm warn cleanup 'C:\Users\\AppData\Roaming\npm\node_modules\@openai\.codex-l0XzpfJG',
npm warn cleanup [Error: EPERM: operation not permitted, unlink 'C:\Users\\AppData\Roaming\npm\node_modules\@openai\.codex-l0XzpfJG
\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe'] {
npm warn cleanup errno: -4048,
npm warn cleanup code: 'EPERM',
npm warn cleanup syscall: 'unlink',
npm warn cleanup path: 'C:\Users\\AppData\Roaming\npm\node_modules\@openai\.codex-l0XzpfJG\node_modules\@openai\codex-win32-x64
\vendor\x86_64-pc-windows-msvc\codex\codex.exe'
npm warn cleanup }
npm warn cleanup ]
npm warn cleanup ]
The update appears to complete, but the warning is confusing and leaves temporary .codex-* install directories behind.
What steps can reproduce the bug?
- On Windows, open Codex CLI in Windows Terminal / PowerShell.
- Start or continue an interactive Codex CLI session.
- Run
codex updatethrough Codex. - Observe that the update invokes
npm install -g @openai/codex. - After installation, npm emits cleanup warnings with
EPERM: operation not permitted, unlink ... codex.exe.
Uploaded thread: 019e3b9c-2a56-7412-a69d-9df4d7172591
What is the expected behavior?
codex update should work as a Windows-safe self-update without producing npm cleanup warnings and without leaving temporary .codex-* directories behind.
If the running Codex process prevents immediate cleanup, the updater should use a Windows-safe strategy such as a separate updater process, side-by-side versioned install, deferred cleanup, or another mechanism that does not try to remove the active codex.exe.
Additional information
This seems specific to the self-update path on Windows. Other tools avoid this class of issue by delegating the update to a separate process, using versioned side-by-side installs, or deferring cleanup until the running executable is no longer locked.
Activity
github-actions commentedon May 18, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
scheatham-citadel commentedon Jun 17, 2026
Still reproduces on codex-cli 0.140.0 on Windows.
Running
codex updatecompletes successfully but still emits the npm cleanup warning:EPERM: operation not permitted, unlink
C:\Users<user>\AppData\Roaming\npm\[email protected]...\node_modules@openai\codex-win32-
x64\vendor\x86_64-pc-windows-msvc\bin\codex.exe
The stale
.codex-*temp directory is recreated each time. The update succeeds, but the warning remains confusing andlooks like the updater is still trying to clean up a locked Codex executable.
txchiang commentedon Jun 30, 2026
Additional reproduction from a Windows/nvm install on 2026-06-30.
Environment observed:
codex-cli 0.142.4npm install -g @openai/codex11.12.1 -> 11.18.0C:\Users\<user>\AppData\Local\nvm\v25.9.0\node_modules\@openai\...codexCLI process was present.Observed warning:
Post-update checks:
codex --versionreturnscodex-cli 0.142.4, so the update itself appears to succeed....\node_modules\@openai\.codex-dZHYjNjNafter the update.This looks consistent with the running Windows executable/package binary being locked during npm's cleanup phase.
tomooch commentedon Jun 30, 2026
I can reproduce this Windows npm cleanup warning on
codex-cli 0.142.4.In my environment,
codex updatesucceeds, but npm prints:I also confirmed that manually deleting the stale
.codex-*directory after the update succeeds, so the lock appears to be transient while the oldcodex.exeis still running.I investigated a possible fix and prepared a small branch here:
https://github.com/tomooch/codex/tree/fix-windows-npm-update-cleanup
Approach:
codex.exemay still be locked.node_modules/@openaidirectory fromcurrent_exe()instead of hardcoding%APPDATA%..codex-*directories directly under that derived@openaidirectory.Validation:
macOS:
cargo fmt -p codex-clicargo test -p codex-cli --bin codexcargo check -p codex-clicargo clippy -p codex-cli --testsWindows:
cargo check -p codex-cli: passedcargo clippy -p codex-cli --tests: passedcargo test -p codex-cli --bin codex derives_npm_openai_dir_from_exe: passedcargo test -p codex-cli --bin codex builds_delayed_cleanup_script: passedcargo test -p codex-cli --bin codex: compiled and ran; 216 passed, 1 unrelateddoctor::thread_inventorytest failedGiven the contributing guidelines say external PRs are by invitation only, I have not opened a PR yet. If this approach aligns with the intended direction, I’d be happy to open a focused PR.
JoeyBling commentedon Jul 29, 2026
Try After exiting Codex/IDE, execute in standalone PowerShell:
txchiang commentedon Aug 5, 2026
lumatic2 commentedon Sep 30, 2026
Additional Windows reproduction: the npm self-update fails before installing the new version, rather than succeeding with only an
EPERMcleanup warning.@openai/[email protected], native package0.158.0-win32-x64,codex-cli 0.158.0.npm install -g @openai/codexwhile Codex CLI sessions from the same global npm installation were still running. At the time, two livecodex-code-mode-host.exeprocesses had executable paths under the package being replaced (one from the current session and one from an older session).reify mark retired, then fails inreify:retireShallow:This is a different failure stage from the previously reported post-update cleanup warnings: npm cannot retire/copy the old platform package, exits nonzero, and leaves the CLI at 0.158.0. The observed live executable paths strongly suggest a Windows file lock, although I did not capture an OS handle trace. A safe updater should avoid replacing the active installation while its CLI/helper processes are running, or report the blocking processes and a concrete recovery step.
leechristensen commentedon Oct 14, 2026
Running
codex.exe updatecauses this.A workaround is to update with npm directly:
Root cause is that on Windows you cannot delete a folder if a file handle is currently opened inside of it. During the update, the current (old version)
codex.exehas its parent directory renamed, which Windows allows.npmattempts to delete the renamed directory, which fails since codex.exe is still running.To confirm, I ran ProcMon during the update and observed the following:
Related: