Skip to content

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

Open

Description

@ufthygygh

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\\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?

  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.

Activity

  1. added
    bug
    on May 18, 2026
  2. added
    CLI
    windows-os
    on May 18, 2026
  3. github-actions commented on May 18, 2026

    @github-actions
    Contributor

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

    Powered by Codex Action

  4. scheatham-citadel commented on Jun 17, 2026

    @scheatham-citadel

    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\[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 and
    looks like the updater is still trying to clean up a locked Codex executable.

  5. txchiang commented on Jun 30, 2026

    @txchiang

    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.

  6. tomooch commented on Jun 30, 2026

    @tomooch

    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.

  7. JoeyBling commented on Jul 29, 2026

    @JoeyBling

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

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

  8. txchiang commented on Aug 5, 2026

    @txchiang
  9. lumatic2 commented on Sep 30, 2026

    @lumatic2

    Additional Windows reproduction: the npm self-update fails before installing the new version, rather than succeeding with only an EPERM cleanup warning.

    • Platform: Windows 11 Home x64, build 26200; Node v24.14.1; npm 11.11.0.
    • Installed Codex before and after failure: @openai/[email protected], native package 0.158.0-win32-x64, codex-cli 0.158.0.
    • Trigger: the built-in update ran npm install -g @openai/codex while Codex CLI sessions from the same global npm installation were still running. At the time, two live codex-code-mode-host.exe processes had executable paths under the package being replaced (one from the current session and one from an older session).
    • npm debug log reaches reify mark retired, then fails in reify:retireShallow:
    Error: EBUSY: resource busy or locked, copyfile
      ...\node_modules\@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\bin\codex-code-mode-host.exe
      -> ...\node_modules\@openai\.codex-bF8cGTP1\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\bin\codex-code-mode-host.exe
    npm exit -4082
    

    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.

  10. leechristensen commented on Oct 14, 2026

    @leechristensen

    Running codex.exe update causes this.
    A workaround is to update with npm directly:

    npm install -g @openai/codex@latest
    

    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.exe has its parent directory renamed, which Windows allows. npm attempts 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:

    Time (PM) | Trace evidence
    -- | --
    1:13:46.867 | codex.exe PID 10920 starts with argument update.
    1:13:47.222 | That process launches npm install -g @openai/codex, which runs as Node PID 38492.
    1:13:56.851 | npm successfully renames the old executable into .codex-ulonQI0y.
    1:14:06.133 | npm finishes writing the replacement codex.exe.
    1:14:06.369 | npm opens the old executable with Delete access successfully, but SetDispositionInformationEx returns CANNOT DELETE, twice.
    1:14:06.417 | npm exits with status 0.
    1:14:06.541 | The original Codex updater finally exits, also with status 0.
    
    
    The old executable remains mapped into the running updater until npm finishes. Windows allows the rename but prevents deletion while that executable is running. This explains the EPERM warning; the successful Delete-access open points away from an ordinary permissions problem.
    

    Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugwindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions