claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] claude is reading certain tags in files wrong (<Name> being read as <n>) breaking its edits

Open inigohidalgo opened this issue 9 months ago • 5 comments

Environment

  • Platform (select one):
    • [X] Anthropic API
  • Claude CLI version: 0.2.45 (Claude Code)
  • Operating System:macos
  • Terminal: VSCode terminal and iTerm2, behavior happens in both

Bug Description

Claude is running into issues editing files that contain a <Name>{name}</Name> tag. When reading those files it seems to be replacing the text with <n>{name}</n>.

It gets stuck trying to change that back, trying in many different ways, grep, sed, etc. And wastes time, credits and context.

Logs


  Now let's update the Header component to implement the collapsible contact section for mobile view:

⏺ Update(file_path: //src/components/Header.tsx)…
  ⎿  String to replace not found in file.

⏺ I need to fix the code in line 88 where there's a typo in the component name. Let's try again:

⏺ Read(file_path: "/src/components/Header.tsx", limit: 10, offset:…
      80)
  ⎿  /**
      * Header component that displays the CV owner's name, title, and contact details
      * Responsive design ensures proper display on both mobile and desktop
      */
     const Header: React.FC<HeaderProps> = ({ name, title, contact }) => {
       return (
         <HeaderContainer>
           <HeaderContent>
             <Name>{name}</Name>
             <Title>{title}</Title>

⏺ I see the issue - there's an HTML tag <n> instead of the <Name> component. Let me fix that and redo the edit:

⏺ Update(file_path: /src/components/Header.tsx)…
  ⎿  String to replace not found in file.

⏺ Let me try another approach - let's read the exact file content and then make the updates:

⏺ Bash(cat -n /src/components/Header.tsx)…
  ⎿  No (tell Claude what to do differently)

Line 88 at the time was <Name>{name}</Name>

⏺ Read(file_path: "/docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md", offset: 165, …
      limit: 20)
  ⎿      text-align: left;
         // Remove the custom font-size override
         max-width: 40%;
         word-break: break-word;
         hyphens: auto;
       }
     `;
     ```

     4. Check for any other occurrences of custom font sizes in the file and replace them with the appropriate typography system styles
     5. Fix any issues with the HTML elements in the component to ensure semantic correctness, particularly checking the component render method to confirm h1 tags are used
     correctly
     6. Look for the line `<n>{name}</n>` near line 120 and fix it to `<Name>{name}</Name>` (this appears to be a typo in the current code)
     7. Save the file

     8. **Commit these changes with the message**:
     ```
     fix(header): improve header text sizing for mobile view

     - Update Name component to use semantic h1 style with improved mobile sizing
     - Remove custom font-size overrides in favor of typography system values

⏺ Update(file_path: /docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md)…
  ⎿  String to replace not found in file.

⏺ This is strange. Let me try to view the actual file contents:

  Bash(grep -n "<n>" /docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md)…

inigohidalgo avatar Mar 16 '25 01:03 inigohidalgo

Some additional info about what claude thinks the issue is:


  Now let's update the Header component to implement the collapsible contact section for mobile view:

⏺ Update(file_path: //src/components/Header.tsx)…
  ⎿  String to replace not found in file.

⏺ I need to fix the code in line 88 where there's a typo in the component name. Let's try again:

⏺ Read(file_path: "/src/components/Header.tsx", limit: 10, offset:…
      80)
  ⎿  /**
      * Header component that displays the CV owner's name, title, and contact details
      * Responsive design ensures proper display on both mobile and desktop
      */
     const Header: React.FC<HeaderProps> = ({ name, title, contact }) => {
       return (
         <HeaderContainer>
           <HeaderContent>
             <Name>{name}</Name>
             <Title>{title}</Title>

⏺ I see the issue - there's an HTML tag <n> instead of the <Name> component. Let me fix that and redo the edit:

⏺ Update(file_path: /src/components/Header.tsx)…
  ⎿  String to replace not found in file.

⏺ Let me try another approach - let's read the exact file content and then make the updates:

⏺ Bash(cat -n /src/components/Header.tsx)…
  ⎿  No (tell Claude what to do differently)

Line 88 at the time was <Name>{name}</Name>

inigohidalgo avatar Mar 16 '25 17:03 inigohidalgo

Even more context, There is clearly something strange going on with replacing text when reading files. There has never been a <n>{name}</n> in any of the files Claude thought it was in.

This is extremely blocking for my current workflow. It gets hung up super frequently, and has cost me a fair amount of credits when it gets stuck in a loop.

⏺ Read(file_path: "/docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md", offset: 165, …
      limit: 20)
  ⎿      text-align: left;
         // Remove the custom font-size override
         max-width: 40%;
         word-break: break-word;
         hyphens: auto;
       }
     `;
     ```

     4. Check for any other occurrences of custom font sizes in the file and replace them with the appropriate typography system styles
     5. Fix any issues with the HTML elements in the component to ensure semantic correctness, particularly checking the component render method to confirm h1 tags are used
     correctly
     6. Look for the line `<n>{name}</n>` near line 120 and fix it to `<Name>{name}</Name>` (this appears to be a typo in the current code)
     7. Save the file

     8. **Commit these changes with the message**:
     ```
     fix(header): improve header text sizing for mobile view

     - Update Name component to use semantic h1 style with improved mobile sizing
     - Remove custom font-size overrides in favor of typography system values

⏺ Update(file_path: /docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md)…
  ⎿  String to replace not found in file.

⏺ This is strange. Let me try to view the actual file contents:

  Bash(grep -n "<n>" /docs/planning/style-overhaul/250316-text-styling-consistency-implementation-steps.md)…

inigohidalgo avatar Mar 16 '25 19:03 inigohidalgo

+1 I opened another one with the same. And it looped when doing this.

GurgehMorat avatar Mar 18 '25 01:03 GurgehMorat

Noting in this issue that https://github.com/DCsunset/taskwarrior-webui contains lots of files that do this for me too.

hakusaro avatar Mar 23 '25 23:03 hakusaro

🔬 CRITICAL: Systemic XML Display Bug - Deeper Than Read Tool After extensive testing, this is not just a read tool issue - it's a fundamental XML rendering bug in Claude Code's entire output pipeline. Evidence: Bug Affects ALL XML Display Test 1: Read Tool (Original Bug)

Claude Code read tool shows: content Actual file contains: <Name>content</Name>

Test 2: Bash Commands (New Discovery)

Asked Claude Code to use bash instead of read tool Bash commands executed: tail -3 filename.xml Bash output correctly showed: <Name>sky_asclause</Name> Claude Code displayed it as: sky_asclause

Root Cause Analysis The corruption happens after files are read correctly:

✅ File system access works fine ✅ Bash commands read XML correctly ❌ Claude Code corrupts XML when displaying results ❌ HTML entity processing applied incorrectly in output pipeline

Technical Evidence File integrity confirmed via multiple methods: bash$ file sample.xml XML 1.0 document text, ASCII text

$ hexdump shows: 3c 4e 61 6d 65 3e = <Name> $ bash commands show: <Name>content</Name> But Claude Code displays: content Systemic Impact

❌ Read tool corrupted ❌ Bash command output corrupted ❌ Any XML content display corrupted ❌ Line counting errors (122 vs 123 lines) ❌ Edit operations fail due to mismatched content

Workaround Status None effective - even bypassing read tool with bash commands doesn't work because the corruption occurs in Claude Code's display layer. Technical Details

Platform: macOS Version: 0.2.48 Scope: All XML/HTML content display Pattern: <Name> → (HTML entity encoding issue)

This is a critical bug affecting Claude Code's entire XML handling pipeline, not just the read tool. Any XML-based development workflow is compromised.

geoferrus avatar May 22 '25 13:05 geoferrus