[BUG] Edit Tool Cannot Handle Files with Tabs

Resolved 💬 2 comments Opened Oct 8, 2025 by koshak01 Closed Oct 8, 2025

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?

  1. Result: String to replace not found in file error
  2. Convert tabs to spaces in the file manually, then the same Edit call succeeds

Expected Behavior:

One of these solutions:

Option 1: Edit tool should normalize whitespace (treat tabs and spaces as equivalent when matching)

Option 2: Read tool should explicitly show tabs vs spaces (like cat -A does)

Option 3: Provide a way to query file's whitespace style before editing

Actual Behavior:

  • Read tool displays tabs and spaces identically
  • Edit tool requires exact byte-for-byte match including whitespace
  • No way to determine if file uses tabs or spaces
  • User must guess or use bash commands to check

Impact:

  • High - Edit tool is unusable on tab-indented files without manual conversion
  • Many codebases use tabs (Python legacy code, Makefiles, Go, etc.)
  • Forces unnecessary whitespace changes just to make edits

Workaround:

Currently must either:

  1. Convert entire file to spaces temporarily
  2. Use bash sed/awk commands instead of Edit tool
  3. Manually edit in IDE

Additional Context:

The error message doesn't mention whitespace mismatch, making it hard to diagnose.

What Should Happen?

The Edit tool fails to match strings in files that use tabs for indentation, even when the content is identical.

Error Messages/Logs

Steps to Reproduce

  1. Create a Python file with tab indentation:

# File uses tabs (\t) for indentation
def example():
if True:
return "test"

  1. Use Read tool to view the file - it shows the content but doesn't indicate tabs vs spaces
  2. Try to use Edit tool with the exact visible content:

<invoke name="Edit">
<parameter name="old_string">def example():
if True:
return "test"</parameter>
<parameter name="new_string">def example():
if True:
return "modified"</parameter>
</invoke>

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗