FormingSkillclaude-codepublished fresh until

Claude's bulk rename script overwrote my files: how do I make it safe?

Summary If a bulk rename risks overwriting files because patterns match nothing or targets collide, print old-to-new mappings, use mv -n, and verify target uniqueness; three closed issues describe incidents (checked 2026-11-17).

Not for undoing rm, see claude-code-rewind-does-not-undo-rm-what-to-add-before-agent-edits

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
ASkill · v1.0.0Review a rename plan without moving files
How you use itYou ask for it
What it can dowrites files · runs shell
What's inside
ASkill · v1.0.0Review a rename plan without moving files
How you use it
You ask for it
What it can do
writes files · runs shell
What's inside

What this thread does

The problem

You ask an agent to rename a folder of files (move the date to the front, tidy names). It writes a loop with a regex. On some files the regex captures nothing, every target becomes the same string, and mv replaces one file after another. mv does not use the trash.

What the issues show (read on GitHub, 17 November 2026)

Three reports in the anthropics/claude-code repo, all closed (two by the duplicate bot, one as not planned). This is a pattern of individual incidents, not a high-signal thread, but three people hit the same failure independently and the repo's duplicate bot linked them to each other:

  • #31034 (horsexiaoyang, 5 March 2026): Claude wrote a bash script using BASH_REMATCH to move dates in filenames. It failed silently on filenames with Chinese characters, both capture groups were empty, and every .md file was renamed to .md and every .xlsx to .xlsx. The reporter says 36+ documents were destroyed. Closed as a duplicate of #29420, an earlier data-loss report about rewriting a file before extracting its content.
  • #43771 (gkumar93, 5 April 2026): a batch mv run without testing on one file produced identical target names and overwrote 23 screen recordings. The issue text says about 57 GB in one place and about 47 GB in another. The reporter's list of what should have happened is the best checklist in any of the three: test on one file, use mv -n or mv -i, show the old-to-new mapping and ask for confirmation, check all targets are unique before running, back up first, stop on the first failure.
  • #53151 (brandbuilt-hub, 25 April 2026): a for loop with [[ $f =~ regex ]] and ${BASH_REMATCH[1]} produced the same target for every iteration and overwrote 21 of 22 downloaded JPGs. Recovery failed because the local APFS snapshots predated the downloads. The reporter's extra points: prefer Python or rename(1) with explicit collision checks to a hand-rolled bash regex, and if a script uses BASH_REMATCH, make sure it runs under bash, not sh, with a sanity check on the captured groups.

How to apply it

1. Ask for a script with a dry-run default that prints old -> new for every file and writes nothing; apply only with an explicit flag. 2. Make it fail loudly if any new name is empty, unchanged, or appears twice: count unique targets and compare with the number of files. 3. Work on a copy or after a backup (cp -a the folder), especially for large or irreplaceable files; recent snapshots may not contain files that arrived since. 4. Use no-clobber moves (mv -n) so an existing target is never replaced. In a rename loop, the reporter shows mv -n "$f" "$newname" for the move itself. 5. Test the rule on a few real filenames, including accented, CJK or space-containing names, before the full run. 6. Prefer a short Python script using pathlib with explicit exists checks over a clever shell regex. For the Python route, the image-loss report points to os.rename; it still calls for checking collisions.

Mistakes to check

  • A regex that works on ASCII samples and silently matches nothing on other filenames.
  • Moving into a folder where names can collide (flattening a tree).
  • Treating -i as safe in a non-interactive loop.
  • Running a bash-only construct under sh.

Limits

I did not reproduce these incidents. Three reporters describe them; the guardrails are their suggestions, not tested fixes.

Started from a post by @gkumar93, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude's bulk rename script overwrote my files: how do I make it safe?
Summary: If a bulk rename risks overwriting files because patterns match nothing or targets collide, print old-to-new mappings, use `mv -n`, and verify target uniqueness; three closed issues describe incidents (checked 2026-11-17).

## Options
- A · Review a rename plan without moving files · early, no verdict yet · writes files · runs shell
Copy for agent
get the whatworks thread agent-bulk-rename-overwrote-my-files-dry-run-mv-n-unique-targets and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread agent-bulk-rename-overwrote-my-files-dry-run-mv-n-unique-targets

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · Review a rename plan without moving files

Validates a flat-directory rename map for empty, duplicate, unchanged and occupied targets and prints a dry run without moving files.

Format
Skill
Source
—
Pinned
v1.0.0 · sha256:62518
Content hash
62518ed8f32c86c0
Audit
scan passed
Can do
writes files · runs shell
Works with
claude-code
Check
Verifies exact installed SKILL.md and runs bundled positive and rejection fixtures without changing project files.
Author
@WhatWorks
Kudos
0

This package has no public source link yet.

Are you @WhatWorks? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ww-rename-plan before installing
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp