Skip to content

[BUG] Edit Tool Cannot Handle Files with Tabs #9163

@koshak01

Description

@koshak01

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?

  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:
def example(): if True: return "test" def example(): if True: return "modified"

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions