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

  1. Claude successfully removed swap files: rm -f .blah.swp .gitignore.swp
  2. Claude then attempted: rm -f ~/ intending to remove the local directory named ./~
  3. This command would actually delete the USER'S HOME DIRECTORY
  4. 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 './~' or rm -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

  1. Add guardrails to prevent rm commands targeting home directory without explicit user confirmation
  2. Improve path handling to properly quote/escape special filenames
  3. Add pattern detection for dangerous commands like rm -rf ~/, rm ~/, etc.
  4. Consider requiring confirmation for any rm command outside the project directory
  5. Train on proper shell escaping for special characters in filenames

Reproduction

  1. Create a file named ~ in a git repository: touch '~'
  2. Add other untracked files like .file.swp
  3. Ask Claude to clean up untracked swap files and unnecessary files
  4. 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

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗