[BUG] Edit tool strips trailing spaces in Markdown files

Status Fixed / completed
Maintainer reply ✓ Yes — ashwin-ant
Activity 8 comments · opened Nov 28, 2025 · closed Apr 18, 2026
💡 Likely answer: A maintainer (ashwin-ant, collaborator) responded on this thread — see the highlighted reply below.

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?

## Summary

The Edit tool removes trailing spaces from old_string and new_string parameters, which causes issues when
creating Markdown files that require line breaks.

## Problem

In Markdown, to create a line break without starting a new paragraph, you need to add two trailing spaces at the
end of a line:

```markdown
Last Updated: 2025-11-28
Version: v16
Author: John Doe

However, when using the Edit tool, these trailing spaces are stripped during parameter transmission:

"Line 1 \nLine 2 " → "Line 1\nLine 2" (spaces removed)

This results in Markdown that renders as a single continuous line instead of multiple lines.

Current Workaround

Users must use the Bash tool with sed command to add trailing spaces:

sed -i '3,6s/$/ /' file.md

What Should Happen?

Suggested Improvements

  1. Preserve trailing spaces: Modify the Edit tool to preserve trailing whitespace
  2. Markdown-aware mode: Add an option that automatically handles line break syntax
  3. Documentation: Document this limitation clearly

Impact

This affects anyone using Claude Code to create or edit Markdown documentation, which is a very common use case.

Error Messages/Logs

Steps to Reproduce

If you make the following with markdown, there are no tracing spaces

Last Updated: 2025-11-28
Version: v16
Author: John Doe

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.55

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

8 Comments

robertmclaws · 8 months ago

I'm running into this issue also and it's a massive problem when you are building documentation systems and having Claude write documentation.

robertmclaws · 8 months ago

I tried to look into this issue and submit a fix but the offending code is not in this repository.

HeoChangwon · 8 months ago

When you ask for a Markdown document of your coding work in Claud Code, it usually begins with the following type, but when you read the saved .md file, there are no two spaces at the end of the line, so it goes straight to one line.

-----------------

**Last Updated**: 2025-11-28
**Version**: v16
**Author**: John Doe

-----------------

If I had to make a problematic prompt,
"Please make a short description of Markdown in a Markdown document."

github-actions[bot] · 7 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

yusefmaali · 7 months ago

The issue is still in action.
I'd like to add that I write exact instructions in CLAUDE.md on how to fix the issue (es. after using the Edit tool in md file, check for missing trailing spaces, restore them not using the Edit tool but with sed, ecc...).
Sometimes this works automatically, sometimes I have to remember Claude that.
In both cases, there's a massive usage of wasted tokens just to fix stripped trailing spaces.

davidfstr · 6 months ago

Indeed I notice that the Edit tool strips trailing whitespace even if Claude Code tries to use a replacement string containing whitespace.

<details>
<summary>I ran an experiment with Claude to diagnose:</summary>

❯ Let's run an experiment. In src/crystal/tests/util/cli.py try to make the following replacement (with dots representing
spaces):

From:
``
....Returns the command (as a list of strings) to run Crystal on the command line.
....
....When running
``

To:
``
....Returns the command (as a list of strings) to run Crystal on the command line.
....
....Whenever running
``

⏺ Read 1 file (ctrl+o to expand)

⏺ Update(src/crystal/tests/util/cli.py)
⎿ Added 2 lines, removed 2 lines
33 def get_crystal_command() -> list[str]:
34 """
35 Returns the command (as a list of strings) to run Crystal on the command line.
36 -
37 - When running from a frozen macOS app, this returns the path to the Crystal binary.
36 +
37 + Whenever running from a frozen macOS app, this returns the path to the Crystal binary.
38 Otherwise, this returns ['python', '-m', 'crystal'] using the current interpreter.
39 """
40 python = sys.executable

⏺ The edit succeeded. Now let me verify what actually happened to the blank line:

⏺ Bash(git diff HEAD src/crystal/tests/util/cli.py | cat -v)
⎿ diff --git a/src/crystal/tests/util/cli.py b/src/crystal/tests/util/cli.py
index 29df7cec..635b0d3b 100644
--- a/src/crystal/tests/util/cli.py
… +12 lines (ctrl+o to expand)

⏺ The experiment confirms the issue: the Edit tool silently drops trailing spaces from blank lines. The original \n (4
spaces) became \n (empty). The tool accepted the edit without error even though my old_string specified an empty blank line
but the actual file had a 4-space blank line — it matched them as equivalent.

So the behavior is:

  • Matching (old_string): blank lines with or without trailing spaces match each other — the tool treats them as equivalent
  • Writing (new_string): blank lines are always written as empty (trailing spaces stripped)

This explains why in my earlier work the Edit tool appeared to "work" when reverting the method, but silently corrupted the
blank lines, requiring the Python script fallback to fix them.

</details>

ashwin-ant collaborator · 4 months ago

This was fixed in v2.1.88 — Edit and Write no longer strip trailing spaces in .md/.mdx files, preserving Markdown hard line breaks. If you're still seeing this in the latest version, please comment with your version and repro and we'll reopen.

github-actions[bot] · 4 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.