apply_patch always adds newline at end of file
Open 💬 7 comments Opened Dec 5, 2025 by paulozoom
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
codex-cli 0.64.0
What subscription do you have?
Plus
Which model were you using?
gpt-5.1-high
What platform is your computer?
Darwin 25.1.0 arm64 arm
What issue are you seeing?
apply_patch always adds \n at the end of file, even if the file didn’t originally have it.
This is usually no bother, but can be annoying, for example in Xcode String Catalogue files (.xcstrings) which do not typically have one — so when Codex makes to it (e.g. to add translations), it always adds newline, resulting in unnecessary edits.
The new line is stripped if the file is opened in Xcode's string catalogue editor (resulting in an edit/diff), only to Codex to add it back if it ever edits the file, and so on, the cycle repeating.
What steps can reproduce the bug?
- Get yourself a .xcstrings file from Xcode (or otherwise a file without a newline at the end).
- Ask Codex to make any sort of edit on the file.
- Diff the edit.
What is the expected behavior?
Don’t add newline at EOF if it didn’t have one.
Additional information
When asking Codex to not do so, it replied:
- I attempted to remove the trailing newline from Sketch/Resources/Localizable.xcstrings using the only file-editing mechanism I’m allowed (apply_patch),
including its special *** End of File marker.
- However, as you saw in the hex dump, the file still ends with 0a (\n), i.e. the last byte remains a newline. With the tools and constraints I have, I can’t
reliably produce a .xcstrings file that does not end in a newline; apply_patch always reintroduces it.
7 Comments
Thanks for the bug report.
Have you confirmed whether it's the
apply_patchtool that's adding the newline? Or is it the model itself that's tellingapply_patchto add the newline?Please use the
/feedbacktool to upload a session where you are seeing this, and post the thread ID here.Closing because no response.
@etraut-openai It happened again, so I used the feedback tool as requested, here’s the ID: 019b35c6-2fa7-7521-a99c-6020993f4104
OK, thanks. Reopening the issue.
Hi @etraut-openai, can you confirm it's intended behavior or a bug.
It's recorded in the test: https://github.com/openai/codex/blob/246f50655111fda3d4fa4f2032285d03464fe249/codex-rs/apply-patch/tests/suite/tool.rs#L223
And the rootcause is here: the last line is always
\nhttps://github.com/openai/codex/blob/246f50655111fda3d4fa4f2032285d03464fe249/codex-rs/apply-patch/src/lib.rs#L362-L367If it's not intended I can file a pull request.
In case this is a "intentional behavior", I made a cli tool to fix this issue: https://github.com/qazxcdswe123/codex-no-newline
can confirm seeing this too