apply_patch: preserve existing line endings or support CRLF/LF selection

Open 💬 1 comment Opened Jul 28, 2026 by OxfordGrid

What variant of Codex are you using?

Codex App on native Windows

What feature would you like to see?

Summary

When Codex uses the built-in apply_patch tool to modify an existing CRLF file on native Windows, newly inserted lines are written with LF endings while untouched lines retain CRLF. The resulting file has mixed line endings.

Requested behavior

  • Preserve the existing file's dominant line-ending style by default.
  • Optionally support an explicit preserve, crlf, or lf setting.
  • For new files, respect repository configuration such as .gitattributes or .editorconfig where possible.

Why this matters

Mixed endings cause Git warnings and Visual Studio normalization prompts. Agents then need a separate whole-file normalization rewrite after every focused patch. Besides being inefficient, that extra rewrite increases the risk of noisy diffs.

Reproduction

  1. On native Windows, create or open a source file that consistently uses CRLF.
  2. Ask Codex to make a focused partial edit using its built-in apply_patch tool.
  3. Inspect the resulting file at the byte level.
  4. The inserted lines use LF while the pre-existing lines remain CRLF.

Expected behavior

A focused patch should not change or mix the target file's established line endings.

Additional information

Observed repeatedly in a C# repository whose documented convention is CRLF. The current workaround is to normalize every touched file after apply_patch, which requires a second write unrelated to the logical code change.

View original on GitHub ↗

1 Comment

FranChauntry · 17 days ago

I have this issue all the time with LLMs on Windows.