[BUG] Destructive batch rename operation caused data loss
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?
Description points:
- Claude executed a batch mv rename command without testing on a single file first
- The rename pattern failed, causing multiple files to get the same target name
- mv overwrote files silently, resulting in loss of 23 files (~57 GB of screen recordings)
- Claude should have: (1) tested on one file first, (2) used mv -n (no-clobber) to prevent overwrites, or (3) asked for confirmation before batch operations on important files
What Should Happen?
- Test first - Run the rename command on a single file to verify the pattern works correctly before applying to all files
- Use safe flags - Use mv -n (no-clobber) which refuses to overwrite existing files, or mv -i (interactive) which prompts before overwriting
- Preview before executing - Show the user a list of "old name → new name" mappings and ask for confirmation before actually renaming
- Validate uniqueness - Check that all generated target filenames are unique before executing any renames
- Create backups - For batch operations on important files, suggest creating a backup first or copy files to a temp location before renaming
- Fail safely - If any part of the operation fails, stop immediately rather than continuing and potentially causing more damage
Example of what I should have done:
# First, preview the changes without executing
for f in *.mov; do
newname=$(generate_new_name "$f")
echo "$f -> $newname"
done
# Ask user: "Does this look correct? (y/n)"
# Then use mv -n to prevent overwrites
mv -n "$f" "$newname"
Error Messages/Logs
❯ move all to Screen Recordings
⏺ Bash(mv /Users/gaurav.kumar/Desktop/Screen\ Recording\ *.mov /Users/gaurav.kumar/Desktop/Screen\ Recordings/)
⎿ Done
Searched for 1 pattern (ctrl+o to expand)
⏺ Done. Your Desktop is now organized:
Desktop/
├── Documents/ (10 files)
├── New Note/
├── Screen Recordings/ (25 files, ~59 GB)
└── Screenshots/ (64 files)
❯ Can you review stream recordings and name the stream recordings as per content?
⏺ I can't view the content of video files (.mov) - I can only read images, PDFs, and text files.
Alternatives:
1. You review and tell me - Open each recording, tell me what it contains, and I'll rename them for you
2. Use macOS Quick Look - Select recordings in Finder and press Space to preview them quickly
3. Batch rename by date/time - I can rename them to a cleaner format like 2026-03-28_10-51AM.mov instead of the long screenshot names
Would any of these work for you?
❯ Batch rename by date/time - I can rename them to a cleaner format like 2026-03-28_10-51AM.mov instead of the long screenshot names
⏺ Bash(cd /Users/gaurav.kumar/Desktop/Screen\ Recordings && for f in *.mov; do
# Extract date and time from filename like "Screen Recording 2026-03-27 at 7.34.10 PM.…)
⎿ Screen Recording 2026-03-28 at 10.04.09 AM.mov -> Screen Recording 2026-03-28 at 10.04.09 AM.mov
Screen Recording 2026-03-28 at 10.51.54 AM.mov -> Screen Recording 2026-03-28 at 10.51.54 AM.mov
Screen Recording 2026-03-28 at 11.15.07 AM.mov -> Screen Recording 2026-03-28 at 11.15.07 AM.mov
… +19 lines (ctrl+o to expand)
⏺ The regex didn't match. Let me fix that.
⏺ Bash(cd /Users/gaurav.kumar/Desktop/Screen\ Recordings && for f in Screen\ Recording*.mov; do
# Parse: "Screen Recording 2026-03-27 at 7.34.10 PM.mov"…)
⎿ Renamed -> 2026-03-28_.mov
Renamed -> 2026-03-28_.mov
Renamed -> 2026-03-28_.mov
… +19 lines (ctrl+o to expand)
⏺ That didn't work correctly - the time extraction failed and files may have been overwritten. Let me check what's left.
Read 1 file (ctrl+o to expand)
⏺ I made a serious mistake. The rename script failed to parse the time correctly, and because multiple files got the same name, they overwrote each other.
Only 2 files remain:
- 2026-03-28_.mov (11 GB) - likely the last Mar 28 recording
- 2026-03-29_.mov (1.1 GB) - likely the last Mar 29 recording
23 screen recordings were lost. I apologize - I should have tested the rename on one file first.
Recovery options:
1. Check Trash - the overwritten files might be recoverable there
2. Time Machine - if you have backups enabled, you can restore from there
3. Data recovery software - tools like Disk Drill might recover recently deleted files
Would you like me to check if they're in Trash?
✻ Crunched for 32s
❯ How can i check Trash
Searched for 1 pattern (ctrl+o to expand)
⏺ I can't access Trash directly. Here's how you can check:
Via Finder:
1. Click the Trash icon in your Dock
2. Look for "Screen Recording" files
Via Terminal (run this yourself):
! ls -lh ~/.Trash/ | grep -i "screen"
However, I should warn you: when mv overwrites a file, it typically does not go to Trash - the data is directly overwritten on disk. The files are likely gone.
Steps to Reproduce
- Create a folder with multiple files that have similar naming patterns with timestamps:
mkdir ~/Desktop/TestFolder
touch ~/Desktop/TestFolder/"Screen Recording 2026-03-28 at 10.04.09 AM.mov"
touch ~/Desktop/TestFolder/"Screen Recording 2026-03-28 at 10.51.54 AM.mov"
touch ~/Desktop/TestFolder/"Screen Recording 2026-03-28 at 11.15.07 AM.mov"
touch ~/Desktop/TestFolder/"Screen Recording 2026-03-29 at 10.14.11 AM.mov"
touch ~/Desktop/TestFolder/"Screen Recording 2026-03-29 at 10.36.56 AM.mov"
- Ask Claude Code: "Batch rename these files to a cleaner date/time format like 2026-03-28_10-04AM.mov"
- Claude executes a batch rename script with a flawed regex pattern that fails to extract the time component:
cd ~/Desktop/TestFolder && for f in Screen\ Recording*.mov; do
date=$(echo "$f" | grep -oE '[0-9]{4}-[0-9]{2}-[0-9]{2}')
time=$(echo "$f" | grep -oE 'at [0-9]+\.[0-9]+\.[0-9]+ [AP]M' | sed 's/at //' | sed 's/\.[0-9][0-9] /-/' | sed 's/\./-/')
newname="${date}_${time}.mov"
mv "$f" "$newname" # No -n flag, will overwrite
done
- Result: Multiple files get renamed to the same filename (e.g., 2026-03-28_.mov), causing mv to silently overwrite previous files
- Data loss: Only the last file for each date survives; all others are permanently lost
Root cause:
- Regex/sed pattern fails silently, producing empty $time variable
- No uniqueness check before renaming
- mv without -n flag overwrites existing files without warning
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.81 (Claude Code)
Platform
AWS Bedrock
Operating System
macOS
Terminal/Shell
iTerm2
Additional Information
⏺ Additional Information:
Environment:
- OS: macOS (Darwin 24.6.0)
- Shell: zsh
- Model: Claude Opus 4.5
- Tool: Claude Code CLI
Context:
- User asked to organize Desktop files into folders (Screenshots, Documents, Screen Recordings)
- Files were successfully moved to folders
- User then asked to batch rename screen recordings from Screen Recording 2026-03-28 at 10.51.54 AM.mov to cleaner format 2026-03-28_10-51AM.mov
- 25 screen recordings totaling ~59 GB were affected
- Only 2 files (~12 GB) survived; 23 files (~47 GB) permanently lost
Files lost:
Screen Recording 2026-03-27 at 7.34.10 PM.mov (177 MB)
Screen Recording 2026-03-27 at 7.37.14 PM.mov (136 MB)
Screen Recording 2026-03-27 at 7.40.00 PM.mov (257 MB)
Screen Recording 2026-03-28 at 10.04.09 AM.mov (120 MB)
Screen Recording 2026-03-28 at 10.51.54 AM.mov (1.9 GB)
Screen Recording 2026-03-28 at 11.15.07 AM.mov (3.0 GB)
... (and 17 more)
Suggested fixes for Claude Code:
- Add guardrails for batch file operations (rename, delete, move)
- Default to mv -n or cp + rm pattern for safer renames
- Require preview + confirmation for operations affecting >5 files
- Warn when regex/pattern extraction produces empty or duplicate values
- Consider adding a --dry-run step for batch operations
Related issue pattern:
This falls under "destructive operations" mentioned in Claude's own system prompt - batch renames should be treated with the same caution as rm -rf or git reset --hard.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗