When Codex proposes code changes, it can output them in two handy formats: a patch (diff) or a shell snippet that runs git apply. On Windows with MSYS2, the clipboard and character encodings can get in the way—especially if your system locale uses CP932 (Shift_JIS). Below are two simple one-liners you can run in MSYS2 to apply those changes safely.
Use this when you clicked “Copy patch” in Codex and your clipboard now contains a unified diff:
msys2$ powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | tr -d '\r' | git apply -v --3way -
# or
msys2$ win32yank -o --lf | git apply -v --3way -powershell.exe Get-Clipboardreads the text you copied from Codex.iconv -f CP932 -t UTF-8converts from Windows CP932 to UTF-8 so Git parses the diff correctly.tr -d '\r'strips Windows\r\nline endings to POSIX\n.git apply -vapplies the patch to your working tree and prints verbose output.
- Run it from the root of your Git repo.
- If you see path mismatches, add
-p0/-p1togit applyas needed. - For a dry run first:
git apply --check -v.
Use this when you clicked “Copy git apply” in Codex and your clipboard now contains a shell command that itself runs git apply:
msys2$ powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | tr -d '\r' | sh
# or
msys2$ win32yank -o --lf | sh- Reads the Codex-generated shell script from the clipboard.
- Converts CP932 → UTF-8 and normalizes line endings.
- Pipes the cleaned script to
sh, which executes it (usually invokinggit applywith the right flags).
- Inspect the clipboard content if you’re unsure:
powershell.exe Get-Clipboard | iconv -f CP932 -t UTF-8 | sed -n '1,60p' - If the snippet creates files or uses paths, run it at the repo root.
Windows often stores clipboard text in CP932 and uses CRLF line endings. Git and POSIX tools expect UTF-8 with LF. The iconv + tr steps remove encoding and newline pitfalls so git apply can do its job reliably.
- ✅ Copy from Codex (Copy patch or Copy git apply)
- ✅ In MSYS2, run the matching one-liner above
- ✅ Confirm with
git status - ✅ Commit the changes when satisfied
That’s it—you can smoothly apply Codex’s suggestions on Windows without wrestling with encodings or line endings.