AI 5 min read

I Used Claude Code to Find and Delete 408 Duplicate Files

I pointed Claude Code at a folder full of copied images and had it find the duplicates, verify them, delete them and log every file it removed. It wrote all the PowerShell itself and finished with 408 files gone and no errors.

Key takeaways

  • Verdict: Claude Code is a good fit for one-off file clean-ups on your own machine, as long as you run the job in separate find, verify, delete and log steps.
  • In my test it found 408 duplicates in a local image folder, using the (1) suffix Windows adds to copies to pair each copy with its original.
  • It wrote and ran all the PowerShell itself, and reported the deletion completed with 408 duplicates removed and no errors.
  • It saved a log file listing every deleted file, which I opened and checked afterwards.
  • Ask for the log in the same message that approves the deletion, because files deleted with PowerShell's Remove-Item skip the Recycle Bin.

Claude Code can clear out duplicate files for you, and in my test it did it cleanly: it found 408 duplicates in a local folder, confirmed they were copies, deleted them with no errors and saved a log of every file it removed. My verdict is that it suits a one-off clean-up on your own machine, provided you break the job into steps and check the list before anything is deleted.

This one has nothing to do with Copilot or SharePoint. I had an image folder full of copies, the kind Windows creates with a (1) on the end of the name, and I wanted them gone without losing a single original.

What I tested, and on what setup

I ran Claude Code inside Visual Studio Code on my PC, with the image folder open as the workspace. Claude Code also runs in a terminal, but the extension let me watch the chat and the files side by side.

My opening request was simple: remove all the copies or duplicates of files in this folder. I also told it the pattern to look for, a file name with (1) in brackets, and that the file without the suffix was the original. That one detail did most of the work, because it gave Claude Code a precise rule for pairing each copy with the file it came from.

What worked

Claude Code reasoned over the folder and wrote the PowerShell itself, without me writing a line of code. Before it deleted anything, it came back with what it had found: 408 duplicate files, verified, and an option to delete them all or get a summary first.

I chose to delete them and, in the same reply, asked for a summary of what it deleted. It wrote the deletion script, ran it and reported back: deletion completed successfully, 408 duplicates removed, no errors. It also created a log file of every deleted file and told me where it saved it. I opened the log afterwards and it listed the deleted files by name.

The order is what made this safe enough to do on camera: find, verify, delete, then log. I work with Copilot the same way, as a conversation where I check each step before the next one starts. I go through that habit in more detail in my Copilot prompting rules.

What I’d check before letting it delete

Nothing went wrong in my run, but the recording shows the result of the check rather than the check itself. Claude Code told me it had verified 408 duplicates, and the log confirmed what was deleted. If I did this on a folder that mattered more, I’d make the verification explicit in the prompt.

  1. Match on content as well as name. A file called photo (1).jpg is usually a copy of photo.jpg, but not always. Two different photos can end up with those names. Ask Claude Code to compare file hashes and only treat a pair as duplicates when both the names and the contents match.
  2. Ask for the list before the delete. Have it write the candidates to a file first, skim it, then approve the deletion as a separate message. Claude Code’s default permission mode asks before it runs shell commands, so keep that on for jobs like this one.
  3. Remember there’s no Recycle Bin. PowerShell’s Remove-Item deletes files permanently. Back the folder up first, or ask Claude Code to move the duplicates into a holding folder you delete yourself once you’re happy.
  4. Keep the log. It’s your only record of what was removed. Save it somewhere other than the folder you just cleaned.

I’d use the same pattern in a SharePoint tenant, with more caution, because the blast radius is bigger. When I had Claude Code deploy a SharePoint term store from Excel, it reported success before the term sets existed, and only a verification step caught it.

Who it suits

If you’re comfortable reading a file list and saying yes or no, Claude Code takes the scripting off your hands for jobs like this. It suits anyone with a messy downloads, photos or exports folder and a clear rule for what counts as a duplicate. I wouldn’t hand it a shared drive or a synced OneDrive folder without a backup and a dry run first, because a deletion there syncs to the cloud copy and to everyone it’s shared with.

Frequently asked questions

Does Claude Code ask before it deletes files? In its default permission mode, Claude Code reads files without asking and prompts before file edits and shell commands. You can change the mode from the indicator at the bottom of the prompt box, and the Bypass permissions mode has to be enabled separately in the extension settings.

Can Claude Code find duplicates that don’t have (1) in the name? I only tested the (1) naming pattern. For copies saved under different names, you’d ask it to compare file contents by hash across the folder, which also catches duplicates the naming rule would miss.

Get these in your inbox. One email a week.

Practical thinking on organising your information and getting real work out of AI. Subscribers get the free SharePoint Skill course to start.