claude-code - 💡(How to fix) Fix [Bug] Edit tool fails on Windows with CRLF line endings: Read output mismatches file content [3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54876Fetched 2026-05-01 05:52:06
View on GitHub
Comments
3
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
commented ×3labeled ×3

Error Message

tool_use_error: String to replace not found in file. String: query.setOrderBy(null); try (Jedis jedis = jedisManager.getJedis(RedisConstants.CACHE_DB_INDEX)) { ... (Note: Read returned LF line endings, but file has CRLF)

Code Example

tool_use_error: String to replace not found in file.
  String: query.setOrderBy(null);
  try (Jedis jedis = jedisManager.getJedis(RedisConstants.CACHE_DB_INDEX)) {
  ...
  (Note: Read returned LF line endings, but file has CRLF)
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

On Windows, the Edit tool fails to match old_string when editing files with CRLF line endings. The Read tool returns content normalized to LF (\n), but the Edit tool tries to match against the original file content with CRLF (\r\n), causing a mismatch even when the visible text is identical.

What Should Happen?

  1. Consistent line ending handling: Read and Edit should use the same line ending format (preserve CRLF on Windows, or normalize both).
  2. Block-level replacement: Support replacing entire code blocks/methods without fragile multi-line string matching (similar to Trae's show_diff).

Error Messages/Logs

tool_use_error: String to replace not found in file.
  String: query.setOrderBy(null);
  try (Jedis jedis = jedisManager.getJedis(RedisConstants.CACHE_DB_INDEX)) {
  ...
  (Note: Read returned LF line endings, but file has CRLF)

Steps to Reproduce

  1. Open a file with CRLF line endings on Windows.
  2. Use Read tool to get a multi-line code block.
  3. Use the returned content as old_string in the Edit tool.
  4. Error: String to replace not found in file.

Claude Model

Other

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.119

Platform

Other

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

No response

extent analysis

TL;DR

The Edit tool fails to match old_string due to inconsistent line ending handling between Read and Edit tools on Windows.

Guidance

  • Verify that the issue is indeed caused by the difference in line endings by checking the output of the Read tool and the original file content.
  • Consider normalizing line endings to a consistent format (e.g., LF) before passing the content to the Edit tool.
  • To mitigate the issue, you can try replacing CRLF with LF in the old_string before using it in the Edit tool.
  • Investigate the possibility of implementing block-level replacement to avoid fragile multi-line string matching.

Example

old_string = old_string.replace('\r\n', '\n')  # Normalize line endings to LF

Notes

The provided information suggests that the issue is specific to Windows and CRLF line endings. The solution may need to be adapted for other platforms or line ending formats.

Recommendation

Apply workaround: Normalize line endings to a consistent format before using the Edit tool, as this is a more feasible solution given the current information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [Bug] Edit tool fails on Windows with CRLF line endings: Read output mismatches file content [3 comments, 2 participants]