Windows: codex update leaves npm cleanup warning because codex.exe is locked

Open 💬 6 comments Opened May 18, 2026 by ufthygygh
💡 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.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' found

What 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\\<user>\\AppData\\Roaming\\npm\\node_modules\\@openai\\.codex-l0XzpfJG',
npm warn cleanup [Error: EPERM: operation not permitted, unlink 'C:\\Users\\<user>\\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\\<user>\\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?

  1. On Windows, open Codex CLI in Windows Terminal / PowerShell.
  2. Start or continue an interactive Codex CLI session.
  3. Run codex update through Codex.
  4. Observe that the update invokes npm install -g @openai/codex.
  5. 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.

View original on GitHub ↗

6 Comments

github-actions[bot] contributor · 3 months ago

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

  • #21872

Powered by Codex Action

scheatham-citadel · 2 months ago

Still reproduces on codex-cli 0.140.0 on Windows.

Running codex update completes successfully but still emits the npm cleanup warning:

EPERM: operation not permitted, unlink
C:\Users\<user>\AppData\Roaming\npm\node_modules\@openai\.codex-...\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 and
looks like the updater is still trying to clean up a locked Codex executable.

txchiang · 1 month ago

Additional reproduction from a Windows/nvm install on 2026-06-30.

Environment observed:

  • Codex CLI after update: codex-cli 0.142.4
  • Install/update command shown by Codex: npm install -g @openai/codex
  • npm version notice in output: 11.12.1 -> 11.18.0
  • Global package location pattern: C:\Users\<user>\AppData\Local\nvm\v25.9.0\node_modules\@openai\...
  • Codex app was also running during the update, and at least one codex CLI process was present.

Observed warning:

npm warn cleanup Failed to remove some directories [
npm warn cleanup   [
npm warn cleanup     'C:\Users\<user>\AppData\Local\nvm\v25.9.0\node_modules\@openai\.codex-dZHYjNjN',
npm warn cleanup     [Error: EPERM: operation not permitted, unlink 'C:\Users\<user>\AppData\Local\nvm\v25.9.0\node_modules\@openai\.codex-dZHYjNjN\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\bin\codex.exe'] {
npm warn cleanup       errno: -4048,
npm warn cleanup       code: 'EPERM',
npm warn cleanup       syscall: 'unlink',
npm warn cleanup       path: 'C:\Users\<user>\AppData\Local\nvm\v25.9.0\node_modules\@openai\.codex-dZHYjNjN\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\bin\codex.exe'
npm warn cleanup     }
npm warn cleanup   ]
npm warn cleanup ]

changed 2 packages in 5s

Post-update checks:

  • codex --version returns codex-cli 0.142.4, so the update itself appears to succeed.
  • The temporary directory remained at ...\node_modules\@openai\.codex-dZHYjNjN after the update.

This looks consistent with the running Windows executable/package binary being locked during npm's cleanup phase.

tomooch · 1 month ago

I can reproduce this Windows npm cleanup warning on codex-cli 0.142.4.

In my environment, codex update succeeds, but npm prints:

npm warn cleanup Failed to remove some directories
EPERM: operation not permitted, unlink ... .codex-*/.../codex.exe

I also confirmed that manually deleting the stale .codex-* directory after the update succeeds, so the lock appears to be transient while the old codex.exe is 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:

  • Only affects Windows.
  • Only applies to the npm update path.
  • Runs only after a successful npm update.
  • Does not hide npm failures.
  • Schedules a detached best-effort cleanup process instead of trying to delete synchronously while codex.exe may still be locked.
  • Derives the npm node_modules/@openai directory from current_exe() instead of hardcoding %APPDATA%.
  • Deletes only .codex-* directories directly under that derived @openai directory.

Validation:

  • macOS:
  • cargo fmt -p codex-cli
  • cargo test -p codex-cli --bin codex
  • cargo check -p codex-cli
  • cargo clippy -p codex-cli --tests
  • Windows:
  • cargo check -p codex-cli: passed
  • cargo clippy -p codex-cli --tests: passed
  • cargo test -p codex-cli --bin codex derives_npm_openai_dir_from_exe: passed
  • cargo test -p codex-cli --bin codex builds_delayed_cleanup_script: passed
  • cargo test -p codex-cli --bin codex: compiled and ran; 216 passed, 1 unrelated doctor::thread_inventory test failed

Given 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 · 1 month ago

Try After exiting Codex/IDE, execute in standalone PowerShell:

Get-Process -Name codex,codex-code-mode-host -ErrorAction SilentlyContinue | Stop-Process -Force
txchiang · 22 days ago

Dear Sir,
The command you provided did not work. The archived chats are stored in the cloud, and as shown in the attached screenshot, there is no option to delete them.
Could you please advise me on how to permanently delete these archived chats?
Best regards,

@.***

From: 周思伟 @.*>
Sent: Wednesday, July 29, 2026 10:39 AM
To: openai/codex
@.*>
Cc: txchiang @.>; Comment @.>
Subject: Re: [openai/codex] Windows: codex update leaves npm cleanup warning because codex.exe is locked (Issue #23320)

[影像被寄件者移除。]JoeyBling left a comment (openai/codex#23320)<https://github.com/openai/codex/issues/23320#issuecomment-5112163031>

Try After exiting Codex/IDE, execute in standalone PowerShell:

Get-Process -Name codex,codex-code-mode-host -ErrorAction SilentlyContinue | Stop-Process -Force

—
Reply to this email directly, view it on GitHub<https://github.com/openai/codex/issues/23320?email_source=notifications&email_token=APNHHKPR7K6RJQUVMJUZUED5HFPT7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJRGIYTMMZQGMY2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-5112163031>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/APNHHKI3KCMZFR65OAVXXCD5HFPT7AVCNFSNUABFKJSXA33TNF2G64TZHM4TMNJUGE2TMNBZHNEXG43VMU5TINBXGA2TIMZXGEZKC5QC>.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS<https://github.com/notifications/mobile/ios/APNHHKK5IQX5K3UJRSV247T5HFPT7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJRGIYTMMZQGMY2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJKTGN5XXIZLSL5UW64Y> and Android<https://github.com/notifications/mobile/android/APNHHKIVX2E2DNYA2XEHOVD5HFPT7A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTKMJRGIYTMMZQGMY2M4TFMFZW63VHMNXW23LFNZ2KKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>. Download it today!
You are receiving this because you commented.Message ID: @.***>