[BUG] Built-in Edit tool silently converts line endings (CRLF → LF) in unrelated lines
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Title: Built-in Edit tool silently converts line endings (CRLF → LF) in unrelated lines
Summary:
When Claude Code's built-in Edit tool is used to insert or modify a portion of a source file, it silently converts line endings from CRLF to LF in lines that are outside the intended edit region and whose content was not changed at all.
What happened:
- The user instructed Claude Code to insert a new code block into a source file that uses mixed CRLF/LF line endings.
- Claude Code used the built-in
Edittool to perform the insertion. - After the edit,
git diffrevealed that dozens of lines outside the inserted block showed as changed — even though their text content was identical to the original. - The sole difference in those lines was that their line endings had been converted from CRLF to LF.
Expected behavior:
The Edit tool should preserve the original line endings of all lines it does not explicitly modify. Lines outside the edit region must not be altered in any way, including line endings.
Actual behavior:
The Edit tool converted CRLF line endings to LF in numerous lines that were not part of the intended edit, resulting in unintended and invisible changes scattered throughout the file.
Why this is a serious problem:
Line ending changes are invisible in most editors and tools, making them particularly dangerous. Specifically:
- They are silent and invisible. Unlike content changes, line ending differences cannot be seen by reading the source code. They only become apparent when using tools such as
git diffor a hex editor. This means the user has no way to notice the damage until they inspect the diff carefully. - They corrupt version history. When committed, these unintended changes appear in
git diffandgit blameas modifications to dozens of lines, permanently polluting the repository's history with noise that obscures the actual intent of the commit. - They violate the user's explicit instructions. The user had specifically instructed Claude Code never to change line endings without being told to do so — precisely because this file uses intentional mixed CRLF/LF line endings. Silently overriding that instruction is a violation of user intent.
- They require costly remediation. Because the changes are scattered invisibly across the file, restoring the original line endings required identifying each affected line from the
git diffoutput and running a separate byte-level fix — work that would not have been necessary had theEdittool preserved the original line endings. - They can cause downstream issues. Tools, compilers, and scripts that are sensitive to line endings may behave differently after such a change, introducing hard-to-diagnose bugs.
Additional context:
The user consistently asks Claude Code for confirmation before any write or overwrite operation. Nevertheless, the line ending changes were made silently with no warning and no opportunity to intervene.
Impact:
Silent, unintended changes to line endings polluted the git diff output, made code review harder, required a separate remediation step, and — in this session — ultimately led to a chain of events that resulted in a further serious incident (uncommitted work being destroyed by git checkout).
What Should Happen?
Expected behavior:
The Edit tool should preserve the original line endings of all lines it does not explicitly modify. Lines outside the edit region must not be altered in any way, including line endings.
Error Messages/Logs
Steps to Reproduce
N/A
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.1.252
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Other
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗