[BUG] Claude trashed a file, spraying line numbers throughout it. This is the LLMs analysis of what went wrong with its edits.

Resolved 💬 3 comments Opened May 8, 2025 by walt93 Closed Jan 3, 2026

Environment

  • Platform (select one):
  • [√] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • Claude CLI version: 0.2.104 (Claude Code)
  • Operating System: macOS 15.3
  • Terminal: IntelJIdea

Bug Description

Claude made some edits, and the file got semi-trashed with line numbers inserted on every line for part of the file.

Steps to Reproduce

  1. Ask Claude to fix a bug
  2. Claude executed a series of edits using tools and Bash script commands
  3. Specifically, Claude attempted to use sed commands to make targeted changes

This is an example of what happened to the file.

684-        <div x-show="syncing" class="position-fixed top-0 end-0 p-3 bg-dark bg-opacity-75 text-light rounded-start d-flex align-items-center" style="z-index: 1050;">
685-            <div class="spinner-border spinner-border-sm me-2" role="status">

Expected Behavior

Claudes editing workflow not to trash files.

Actual Behavior

Claudes editing workflow trashed a file.

Additional Context

I asked ur bot for a root cause analysis of what just went down, and this is what came back:

------vvvv LLM output below vvvv-------
Root Cause Analysis

The file content was displayed to Claude with line number prefixes (like "684-") at the beginning of each line for reference. These prefixes were intended to be informational
metadata about the file's structure.

When Claude executed commands like:

  sed -i '' 's|<div class="alert alert-danger" x-show="statusData.last_error">|<div class="alert alert-danger" x-show="statusData.last_error" x-cloak>|g'
  /Users/walt/IdeaProjects/avideo-admin-tools/channelsync.php

The command executed against a file that already contained these line number prefixes, causing them to be permanently incorporated into the file content rather than being treated
as reference metadata.

A partial bash script that led to corruption:

  cat > /tmp/fix_script.sh << 'EOF'
  #!/bin/bash
  # Add x-cloak to the error message alert
  sed -i '' 's|<div class="alert alert-danger" x-show="statusData.last_error">|<div class="alert alert-danger" x-show="statusData.last_error" x-cloak>|g'
  /Users/walt/IdeaProjects/avideo-admin-tools/channelsync.php
  # Add x-cloak to the progress indicator  
  sed -i '' 's|<div class="mb-3" x-show="statusData.service_status === .running.">|<div class="mb-3" x-show="statusData.service_status === '\''running'\''" x-cloak>|g'
  /Users/walt/IdeaProjects/avideo-admin-tools/channelsync.php
  chmod +x /tmp/fix_script.sh
  EOF


```  Impact

  - Every line from 563 to the end of the file had a line number prefix like "684-" preceding the actual content
  - This caused PHP syntax errors, specifically: "PHP Parse error: syntax error, unexpected token 'foreach' in /var/www/html/conspyre.tv/management/channelsync.php on line 654"
  - Resulted in a blank white screen when accessing the page

  Resolution

  The file was reverted to the previous version using git.

  Recommendations for Prevention

  1. Ensure tools properly distinguish between line number displays and actual file content
  2. Use direct file editing APIs rather than shell commands for complex file manipulations
  3. Implement a validation step that checks PHP syntax after automated edits
  4. For critical file edits, implement staged changes with syntax verification before committing to the main file

View original on GitHub ↗

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