[BUG] Write and Edit silently strip trailing whitespace; a whitespace-only new_string turns a replacement into a deletion
Environment: Claude Code desktop app 2.26454.0 (agent claude-code_2-1-289), Windows 11.
What happens
The Write and Edit tools remove the whitespace at the end of every line of the text they are given, in any file that does not end in .md. Markdown files keep it. The tool reports success either way.
For most edits that is harmless tidying. It is harmful when new_string is made only of whitespace: all of it is "trailing", so it becomes empty, and the replacement becomes a deletion.
Reproduction
A file case.txt holding a<TAB>b<TAB>c\n1<TAB>2<TAB>3\n (12 bytes). Edit with old_string = one tab, new_string = two spaces, replace_all: true.
- Reported: "All occurrences were successfully replaced."
- The file now holds
abc\n123\n(8 bytes). The tabs are gone and no space was written.
Further calls, each checked with od -c:
| Tool | File | Asked | Result |
|---|---|---|---|
| Edit | .txt | a<TAB>b to a b | written as asked (the control) |
| Edit, replace_all off | .txt | one tab to two spaces | tab deleted, nothing written |
| Edit | .txt | one space to two spaces | space deleted, nothing written |
| Write | .txt | content " " | empty file |
| Write | .txt | " z" | written as asked |
| Write | .txt | "z \ny\n" | "z\ny\n" |
| Write | .txt | "w<TAB>\nv\n" | "w\nv\n" |
| Write | .md | "z \ny\n" | written as asked |
| Edit | .md | one tab to two spaces | written as asked |
| Edit | .txt | k to "k " | refused: "No changes to make: old_string and new_string are exactly the same." |
The last row shows the strip happens before the tool compares the strings.
Expected
Either write the text as given, or say so when stripping changed it. At the least, refuse or warn when stripping empties a non-empty new_string, since the agent asked for a replacement and got a deletion under a success message.
Why it matters
The only signal is the file's bytes. An agent converting indentation (tabs to spaces) in a code file deletes it instead, and is told it succeeded.