[BUG] Data loss caused by Claude Code rewriting a file before extracting content

Resolved 💬 4 comments Opened Feb 27, 2026 by Ivanlh20 Closed Apr 20, 2026

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?

During a refactoring session, I asked Claude Code to split a large monolithic header file (~2856 lines) into separate focused files. The task involved:

Extracting classes from the monolith into new files
Replacing the monolith with a slim header
Moving ~2300 lines of private tabulated data to a detail implementation file
Claude rewrote the monolith before extracting the private tabulated data, permanently overwriting it. I had a backup and Claude acknowledged the mistake, but recovering the data manually from the backup took significant extra time.

What should have happened: Read and extract all content from a file before overwriting it.

Impact: Lost ~2300 lines of tabulated scientific data. Required manual recovery from backup. Significant time lost.

Suggestion: Before overwriting or replacing a large file, Claude should verify that all content that needs to be preserved has already been written to its new location. A simple check like "does the target file already contain the extracted content?" would prevent this class of mistake.

What Should Happen?

Read and extract all content from a file before overwriting it.

Error Messages/Logs

Steps to Reproduce

During a refactoring session, I asked Claude Code to split a large monolithic header file (~2856 lines) into separate focused files. The task involved:

Extracting classes from the monolith into new files
Replacing the monolith with a slim header
Moving ~2300 lines of private tabulated data to a detail implementation file
Claude rewrote the monolith before extracting the private tabulated data, permanently overwriting it. I had a backup and Claude acknowledged the mistake, but recovering the data manually from the backup took significant extra time.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.6

Platform

Other

Operating System

Ubuntu/Debian Linux

Terminal/Shell

VS Code integrated terminal

Additional Information

<img width="457" height="61" alt="Image" src="https://github.com/user-attachments/assets/59f375b8-b9d1-4970-97ad-87c35b13d416" />

View original on GitHub ↗

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