Skip to content

# Windows apply_patch bug report #15061

Closed as duplicate
Closed as duplicate

Description

@huyonger

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:

    $patch = @'
    *** Begin Patch
    *** End Patch
    '@
    
  3. 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

  1. added
    bug
    on Mar 18, 2026
  2. added
    CLI
    windows-os
    tool-calls
    on Mar 18, 2026
  3. removed
    CLI
    on Mar 18, 2026
  4. etraut-openai commented on Mar 18, 2026

    @etraut-openai
    Contributor

    This appears to be a duplicate of #15003

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

    bugtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions