Safe Delete
Expert on safe file deletion practices using trash instead of rm.
Overview
- Blocks dangerous patterns like
rm -rf /,rm -rf ~,sudo rm -rf - Transforms rm to trash for recoverable deletion
- Uses PreToolUse hooks to intercept Bash commands
- Provides CLAUDE.md instructions so Claude uses trash by default
- Works globally or per-project via plugin installation
How It Works
Two-Layer Protection
- CLAUDE.md Instructions - Tells Claude to use
trashinstead ofrm - PreToolUse Hook - Catches rm commands and either blocks or transforms them
Hook Processing Stages
Stage 1: Block dangerous patterns
rm -rf /,rm -rf ~,rm -rf .,rm -rf *sudo rm -rf(any path)--no-preserve-rootflag
Stage 2: Transform safe rm to trash
rm file.txt→trash file.txtrm -rf ./build→trash ./buildrm -r dir/→trash dir/
Quick Start
# Install trash (macOS)
brew install trash
echo 'export PATH="/opt/homebrew/opt/trash/bin:$PATH"' >> ~/.zshrc
# Install trash (Linux)
pip install trash-cli
Documentation
- Installation - Setup for macOS, Linux, global/per-project
- Dangerous Patterns - Full list of blocked patterns
- Trash Alternatives - trash-cli usage guide
- Configuration - Customizing blocked patterns
Command Examples
# Check if a command would be blocked or transformed
/safe-delete check "rm -rf ./node_modules"
# Convert an rm command to trash
/safe-delete convert "rm -rf ./dist"
# List all blocked patterns
/safe-delete patterns
# Install trash utility
/safe-delete install
Why Use This
| Command | Risk | Recovery |
|---|---|---|
rm -rf ./build |
Permanent deletion | None |
trash ./build |
Moves to Trash | Easy restore |
rm -rf / |
System destruction | Reinstall OS |
Hook Response Examples
// Blocked (dangerous)
{
"decision": "block",
"reason": "Blocked dangerous command: 'sudo rm -rf' pattern detected."
}
// Transformed (safe)
{
"decision": "modify",
"modifiedToolInput": {
"command": "trash ./node_modules"
}
}