From latestaiagents
CRITICAL SAFETY SKILL - Use this skill before any file system operation that deletes, moves, or overwrites files. Activate when the user wants to rm, mv, cp (with overwrite), clear directories, or perform bulk file operations. This skill prevents accidental file loss through verification and confirmation protocols.
npx claudepluginhub latestaiagents/agent-skills --plugin skills-authoringThis skill uses the workspace's default tool permissions.
**CRITICAL: File deletions can be permanent. This skill prevents irreversible file loss.**
Guides safe rm -rf and rm -r usage to prevent deleting current directory and breaking shell sessions. Includes pwd checks, cd patterns, and checklists.
Blocks destructive Bash commands like rm -rf, DROP TABLE, git force-push, reset --hard, and restricts file edits to a specific directory. Use for protection on critical systems.
Blocks destructive commands like rm -rf, git --force-push, kubectl delete; restricts edits to specified directories for production systems or autonomous agents.
Share bugs, ideas, or general feedback.
CRITICAL: File deletions can be permanent. This skill prevents irreversible file loss.
| Level | Operations | Requires |
|---|---|---|
| โ CRITICAL | rm -rf, recursive delete on directories | Full path verification + explicit confirmation |
| ๐ด HIGH | rm multiple files, mv with overwrite | List all files + confirmation |
| ๐ MEDIUM | rm single file, cp with overwrite | Verify file exists + confirm |
| ๐ข LOW | cp to new location, mkdir, touch | Standard execution |
Step 1: Verify the path
# ALWAYS expand and verify the path first
realpath /path/to/target
ls -la /path/to/target
# Check what's inside (for directories)
find /path/to/target -type f | wc -l # Count files
du -sh /path/to/target # Check size
Step 2: Present impact to user
## File Deletion Impact Assessment
**Command:** rm -rf ./node_modules
**Resolved path:** /Users/dev/myproject/node_modules
**Contents:**
- Total files: 45,234
- Total directories: 8,901
- Total size: 234 MB
- Contains hidden files: Yes (.cache, .bin)
**Can be recreated:** Yes (via `npm install`)
Proceed with deletion? Type "yes, delete node_modules" to confirm.
โ **CRITICAL: RECURSIVE DELETE REQUESTED**
**Command:** rm -rf /var/www/myapp
**โ ๏ธ FULL PATH CHECK:**
- Requested path: /var/www/myapp
- Resolved path: /var/www/myapp
- Parent directory: /var/www (contains 3 other directories)
- Is symlink: No
**Contents to be deleted:**
- Files: 1,234
- Directories: 89
- Size: 456 MB
- Includes:
- Source code (*.js, *.ts): 234 files
- Configuration (*.json, *.yml): 12 files
- Environment files (.env): 1 file โ ๏ธ
- Uploaded files (uploads/): 567 files โ ๏ธ
**Recovery:**
- Git repository: Yes (can recover source code)
- Uploads folder: NO GIT โ ๏ธ (not recoverable)
- .env file: NO GIT โ ๏ธ (not recoverable)
**Before deletion, I recommend:**
1. Backup uploads folder: `cp -r uploads /backup/uploads_$(date +%Y%m%d)`
2. Backup .env: `cp .env /backup/.env_$(date +%Y%m%d)`
Proceed with deletion after backup? Type "yes, delete /var/www/myapp after backup" to confirm.
โโโ **EXTREME DANGER: CATASTROPHIC PATH DETECTED**
**Command:** rm -rf ~/ (or /, /home, /usr, /etc, /var)
**๐ซ I WILL NOT EXECUTE THIS COMMAND.**
This would delete:
- Your entire home directory
- All personal files, documents, and configurations
- SSH keys, credentials, and secrets
- Potentially your entire system
**This is almost certainly a mistake.**
If you need to clean up:
- Specify exact subdirectories to delete
- Use `rm -rf ~/specific/directory` instead
- Never use wildcards at root level
**I will not proceed with this request under any circumstances.**
๐ด **DANGEROUS: WILDCARD DELETION**
**Command:** rm -rf *.log
**Working directory:** /var/log/myapp
**Files matching pattern:**
1. access.log (234 MB)
2. error.log (45 MB)
3. debug.log (12 MB)
4. app.2024-01-15.log (5 MB)
5. app.2024-01-14.log (4 MB)
... and 23 more files
**Total files:** 28
**Total size:** 345 MB
**Potential issues:**
- Pattern `*.log` is broad - verify these are all logs you want to delete
- Some may be needed for debugging recent issues
- Rotating logs may have important history
**Safer alternatives:**
```bash
# Delete only old logs
find . -name "*.log" -mtime +30 -delete
# Keep recent logs
rm -f *.log.2023*
Proceed with deleting all 28 .log files? Type "yes, delete 28 log files" to confirm.
### Moving Files (Overwrite Risk)
```markdown
## File Move Impact Assessment
**Command:** mv ./config.json ./backup/config.json
**โ ๏ธ OVERWRITE WARNING:**
A file already exists at the destination!
**Source file:**
- Path: ./config.json
- Size: 2.3 KB
- Modified: 2024-01-16 14:30:00
**Destination file (WILL BE OVERWRITTEN):**
- Path: ./backup/config.json
- Size: 1.8 KB
- Modified: 2024-01-15 09:00:00
**Differences detected:** Yes (source is newer and larger)
**Options:**
1. Overwrite (lose old backup)
2. Rename destination first: `mv ./backup/config.json ./backup/config.json.old`
3. Use versioned name: `mv ./config.json ./backup/config.$(date +%Y%m%d).json`
4. Cancel
Choose an option or type "yes, overwrite backup/config.json" to proceed with overwrite.
## File Copy Impact Assessment
**Command:** cp -r ./src ./backup/src
**โ ๏ธ DIRECTORY OVERWRITE WARNING:**
The destination directory already exists!
**Source directory:**
- Path: ./src
- Files: 234
- Size: 12 MB
**Destination directory (contents may be OVERWRITTEN):**
- Path: ./backup/src
- Files: 198
- Size: 10 MB
- Modified: 2024-01-14 16:00:00
**What will happen:**
- 198 existing files may be overwritten with newer versions
- 36 new files will be added
- 0 files in destination will be deleted (cp doesn't delete)
**Safer alternatives:**
```bash
# Create versioned backup
cp -r ./src ./backup/src_$(date +%Y%m%d_%H%M%S)
# Use rsync for smarter sync
rsync -av --backup --suffix=.bak ./src/ ./backup/src/
Choose approach or type "yes, overwrite backup/src" to proceed.
## Safe Patterns
### Safe Deletion with Confirmation
```bash
# Interactive deletion (asks for each file)
rm -i file1 file2 file3
# Show what would be deleted (dry run)
find /path -name "*.tmp" -print # Preview
find /path -name "*.tmp" -delete # Execute after verification
# Move to trash instead of permanent delete
# macOS
mv file ~/.Trash/
# Linux (with trash-cli)
trash-put file
# Never use: rm -rf *
# Instead, be explicit:
rm -rf ./node_modules
rm -rf ./dist
rm -rf ./.cache
# Or use a list:
DIRS_TO_CLEAN="node_modules dist .cache"
for dir in $DIRS_TO_CLEAN; do
echo "Deleting: $dir"
rm -rf "./$dir"
done
# Create timestamped backup
BACKUP_DIR="./backups/$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"
cp -r ./important_folder "$BACKUP_DIR/"
# Then proceed with risky operation
rm -rf ./important_folder
# Make rm interactive by default
alias rm='rm -i'
# Require verbose output for dangerous operations
alias rm='rm -iv'
alias mv='mv -iv'
alias cp='cp -iv'
# Prevent recursive operations on root
alias rm='rm --preserve-root'
# Add confirmation for rf
rmrf() {
echo "โ ๏ธ About to delete: $@"
echo "Files: $(find "$@" -type f 2>/dev/null | wc -l)"
read -p "Are you sure? (yes/no) " confirm
if [ "$confirm" = "yes" ]; then
rm -rf "$@"
else
echo "Aborted"
fi
}
# Safe delete with trash support
safe_delete() {
local target="$1"
local trash_dir="${HOME}/.local/share/Trash/files"
if [ ! -e "$target" ]; then
echo "Error: $target does not exist"
return 1
fi
# Show what will be deleted
echo "Target: $(realpath "$target")"
if [ -d "$target" ]; then
echo "Type: Directory"
echo "Files: $(find "$target" -type f | wc -l)"
echo "Size: $(du -sh "$target" | cut -f1)"
else
echo "Type: File"
echo "Size: $(ls -lh "$target" | awk '{print $5}')"
fi
echo ""
read -p "Move to trash? (yes/no) " confirm
if [ "$confirm" = "yes" ]; then
mkdir -p "$trash_dir"
mv "$target" "$trash_dir/$(basename "$target").$(date +%s)"
echo "Moved to trash. Recover from: $trash_dir"
else
echo "Aborted"
fi
}
| Pattern | Risk | Safe Alternative |
|---|---|---|
rm -rf / | System destruction | Never execute |
rm -rf ~ | Home directory loss | Be specific: rm -rf ~/Downloads/temp |
rm -rf * | Current directory wipe | List files explicitly |
rm -rf . | Current directory wipe | rm -rf ./specific-folder |
rm -rf .. | Parent directory wipe | Never use |
mv * /dev/null | Data loss | Use specific file names |
> important_file | File content wipe | Check file existence first |
# Check trash first (macOS/Linux with trash-cli)
ls ~/.Trash/ # macOS
ls ~/.local/share/Trash/files/ # Linux
# For recent deletions, check backup
ls ~/Dropbox/ # If using cloud backup
ls ~/.snapshots/ # If using Time Machine or snapshots
# For Git-tracked files
git checkout -- deleted_file
git restore deleted_file
# For untracked files in Git directory
# Unfortunately, mostly unrecoverable
# Prevention is the only cure
| DO | DON'T |
|---|---|
Verify path with realpath first | Trust relative paths |
Preview with ls before rm | Use wildcards blindly |
Use -i flag for interactive | Auto-confirm everything |
| Backup before bulk operations | Assume recovery is possible |
| Move to trash instead of delete | Use rm -rf casually |
| Use explicit file lists | Use * in dangerous commands |
| Double-check working directory | Run commands from wrong location |
Before any deletion:
realpath or pwdls or findecho first