claude-code - 💡(How to fix) Fix CRITICAL: Claude modifies/deletes files without making backups despite explicit global rule [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48313Fetched 2026-04-16 07:03:19
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1
RAW_BUFFERClick to expand / collapse

Severity: CRITICAL — Data Loss

What happened

Claude Code was given an explicit global CLAUDE.md rule: NEVER delete or modify files without making a backup first. Despite this rule being loaded in every session, Claude repeatedly modified production files (app.js, app.css) without creating backups, then could not restore them when asked.

Impact

  • Working, approved production code was modified without backups
  • When the user asked for the backup, none existed
  • Hours of debugging work (founder-approved changes) were permanently lost
  • User had to re-debug from scratch

Expected behavior

Before modifying ANY file that already exists, Claude should:

  1. Read the file
  2. Create a timestamped backup (e.g., file.bak_YYYYMMDD_HHMMSS)
  3. Then make the modification

This should be enforced especially when CLAUDE.md contains an explicit rule about it.

Requested resolution

  • Refund of session time/credits spent re-debugging lost work
  • Bonus API credits for the operational disruption caused
  • Fix: Claude should treat CLAUDE.md backup rules as hard constraints, not suggestions

Session context

This occurred during a production map application development session. The modifications destroyed working code that had been reviewed and approved by the product founder.

extent analysis

TL;DR

Implement a backup mechanism that creates a timestamped copy of existing files before modifying them, as specified in the CLAUDE.md rules.

Guidance

  • Review the CLAUDE.md loading process to ensure that the backup rules are properly parsed and enforced.
  • Modify the file modification logic to create a backup copy of the file before making any changes, using a timestamped filename (e.g., file.bak_YYYYMMDD_HHMMSS).
  • Consider adding a validation step to verify that a backup exists before allowing modifications to proceed.
  • Ensure that the backup mechanism is integrated with the existing file modification workflow to prevent data loss.

Example

function modifyFile(fileName, newContent) {
  const backupFileName = `${fileName}.bak_${getDateTimestamp()}`;
  fs.copyFile(fileName, backupFileName, (err) => {
    if (err) {
      console.error(`Error creating backup: ${err}`);
    } else {
      fs.writeFile(fileName, newContent, (err) => {
        if (err) {
          console.error(`Error writing file: ${err}`);
        }
      });
    }
  });
}

function getDateTimestamp() {
  const date = new Date();
  return `${date.getFullYear()}${padZero(date.getMonth() + 1)}${padZero(date.getDate())}_${padZero(date.getHours())}${padZero(date.getMinutes())}${padZero(date.getSeconds())}`;
}

function padZero(num) {
  return (num < 10 ? '0' : '') + num;
}

Notes

The provided example is a basic illustration of how the backup mechanism could be implemented. The actual implementation may vary depending on the specific requirements and constraints of the project.

Recommendation

Apply workaround: Implement the backup mechanism as described above to prevent data loss and ensure that CLAUDE.md rules are enforced. This will provide a reliable way to recover modified files in case of errors or unintended changes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Before modifying ANY file that already exists, Claude should:

  1. Read the file
  2. Create a timestamped backup (e.g., file.bak_YYYYMMDD_HHMMSS)
  3. Then make the modification

This should be enforced especially when CLAUDE.md contains an explicit rule about it.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING