# Windows `apply_patch` bug report

Resolved 💬 2 comments Opened Mar 18, 2026 by huyonger Closed Mar 18, 2026

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?

  1. Open Codex CLI on Windows in PowerShell.
  2. Create a multiline patch string:

```powershell
$patch = @'
* Begin Patch
* End Patch
'@

  1. 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?

``markdown
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_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗