Claude Code Deleted My Files. Here's How I Stop It Now
Claude Code deleted my files. Forty-nine of them, in one go, and they were not even inside the project it was working on. I made a video about it and the four guards I use now to stop it. This article has what the video has no room for: what the official docs say about deny rules and hooks (including a table of the commands a deny rule does not stop), a hook script I wrote and ran against a test…
Claude Code inadvertently deleted 49 files from the user's project by following a symlink that pointed to shared settings folders. The user discovered this by creating a video about the incident and outlining four safeguards to prevent such occurrences.
The official documentation provides two crucial points about Claude Code's behavior. First, user instructions or the CLAUDE.md file "shape what Claude tries to do, but they don't change what Claude Code allows." Second, a deny rule "isn't a security boundary around the program." To safeguard against Claude's actions, the user employs a combination of tools and habits.
The four safeguards consist of two measures that exist outside the AI and two personal habits. The two external safeguards are:
1. A "never list" or deny rules, which live in the settings.json file. This list specifies actions Claude Code is explicitly forbidden to perform, evaluated in order of precedence.
2. A PreToolUse hook, a script that reads every command before it runs, preventing unsafe operations from executing.
The two personal habits are:
1. Backing up data before making any changes.
2. Inspecting files before deletion, using the ls -la command on parent folders to identify symlinks and understand their contents.
The user has experienced the consequences of Claude Code's actions firsthand, noting that 43 files within a shared docs folder and an additional 6 files in the shared commands folder were removed. For the user's own testing purposes, they replicated the situation on a throwaway folder to demonstrate the potential impact.
The user has established a comprehensive list of 25 deny rules within the settings.json file, covering a range of actions to prevent potential damage. These rules include preventing disk wipes, database resets, and various destructive commands executed through tools like Docker, Git, and Prisma.
The user acknowledges that AI systems like Claude Code may not always act with the intention to cause harm, but the lack of awareness and understanding of the broader consequences can lead to unintended file deletions. The four safeguards mentioned above help mitigate the risk of such accidental deletions, ensuring that the user maintains control over their project's data.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to