[FEATURE] Claude Code executed destructive bulk file rename without backup, causing
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
During a Claude Code session, I asked Claude to batch-rename files in a directory (move the
date from the end of filenames to the beginning). Claude generated a bash script using
BASH_REMATCH with a regex to extract and rearrange filename components. However,
BASH_REMATCH failed silently when processing filenames containing CJK (Chinese) characters,
causing both the name and date capture groups to be empty. This resulted in all .md files
being renamed to literally .md and all .xlsx files to .xlsx — each file overwriting the
previous one.
Proposed Solution
Title: Claude Code executed destructive bulk file rename without backup, causing
irrecoverable data loss of 36+ files
Body:
Summary
During a Claude Code session, I asked Claude to batch-rename files in a directory (move the
date from the end of filenames to the beginning). Claude generated a bash script using
BASH_REMATCH with a regex to extract and rearrange filename components. However,
BASH_REMATCH failed silently when processing filenames containing CJK (Chinese) characters,
causing both the name and date capture groups to be empty. This resulted in all .md files
being renamed to literally .md and all .xlsx files to .xlsx — each file overwriting the
previous one.
36+ documentation files were permanently destroyed. Only the last .md and last .xlsx to be
processed survived (as .md and .xlsx). Since mv does not use the trash, the files are
irrecoverable.
What happened
- I asked Claude to rename files in a directory: move the date suffix (e.g., _2026-01-07)
to the front of the filename (e.g., 20260107xxx.md).
- Claude first ran a dry-run preview using echo — the preview output appeared correct
(though it was also affected by the same bug, showing -> .md, which went unnoticed).
- Claude then ran the actual mv commands without creating a backup first.
- BASH_REMATCH silently failed on CJK filenames, producing empty capture groups.
- All 36 .md files were sequentially renamed to .md, each overwriting the last. Same for 3
.xlsx files renamed to .xlsx.
- Result: 38 files reduced to 2 surviving files + 2 unaffected files.
Expected behavior
Before performing any destructive batch file operation, Claude Code should:
- Create a backup of the target directory (e.g., cp -r dir dir.bak) before executing bulk
renames/deletes.
- Validate the dry-run output — the preview already showed -> .md as the target filename,
which should have been caught as obviously wrong before proceeding.
- Test on a single file first before applying to the entire directory.
- Refuse or warn when a batch operation would cause multiple files to map to the same
destination filename (collision detection).
Environment
- macOS (Darwin 25.0.0)
- Claude Code CLI
- Model: claude-opus-4-6
- Shell: zsh
- Filenames contained Chinese (CJK) characters
Impact
- 38 files lost, including project analysis documents, architecture docs, and technical
design docs accumulated over months.
- Files cannot be recovered (no Time Machine, mv bypasses trash).
- Regenerating these documents will cost significant time and API credits.
Suggestion
Consider adding guardrails for destructive file operations in Claude Code:
- Mandatory backup before bulk file mutations — When Claude is about to mv, rm, or
overwrite multiple files, it should automatically back up the directory first.
- Collision detection — Before executing a batch rename, verify that all destination
filenames are unique. Abort if collisions are detected.
- Dry-run validation — When a dry-run is performed, Claude should programmatically verify
the output makes sense (e.g., no empty filenames, no duplicate targets) rather than just
displaying it.
- Single-file test-first pattern — For batch operations, execute on one file first, verify
the result, then proceed with the rest.
Alternative Solutions
Additional Request
Given that the data loss was caused by Claude Code executing a destructive batch operation without safeguards, I hope it would be possible to receive some token credit compensation to help regenerate the lost documents.
Recreating these files will require significant API usage and time. Token credits would help offset the cost of rebuilding the project analysis documents, architecture documentation, and technical design materials that were lost.
My account email is: aaa.com
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
_No response_
Additional Context
Additional Request
Given that the data loss was caused by Claude Code executing a destructive batch operation without safeguards, I hope it would be possible to receive some token credit compensation to help regenerate the lost documents.
Recreating these files will require significant API usage and time. Token credits would help offset the cost of rebuilding the project analysis documents, architecture documentation, and technical design materials that were lost.
My account email is: horsexiaoyang@gmail.com
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗