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

Feature Request: Restore 'backup before delete' safety behavior for destructive file operations

Open kiki830621 opened this issue 1 year ago • 1 comments

Summary

During folder reorganization tasks, Claude Code deletes files it deems "unused" rather than moving them to an archive folder. This results in permanent data loss when files have purposes Claude doesn't recognize.

The Core Problem

When asked to "reorganize" or "clean up" a folder structure, Claude Code:

  1. Identifies files/folders that don't fit the new structure
  2. Directly deletes them instead of preserving them
  3. Cannot know the purpose of all files, especially those deeply nested or with non-obvious naming

The issue is not about backup strategies—it's about the default behavior of deleting unknown files.

Real-World Incident

User asked Claude to reorganize a teaching resources folder. Claude:

  • Created a new organized structure ✓
  • Moved files that fit the new structure ✓
  • Deleted files/folders it couldn't categorize ✗

Result: Years of accumulated resources were deleted. User had to restore from Dropbox version history.

Current Behavior vs Expected Behavior

Scenario Current Behavior Expected Behavior
File doesn't fit new structure rm -rf file mv file 99_archive/
Folder seems unused rm -rf folder mv folder 99_archive/
Unknown purpose Delete it Preserve it, ask user later

Proposed Solution

"Move to archive" should replace "delete" for reorganization tasks:

# Current (dangerous):
rm -rf old_folder  # Gone forever

# Proposed (safe):
mv old_folder 99_archive/old_folder_20241202  # Preserved, no extra disk space

Why mv to archive instead of cp backup?

  • mv within the same filesystem doesn't increase disk usage
  • No "disk space explosion" concern
  • Files are preserved but out of the way
  • User can review archive later and decide what to truly delete

Key Principle

Claude should never delete files whose purpose it doesn't fully understand.

If Claude cannot confidently explain why a file should be deleted, it should be moved to archive instead.

Trade-off Consideration

I understand Claude Code is an agentic tool where excessive confirmation reduces efficiency. This proposal doesn't require confirmation for every operation—it simply changes the default behavior from "delete unknown" to "archive unknown."

The user can:

  1. Review the archive folder after reorganization
  2. Decide what to permanently delete
  3. Or configure Claude to auto-delete archive after N days

Scope

This applies specifically to:

  • Folder reorganization tasks
  • "Clean up" operations
  • Structure migrations

Normal file operations (user explicitly asks to delete something) should work as before.


Relationship to Existing Issues

This issue is not a duplicate of the related issues flagged:

Issue Focus How This Differs
#10077 Bug: rm -rf deleted entire home directory That's a catastrophic bug. This is about normal reorganization behavior where deletion happens intentionally but unsafely.
#2498 Bug: Deleted based on superficial pattern matching Similar root cause, but this proposes a specific solution (archive-first) rather than just reporting the problem.
#6001 Feature: General Undo/Checkpoint system That's a heavyweight solution requiring new infrastructure. This proposes a lightweight behavioral change: mv instead of rm.

This proposal is complementary: Even with checkpoints (#6001), the default behavior during reorganization should still be "archive unknown" rather than "delete unknown."


Implementation Details

Archive Folder Naming Convention

99_archive/
├── old_folder_20241202_143052/    # timestamp to avoid conflicts
├── unused_file_20241202_143055.txt
└── ...

Handling Naming Conflicts

# If archive target already exists, append incrementing suffix
99_archive/old_folder_20241202/      # first
99_archive/old_folder_20241202_1/    # conflict → append _1
99_archive/old_folder_20241202_2/    # still conflict → append _2

Edge Cases

  • Cross-filesystem moves: Fall back to cp + rm with user notification
  • Archive folder doesn't exist: Create it automatically
  • Archive getting too large: Warn user, suggest review

Thank you for considering this feedback.

kiki830621 avatar Dec 02 '25 04:12 kiki830621

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/10077
  2. https://github.com/anthropics/claude-code/issues/2498
  3. https://github.com/anthropics/claude-code/issues/6001

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 02 '25 04:12 github-actions[bot]