Repository navigation
Description
What version of Codex CLI is running?
0.115.0
What subscription do you have?
GitHub Copilot
Which model were you using?
gpt-5.4 (via GitHub Copilot)
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 (PowerShell)
What issue are you seeing?
On Windows, apply_patch can fail when called from PowerShell with a multiline patch string, even when the patch itself is valid.
Typical errors I saw:
Invalid patch: The last line of the patch must be '*** End Patch'Error: --codex-run-as-apply-patch requires a UTF-8 PATCH argument.
From local investigation, the issue appears to be in the Windows helper layer rather than in patch parsing itself.
In my environment, the generated helper is a .bat wrapper that forwards arguments to codex.exe using %*. When I bypass that wrapper and call codex.exe --codex-run- as-apply-patch directly, the same patch succeeds.
What steps can reproduce the bug?
-
Open Codex CLI on Windows in PowerShell.
-
Create a multiline patch string:
$patch = @' *** Begin Patch *** End Patch '@
-
Run:
apply_patch $patch
This can fail with:
Invalid patch: The last line of the patch must be '*** End Patch'
I also saw cases that failed with:
Error: --codex-run-as-apply-patch requires a UTF-8 PATCH argument.
For comparison, this direct invocation succeeds in my environment:
$exe = "C:\Users\huyong\AppData\Local\nvm\v22.21.1\node_modules@openai\codex\node_modules@openai\codex-win32-x64\vendor\x86_64-pc-windows-msvc\codex\codex.exe"
$patch = @'
*** Begin Patch
*** Add File: test.txt
+hello
*** End Patch
'@
$patch = $patch.TrimEnd("r", "n")
& $exe --codex-run-as-apply-patch $patch
What is the expected behavior?
`apply_patch` should accept a valid multiline patch string from PowerShell and apply it successfully on Windows, without requiring users to bypass the generated helper
manually.
Additional information
Root-cause hypothesis: forwarding multiline patch text through `apply_patch.bat` using `%*` is fragile on Windows PowerShell and can corrupt argument boundaries or trailing
formatting.
A likely fix direction would be:
- use an `.exe` helper on Windows instead of a `.bat` wrapper
- dispatch by executable stem so `apply_patch.exe` still resolves to `apply_patch`
I am not submitting a PR because the repository only accepts external code contributions by invitation, but I am happy to provide more logs, reproduction details, or the
patch I tested locally.
### Additional information
_No response_
Activity
github-actions commentedon Mar 18, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
etraut-openai commentedon Mar 18, 2026
This appears to be a duplicate of #15003