Introduction
AI coding assistants are becoming everyday tools for software developers, but they can still cause serious damage when a command goes wrong. Recent reports from Claude Code users describe agents that unintentionally deleted entire drives, wiped mounted data disks, and erased more than a year of unpublished git history. These incidents show that even advanced language models can generate destructive shell commands when variables resolve to empty or unexpected values.
What Happened
Three separate issue reports from this past autumn describe the same pattern from different operating systems.
- Windows with Git Bash: An agent attempted to clear old test state by running a recursive delete against the output of a path conversion command. Because standard error was suppressed, the operation ran silently for about 35 minutes and deleted roughly 600 gigabytes, including the Windows user profile and several git repositories.
- Windows with WSL: A subagent tried to copy a project into Linux using rsync with the delete flag. An outer shell expanded an unset variable to nothing, turning the destination into the root of the mounted Windows data drive. Files removed this way bypass the Recycle Bin entirely.
- macOS: An agent removed a repository's .git directory, destroying more than twelve months of history that had never been pushed to a remote server.
- macOS process signals: An agent used pkill with an option that BSD pkill does not support. The malformed argument matched nearly every process and sent termination signals to other active Claude Code sessions.
Why This Matters
Common advice for safe shell scripting did not prevent these accidents. Quoting a variable does not help when that variable is empty, because 'rm -rf $D/' still becomes 'rm -rf /'. The 'set -u' option only triggers in the shell that actually sees the unset variable, which was not the shell that expanded it in the WSL case. The '--preserve-root' flag protects the root directory itself but not paths like '/*', '/c/', or '/mnt/d/'.
AI agents also rarely apply these safeguards on their own. A memory file warning against recursive deletes is only a suggestion, not an enforced check. The consequences can be severe: hundreds of gigabytes lost, local git history erased, and deletions that cannot be undone through standard operating system trash folders.
Key Takeaways
- Use ${VAR:?} so the shell stops with an error instead of substituting an empty string into a destructive command.
- Print or inspect the target path before running 'rm -rf' or 'rsync --delete', especially when the value comes from a command substitution.
- Move a .git folder aside with 'mv' rather than deleting it, preserving history if something goes wrong.
- PreToolUse hooks can inspect command text before execution. The open-source claude-bulkhead project includes rules that block recursive deletes built from empty variables, .git removal, and unquoted variables containing spaces or wildcards.
- Hooks cannot see deletions hidden inside scripts that an agent writes and then executes, so the scripts themselves must use safe variable expansion.
Conclusion
AI coding agents are powerful, but they are not immune to simple shell mistakes. A single empty variable can turn a cleanup command into a data-loss event. By combining defensive shell patterns, careful target inspection, and pre-execution hooks, developers can catch dangerous commands before they run. The safest approach is to assume any agent-generated delete command could be wrong until it is verified.

Discussion
Join the conversation
Thoughtful reactions, questions, and follow-up ideas help shape the next story.