Agent skill
safe-file-ops
Safely delete and manage files and folders. Uses git rm for git-tracked files, moves other files to .trash directory. Automatically applied when deletion operations are needed.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/safe-file-ops
SKILL.md
Safe File Operations
Purpose
A skill for safely deleting files and folders. Git-tracked files are removed using git rm for safe version control removal, while non-tracked files are moved to the .trash directory for possible recovery.
Core Principles
- Git-tracked files: Use
git rmfor safe deletion (maintains version history) - Non-tracked files: Move to
.trash/directory (recoverable) - Safety: Never permanently delete - keep in trash for recovery
- Auto-detection: Automatically detect if files are git-tracked
Use Cases
- When you need to delete files or folders
- When cleaning up folders that are no longer needed
- When deleting a mix of git-tracked and non-tracked files
Workflow
Step 1: Collect File/Folder List
Confirm the paths of files or folders the user wants to delete:
Please provide the paths of files or folders you want to delete.
(e.g., src/old-component.ts, tests/deprecated/, docs/draft.md)
Step 2: Check Git Tracking Status
Check if each file/folder is tracked by Git:
# Check if file is tracked by git
git ls-files --error-unmatch <filepath>
# Check git-tracked files in folder
git ls-files <folderpath>
Step 3: Separate Handling
Git-tracked files:
# Delete file (remove from staging area)
git rm <filepath>
# Delete folder (recursively)
git rm -r <folderpath>
Non-tracked files:
# Create .trash directory (if not exists)
mkdir -p .trash
# Move file (avoid path conflicts)
mv <filepath> .trash/
# Move folder
mv <folderpath> .trash/
Step 4: Report Summary
Report the list of processed files and their locations:
✅ Git-tracked files (deleted with git rm):
- src/old-component.ts
- lib/deprecated/
✅ Non-tracked files (moved to .trash/):
- cache/temp.dat
- logs/old-logs/
📁 All preserved files: .trash/
Examples
Example 1: Delete Single File
# Input: "Delete src/utils/legacy.ts"
# Check git status
$ git ls-files --error-unmatch src/utils/legacy.ts
src/utils/legacy.ts # Git-tracked file confirmed
# Execute deletion
$ git rm src/utils/legacy.ts
rm 'src/utils/legacy.ts'
✅ Removed src/utils/legacy.ts from git.
Example 2: Delete Mixed Files/Folders
# Input: "Delete build/ folder and temp.dat file"
# Check git status
$ git ls-files build/
build/index.html # Git-tracked
build/bundle.js # Git-tracked
$ git ls-files --error-unmatch temp.dat
# (No output - non-tracked file)
# Separate handling
$ git rm -r build/
$ mkdir -p .trash
$ mv temp.dat .trash/
✅ Git-tracked files (deleted with git rm):
- build/
✅ Non-tracked files (moved to .trash/):
- temp.dat
Important Notes
- No permanent deletion: All files are kept in recoverable state
- Git commit required: Files deleted with
git rmneed to be committed - .trash management: Periodically cleaning
.trash/directory is recommended - Path conflicts: Files with same name in
.trash/will be overwritten
Clean Up .trash
To empty the .trash directory:
# Completely delete .trash directory
rm -rf .trash/
# Or delete only files older than 30 days
find .trash/ -type f -mtime +30 -delete
Related Operations
- Undo: Recover git-tracked files with
git checkout HEAD -- <file> - Commit: Commit deletions with
git commit -m "Remove old files" - Cleanup: Periodic
.trash/directory cleaning recommended
Reference: This skill is based on Claude Code official Skills documentation. (https://code.claude.com/docs/en/skills)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?