CRITICAL: Claude attempts to delete home directory when cleaning up file named '~'
Resolved 💬 5 comments Opened Apr 16, 2026 by lmello Closed Apr 19, 2026
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
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗