codex - 💡(How to fix) Fix apply_patch inserts LF into CRLF files on Windows, causing VS line-ending warnings and unreliable undo

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fix / Workaround

On Windows, when Codex edits an existing CRLF code file, apply_patch appears to insert or replace lines using LF-only line endings. This creates mixed line endings in the same file.

  1. Use Codex App on Windows with a repository containing CRLF code files.
  2. Open a Visual Studio project file, for example a .vb file.
  3. Ask Codex to make a small edit using apply_patch, such as adding a test comment.
  4. Open or save the edited file in Visual Studio.
  5. Visual Studio reports inconsistent line endings.
  6. Inspect the file line endings. The file contains mixed CRLF and LF lines.
  7. Ask Codex to normalize the file back to CRLF, or manually normalize it.
  8. Try using the Codex app “undo/revert changes” button.
  9. The revert may fail and report that some files were skipped / could not be restored.

Observed Git config / file state:

  • git config core.autocrlf = true
  • Example file initially shows as CRLF in working tree: i/lf w/crlf attr/text=auto
  • After apply_patch edits, inserted lines can become LF-only, causing mixed line endings.
RAW_BUFFERClick to expand / collapse

What version of the Codex App are you using (From “About Codex” dialog)?

26.521.10419

What subscription do you have?

ChatGPT Plus

What platform is your computer?

Windows 11 25H2 26200.6899

What issue are you seeing?

On Windows, when Codex edits an existing CRLF code file, apply_patch appears to insert or replace lines using LF-only line endings. This creates mixed line endings in the same file.

Visual Studio then shows an “Inconsistent Line Endings” warning.

If the assistant subsequently normalizes the file back to CRLF, the Codex app’s built-in undo/revert feature can fail. The revert dialog says some files could not be restored / were skipped.

This makes Codex edits difficult to undo reliably in Windows/Visual Studio projects.

What steps can reproduce the bug?

Feedback ID: 019e7251-6bbb-7340-9ac7-801c6d1c5880 Feedback ID / session id: 019e7251-6bbb-7340-9ac7-801c6d1c5880

Reproduction steps:

  1. Use Codex App on Windows with a repository containing CRLF code files.
  2. Open a Visual Studio project file, for example a .vb file.
  3. Ask Codex to make a small edit using apply_patch, such as adding a test comment.
  4. Open or save the edited file in Visual Studio.
  5. Visual Studio reports inconsistent line endings.
  6. Inspect the file line endings. The file contains mixed CRLF and LF lines.
  7. Ask Codex to normalize the file back to CRLF, or manually normalize it.
  8. Try using the Codex app “undo/revert changes” button.
  9. The revert may fail and report that some files were skipped / could not be restored.

Observed Git config / file state:

  • git config core.autocrlf = true
  • Example file initially shows as CRLF in working tree: i/lf w/crlf attr/text=auto
  • After apply_patch edits, inserted lines can become LF-only, causing mixed line endings.

What is the expected behavior?

apply_patch should preserve the existing line ending style of the edited file.

If a file uses CRLF, inserted or replaced lines should also use CRLF. This would avoid Visual Studio line-ending warnings and should keep Codex app undo/revert reliable.

Additional information

This likely affects Windows projects broadly, not only VB.NET.

The issue was observed in a Visual Studio / VB.NET project, but the root problem appears to be line-ending preservation during apply_patch writes.

The project path also contains non-ASCII / Chinese directory names, but the strongest evidence points to LF-only lines being inserted into existing CRLF files.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix apply_patch inserts LF into CRLF files on Windows, causing VS line-ending warnings and unreliable undo