Project Cleaner & Janitor
When to use this skill
- •When the user explicitly asks to "clean up unused files" or "delete dead code".
- •Post-refactoring, to remove old implementations.
- •When the project feels "bloated" with temporary files.
Workflow
1. The Scan (Dry Run)
Do not delete anything yet.
- •Junk Pattern Scan: Look for common temporary/system files:
- •
.DS_Store,Thumbs.db,.logfiles (root),.tmpfiles. - •Empty Directories: Find folders with no content.
- •
- •Orphan File Scan (Static Analysis):
- •Identify all source files (ts, js, dart, py).
- •Checks if each file is imported by at least one other file in the project.
- •Exclusion: Ignore "entry points" (e.g.,
main.tsx,page.tsx,index.js,app.py) as they are rarely imported but essential.
- •Dead Code Scan:
- •Identify exported functions/constants that are never imported.
- •Note: This is complex to do perfectly with regex. If using a language server (LSP) is possible, use it. Otherwise, rely on reliable grep/ripgrep searches.
2. The Report
Present the findings to the user in a clear list:
markdown
### 🧹 Cleaning Report **Junk Files (Safe to delete):** - `.DS_Store` - `npm-debug.log` **Orphan Files (No imports found):** - `src/components/OldButton.tsx` (CAUTION: Is this an entry point?) - `utils/unused_helper.js` **Empty Folders:** - `src/features/old_feature/`
3. The Confirmation
Ask: "Do you want me to proceed with deleting the Junk Files? What about the Orphan Files?"
4. The Action
Only after receiving "Yes" or specific instructions (e.g., "Delete junk, keep orphans"):
- •Run the deletion commands.
- •(Optional) If it was dead code removal within a file, edit the file to remove the unused block.
Instructions
Tools to Use
- •
find: For empty directories (find . -type d -empty). - •
fd/find: For pattern matching junk files. - •
grep/ripgrep: For checking imports.- •Heuristic: To check if
OldButton.tsxis used, search forOldButtonstring in the wholesrc/directory. If count is 1 (the definition itself), it's likely unused.
- •Heuristic: To check if
Safety Rules
- •Never delete
node_modules/,.git/,.next/,build/manually. (Use standard clean commands for those). - •Always respect
.gitignore. - •Backup Strategy: If the user is unsure, offer to move files to a
_deprecated/folder instead of permanent deletion.
Self-Correction Checklist
- •"Did I assume this file is unused just because I didn't see an import?" -> Check if it's a Next.js Page (
page.tsx) or API route. THESE ARE NEVER IMPORTED. Whitelist them. - •"Am I about to delete a configuration file?" -> Whitelist
*.config.js,Dockerfile,.env*.