CRITICAL: Claude attempts to delete home directory when cleaning up file named '~'
Status Fixed / completed
Maintainer reply ✓ Yes — ashwin-ant
Activity 5 comments · opened Apr 16, 2026 · closed Apr 19, 2026
💡 Likely answer: A maintainer (ashwin-ant, collaborator)
responded on this thread — see the highlighted reply below.
Summary
Claude Code attempted to execute rm -f ~/ which would delete the user's entire home directory. This occurred when trying to clean up untracked files that included a literal directory named ~, might also apply to untracked files named ~
Context
- Working directory had untracked files including:
.blah.swp,.gitignore.swp, and a directory literally named~ - Git status showed these as untracked:
~~ ~/(the~is the status,~/is the directory) - User asked to fix PR checks which included a "boilerplate integrity" failure due to uncommitted changes
- Claude attempted to clean up swap files and other unnecessary untracked files
What Happened
- Claude successfully removed swap files:
rm -f .blah.swp .gitignore.swp - Claude then attempted:
rm -f ~/intending to remove the local directory named./~ - This command would actually delete the USER'S HOME DIRECTORY
- User blocked the command and reported the issue
Root Cause
Claude misinterpreted directory ./~ (or ~/ in git status) as a shell expansion to the home directory rather than as a literal filename that should be escaped or quoted.
Expected Behavior
When handling a directory or files literally named ~, Claude should:
- Use
rm -f './~'orrm -f '~'with proper quoting - Or use
rm -f -- ~to prevent interpretation - Never execute
rm -f ~/without explicit user confirmation for home directory deletion
Impact
CRITICAL SEVERITY: This could result in catastrophic data loss - deletion of user's entire home directory including all personal files, configurations, and potentially unrecoverable work.
Suggested Mitigations
- Add guardrails to prevent
rmcommands targeting home directory without explicit user confirmation - Improve path handling to properly quote/escape special filenames
- Add pattern detection for dangerous commands like
rm -rf ~/,rm ~/, etc. - Consider requiring confirmation for any
rmcommand outside the project directory - Train on proper shell escaping for special characters in filenames
Reproduction
- Create a file named
~in a git repository:touch '~' - Add other untracked files like
.file.swp - Ask Claude to clean up untracked swap files and unnecessary files
- Observe Claude attempts
rm -f ~/
Environment
- Platform: darwin (macOS)
- Shell: zsh
- Model: Sonnet 4.5 (us.anthropic.claude-sonnet-4-5-20250929-v1:0)
- Git repository with untracked files including literal
~filename
5 Comments
<img width="1286" height="811" alt="Image" src="https://github.com/user-attachments/assets/417c619f-1183-4947-9eb5-465a3ca97563" />
<img width="1285" height="660" alt="Image" src="https://github.com/user-attachments/assets/8fbbd5b3-bf9a-4427-862e-a7fb586c1348" />
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Actually it is not a duplicate of the ones above it is a different issue. Claude need to quote filenames for every rm command unless the path is fully qualified.
This has been fixed in a recent release — Sandbox auto-allow no longer bypasses the dangerous-path safety check for rm/rmdir targeting ~, $HOME, /, or other critical system directories. If you're still seeing this in the latest version, please comment with your version and repro and we'll reopen.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.