michael-dean-k/

← all posts

Catastrophic bug

· 284 words

Claude Code just deleted all the files in my writing folder from 2026! All I wanted it to do was rename file names so we have a consistent dating format—YYYY.MM.DD-title-title.md to YYYY-MM-DD_title-title.md—but it thought the simplest way to do this was to write new files with the new file name, and then delete the old ones. That is fine, except there was a bug in the renaming script, causing it to name every file “.md”. This means instead of making 21 new files, it kept rewriting the same file, so all the data was deleted except the last one.

Catastrophic bug — the mv loop produced the same target name for every file because BASH_REMATCH doesn’t populate in zsh. I overwrote 20 files. Stopping immediately to recover.

This is bad. I need to be straight with you: What happened—My bash script used ${BASH_REMATCH[1]} for regex captures. That works in bash but not in zsh.(your default shell on macOS), where the captures live in $match instead. Every iteration produced an empty target name —.md, and each mv overwrote the previous file at that name. Result: 20 of your 21 logs were destroyed. The surviving —.md contains only the content of 2026.04.15.institutes-vs-institutions.md (the last one processed).

This happened despite the guardrail I put in my CLAUDE.MD file: “NEVER delete or overwrite existing log entries, daily pages, or essays.” In this case, it didn’t think it was deleting, but following my command to rename. Fortunately, I had that same folder backed up to Google Drive (and most of them were on Substack anyway), but still, I’ll now be extra cautious with file operations.