apply_patch execution failed

Open 💬 2 comments Opened Jun 10, 2026 by wangzhilin777
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the Codex App are you using (From “About Codex” dialog)?

26.602.40724

What subscription do you have?

plus

What platform is your computer?

WIN10 X64

What issue are you seeing?

After the Codex client was updated, the apply_patch launch path was switched from Windows Apps to AppData\Local\OpenAI\Codex\bin
But the current thread or some residual temporary directory is still holding the old wrapper
As a result, the phenomenon of "the same machine, the same Codex, sometimes it can be used and sometimes it is denied access" appeared
Why is the old entry cache not processed before changing paths?

What steps can reproduce the bug?

fix the problem

What is the expected behavior?

_No response_

Additional information

_No response_

View original on GitHub ↗

2 Comments

github-actions[bot] contributor · 2 months ago

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

  • #26087
  • #26011
  • #25860
  • #27171

Powered by Codex Action

chenziwenhaoshuai · 1 month ago

Windows MSIX apply_patch Workaround

I found a working workaround for the Windows MSIX version of Codex Desktop.

The problem is that Codex Desktop generates apply_patch.bat with an absolute path to:

C:\Program Files\WindowsApps\...\app\resources\codex.exe

That packaged executable returns Access is denied when launched by an external shell process.

Workaround

Set CODEX_CLI_PATH as a Windows user-level environment variable, before starting Codex Desktop:

$npmRoot = (& npm.cmd root -g).Trim()
$cli = Join-Path $npmRoot `
  '@openai\codex\node_modules\@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\bin\codex.exe'

if (-not (Test-Path -LiteralPath $cli)) {
  throw "Codex CLI binary not found: $cli"
}

[Environment]::SetEnvironmentVariable('CODEX_CLI_PATH', $cli, 'User')
Write-Host "CODEX_CLI_PATH=$cli"

Then completely exit Codex Desktop, terminate any remaining codex.exe processes, and start Codex again.

After restarting, the generated wrapper points to the npm-installed CLI instead:

@echo off
"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" --codex-run-as-apply-patch %*

apply_patch then works normally. I verified this with a multiline patch that created a file successfully.

Important Details

CODEX_CLI_PATH must be a Windows user-level environment variable inherited by the Codex Desktop process before startup. Setting the same name only inside ~/.codex/config.toml is not sufficient for this fix.

This workaround does not modify WindowsApps ACLs or patch the temporary .codex\tmp\arg0 directory, which Codex regenerates after restarting.

Verification

After restarting Codex, check the generated wrapper:

$wrapper = (Get-Command apply_patch).Source
Get-Content -Raw $wrapper

The wrapper should reference the npm-installed codex.exe, not the executable under C:\Program Files\WindowsApps.