Windows Desktop regression: generated `apply_patch.bat` calls inaccessible WindowsApps `codex.exe` instead of local `CODEX_CLI_PATH`
What version of the Codex App are you using (From “About Codex” dialog)?
26.616.51431
What subscription do you have?
Plus
What platform is your computer?
Microsoft Windows NT 10.0.26200.0
What issue are you seeing?
### This may be related to existing Windows sandbox/apply_patch issues such as #29200, but I am opening this separately because I found a more specific root-cause signal: the generated temporary apply_patch.bat wrapper points to the protected WindowsApps-packaged codex.exe, which returns Access is denied when run directly, while the local cached Codex CLI path from CODEX_CLI_PATH runs successfully.
Summary
On Codex Desktop for Windows, apply_patch fails because the generated temporary apply_patch.bat wrapper points to the packaged codex.exe under C:\Program Files\WindowsApps\..., which cannot be executed directly from my user/shell context and returns Access is denied.
A local cached Codex CLI binary exists and runs successfully from:
C:\Users\a******\AppData\Local\OpenAI\Codex\bin\8e55c2dd143b6354\codex.exe
So the issue appears to be that the generated apply_patch.bat wrapper is using an inaccessible WindowsApps package path instead of the accessible local cached CLI path / CODEX_CLI_PATH.
Environment
OS: Microsoft Windows 10.0.26200.8655
Codex Desktop app version seen in config: 26.616.51431 / later package path 26.616.6631.0
Codex CLI local cached version: codex-cli 0.142.0-alpha.6
Windows sandbox config:
[windows]
sandbox = "unelevated"
Relevant config value from ~\.codex\config.toml:
CODEX_CLI_PATH = 'C:\Users\a***\AppData\Local\OpenAI\Codex\bin\8e55c2dd143b6354\codex.exe'
Symptoms**
When Codex tries to use apply_patch, it reports that the Windows sandbox wrapper / local apply_patch tool refused to run. The fallback also fails.
Example Codex output:
The local apply_patch tool technically refused to run in the new Windows sandbox profile; I will apply the same unified patch via git apply without expanding the file scope.
Then git apply fails because the input is in apply_patch format, not standard diff --git format:
error: No valid patches in input (allow with "--allow-empty")
When Codex tries the generated apply_patch.bat directly, it fails with:
Access is denied.
Investigation
Codex generated this temporary wrapper:
C:\Users\a*****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat
Get-Command apply_patch resolves to:
Get-Command apply_patch -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
Output:
C:\Users\a*****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat
The contents of the generated wrapper are:
@echo off
"C:\Program Files\WindowsApps\OpenAI.Codex_26.616.6631.0_x64__2p2nqsd0c76g0\app\resources\codex.exe" --codex-run-as-apply-patch %*
Running this wrapper manually also fails:
& "C:\Users\a*****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat"
Output:
Access is denied.
The wrapper file itself appears to have correct ACLs:
icacls "C:\Users\a*****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat"
Output:
C:\Users\a****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
DESKTOP-**\a***:(I)(F)
Successfully processed 1 files; Failed processing 0 files
There is also no Zone.Identifier stream on the wrapper:
Get-Item "C:\Users\a*****\.codex\tmp\arg0\codex-arg0vPR7Mj\apply_patch.bat" -Stream *
Output only shows:
Stream: :$DATA
So the .bat itself does not seem to be blocked.
The failing executable appears to be the WindowsApps-packaged codex.exe referenced inside the wrapper.
Running the packaged WindowsApps codex.exe directly fails:
& "C:\Program Files\WindowsApps\OpenAI.Codex_26.616.6631.0_x64__2p2nqsd0c76g0\app\resources\codex.exe" --version
Output:
Program 'codex.exe' failed to run: Access is denied.
CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
FullyQualifiedErrorId : NativeCommandFailed
But the local cached CLI binary runs successfully:
& "C:\Users\a*****\AppData\Local\OpenAI\Codex\bin\8e55c2dd143b6354\codex.exe" --version
Output:
codex-cli 0.142.0-alpha.6
What I already tried
I checked and/or cleared the usual local causes:
- No ~/.codex/.env file exists
- No proxy env vars from
set | findstr /I proxy - Cleared ~/.codex/.sandbox
- Cleared ~/.codex/.sandbox-bin
- Cleared ~/.codex/.sandbox-secrets
- Checked Windows Defender Protection History; no recent blocks
- The generated apply_patch.bat has correct ACLs
- The generated apply_patch.bat has no Zone.Identifier stream
The issue remains.
Expected behavior
The generated apply_patch.bat should call an executable path that is accessible from the current sandbox/session/user context.
For example, it could use the local cached CLI path already present in config / environment:
C:\Users\a******\AppData\Local\OpenAI\Codex\bin\8e55c2dd143b6354\codex.exe
instead of the protected WindowsApps package path:
C:\Program Files\WindowsApps\OpenAI.Codex_26.616.6631.0_x64__2p2nqsd0c76g0\app\resources\codex.exe
Actual behavior
The generated apply_patch.bat points to the WindowsApps packaged codex.exe, which fails with Access is denied, causing apply_patch to fail.
Possible root cause
The apply_patch.bat wrapper generation may be using the packaged app resource path instead of the accessible local cached CODEX_CLI_PATH.
This seems related to Windows packaged app / WindowsApps execution restrictions. The packaged binary exists but cannot be launched directly from the user context, while the local cached CLI binary works.
Possible fix
When generating apply_patch.bat on Windows Desktop, prefer the accessible local cached Codex CLI path, such as CODEX_CLI_PATH, instead of the protected WindowsApps package path.
Temporary manual workaround that appears logically correct:
@echo off
"C:\Users\a*******\AppData\Local\OpenAI\Codex\bin\8e55c2dd143b6354\codex.exe" --codex-run-as-apply-patch %*
instead of:
@echo off
"C:\Program Files\WindowsApps\OpenAI.Codex_26.616.6631.0_x64__2p2nqsd0c76g0\app\resources\codex.exe" --codex-run-as-apply-patch %*
However, this is only a temporary workaround because Codex regenerates these wrappers under ~\.codex\tmp\arg0\codex-arg0....
Possible trigger / correlation:
I also noticed this started around the time Windows updated/installed “Windows App Runtime Main.2” on my machine. I am not claiming that this is definitely the root cause, but it may have changed or exposed packaged app / WindowsApps execution behavior.
However, the direct evidence is that the generated apply_patch.bat points to the WindowsApps-packaged codex.exe, and that executable cannot be launched directly from PowerShell (Access is denied), while the local cached Codex CLI path runs successfully.
What steps can reproduce the bug?
All you have to do is ask Codex to edit an existing file
What is the expected behavior?
_No response_
Additional information
Possible fix:
The issue may be in the Windows apply_patch.bat wrapper generator. It currently writes the protected WindowsApps codex.exe path into the wrapper, but that executable cannot be launched directly and returns Access is denied.
Using the local cached CLI path from CODEX_CLI_PATH instead may fix it, since that binary runs successfully on the same machine.
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Severity: Critical / Urgent
This is not a degraded editing experience: it is a complete blocker. The workspace is writable and repository inspection works, but Codex cannot execute its required
apply_patchpath. Any task that must edit source files stops at the patch step, so normal coding work cannot proceed until the WindowsApps patch-executor regression is fixed.Reproduced on a newer Codex Desktop build; this regression is still present.
Environment
26200.8655, x64OpenAI.Codex_26.707.9981.0_x64__2p2nqsd0c76g0codex-cli 0.144.2workspace-writewith the repository inside the declared writable rootObserved behavior
Every real built-in
apply_patchwrite hung with no stdout/stderr, including:After terminating the hung calls,
git statusconfirmed that no partial files or modifications were left behind.The generated launcher resolves to a temporary wrapper under
%USERPROFILE%\.codex\tmp\arg0\...\apply_patch.batcontaining:Running this wrapper from an elevated PowerShell context fails with
Access is denied, before patch parsing or workspace file access.Control comparison:
%LOCALAPPDATA%\OpenAI\Codex\bin\3135b80b111fd431\codex.exe --versionsucceeds and reportscodex-cli 0.144.2.--codex-run-as-apply-patchmode with the patch supplied as one UTF-8 argv value successfully applies the same patch in the same workspace.Additional observation: ordinary sandboxed shell calls such as
Get-Locationalso hung in the affected task context, while approved elevated shell calls worked. Restarting/reusing the same task did not clear the bad execution context.Impact
This blocks the required safe editing path. Repository rules explicitly forbid falling back to
Set-Content, Base64 writes, whole-file overwrite scripts, or similar direct-write workarounds, so coding tasks stop at the edit step.Expected fix
When Codex Desktop generates
apply_patch.bat, it should either:CODEX_CLI_PATH, orThe tool should also surface the underlying launch/sandbox error instead of hanging indefinitely with empty output.
No project source, production identifiers, or user-specific paths are included in this report.
Additional reproduction: ChatGPT Windows App 1.2026.190.0 / Codex CLI 0.145.0
Reproduced on 2026-07-26 with the ChatGPT Windows App package version 1.2026.190.0 and Codex CLI 0.145.0.
The standalone npm/Scoop CLI works normally. The failure is specific to the Windows App generated arg0 wrapper: it targets the packaged codex.exe under C:\Program Files\WindowsApps\..., and the command-runner context cannot execute that target because of the WindowsApps ACL. The workspace itself is writable and is not the primary cause.
As a control, replacing the generated wrapper target with the user-installed native CLI executable makes apply_patch work. This confirms that the issue is the packaged executable launch/ACL path, not patch syntax or the CLI implementation.
The workaround is not durable: the App creates new random %USERPROFILE%\.codex\tmp\arg0\codex-arg0* directories for new sessions, so the generated wrapper can regress after an App restart or when a new Codex process is created. Users should not need to install a second CLI, modify WindowsApps ACLs, or run a repair script.
Expected fix: have the Windows App generate apply_patch wrappers that invoke an accessible per-user/cached CLI, or launch the packaged backend through an appropriate broker/token context. The App should own this setup and preserve it across restarts and updates.