skills/slop-cleanup/SKILL.md
Refactor a codebase to remove AI slop, dead code, weak types, duplication, defensive over-engineering, and legacy cruft using 8 parallel specialized subagents across two cleanup waves. Don't use for adding new features, performance tuning, or security-only audits.
npx skillsauth add luongnv89/skills slop-cleanupInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Aggressively clean up a codebase by eliminating eight distinct categories of code quality problems. Orchestrates eight specialized subagents that each own one cleanup category, so each one stays focused, deep, and fast — and so they can run in parallel on independent slices of the problem.
The philosophy is simple: a clean codebase has one clear way to do each thing. Duplication, weak types, unused code, hidden errors, and legacy fallbacks all create multiple paths where one would do. This skill hunts down those extra paths and removes them.
Before creating/updating/deleting files, sync the current branch with remote:
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"
If the working tree is not clean, stash first, sync, then restore:
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop
If origin is missing, pull is unavailable, or rebase/stash conflicts occur, stop and ask the user before continuing.
This skill deletes and rewrites code aggressively. That is the point. But because deletions are harder to reverse than additions, enforce these gates:
git status is not clean, stop and ask the user to commit or stash.chore/slop-cleanup-YYYYMMDD). Never work directly on main/master.Before starting:
package.json, pyproject.toml, go.mod, Cargo.toml, pom.xml, etc. The subagents tailor tool choices (knip, madge, ts-prune, vulture, ruff, etc.) to the stack.npx. If not, fall back to manual analysis and note this in the report.package.json, Makefile, pyproject.toml, CI configs. These run between phases.Eight specialized subagents, each focused on one cleanup category. They run in two waves because some categories produce findings that others need to reason about. Within a wave, subagents run in parallel.
┌─────────────────────────────────────────────┐
│ Main SKILL (Orchestrator) │
│ - Detect stack & tools │
│ - Create cleanup branch │
│ - Dispatch subagents in waves │
│ - Run tests between waves │
│ - Assemble final report │
└──────────────┬──────────────────────────────┘
│
┌─────────┴──────────┐
│ Wave 1 │ (analyze + narrow edits, run in parallel)
│ │
▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Unused │ │ Circular │ │ Weak │ │ Slop/ │
│ Code │ │ Deps │ │ Types │ │ Comments │
│ (knip) │ │ (madge) │ │ │ │ │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
↓ test + typecheck gate ↓
┌─────────────────────┐
│ Wave 2 │ (structural, needs Wave 1 done first)
│ │
▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ Dedupe/ │ │ Type │ │ Defensive│ │ Legacy/ │
│ DRY │ │ Consol. │ │ Prog. │ │ Deprec. │
└──────────┘ └──────────┘ └──────────┘ └──────────┘
↓ test + typecheck gate ↓
┌──────────────────────┐
│ Report Assembler │
│ SLOP_CLEANUP.md │
└──────────────────────┘
Why two waves? Wave 1 subagents do pure cleanup — removing things that are clearly wrong. Their results shrink the surface area for Wave 2, which restructures what remains (deduplication, type consolidation, legacy collapse). Running Wave 2 first would mean merging duplicates that later get deleted as unused, wasting work.
Each subagent has its own prompt file in agents/. The orchestrator spawns them via the Agent tool (subagent_type: general-purpose) with their prompt file as context.
| # | Wave | Subagent | Prompt file | Scope |
|---|------|----------|-------------|-------|
| 1 | 2 | Deduplicator | agents/deduplicator.md | Extract shared code; apply DRY only where it reduces complexity |
| 2 | 2 | Type Consolidator | agents/type-consolidator.md | Merge duplicate type/interface/struct definitions into shared modules |
| 3 | 1 | Unused Code Killer | agents/unused-code-killer.md | Find and delete unreferenced code using knip/ts-prune/vulture/etc. |
| 4 | 1 | Circular Dep Untangler | agents/circular-dep-untangler.md | Detect and break circular dependencies using madge/dep-cruiser |
| 5 | 1 | Weak Type Strengthener | agents/weak-type-strengthener.md | Replace any/unknown/interface{}/Object with specific types |
| 6 | 2 | Defensive Programming Remover | agents/defensive-programming-remover.md | Remove try/catch, fallbacks, and null-checks that hide errors |
| 7 | 2 | Legacy Code Remover | agents/legacy-code-remover.md | Delete deprecated, fallback, and duplicated-by-migration code paths |
| 8 | 1 | Slop Comment Cleaner | agents/slop-comment-cleaner.md | Remove AI-generated fluff, stubs, work-in-motion comments, LARP |
# Refuse if working tree is dirty
git diff-index --quiet HEAD -- || { echo "Commit or stash changes first"; exit 1; }
# Create cleanup branch
date_tag=$(date +%Y%m%d)
git checkout -b "chore/slop-cleanup-${date_tag}"
Detect the stack (language, package manager, test command, typecheck command) and write a one-line summary the user sees before dispatch begins.
Spawn subagents 3, 4, 5, and 8 in a single turn (multiple Agent tool calls in one message). Each receives:
.slop-cleanup/wave-1/<subagent>.mdWait for all four to finish. Run tests and typecheck. If anything broke, stop and report which subagent's commit introduced the failure (bisect by commit).
Spawn subagents 1, 2, 6, and 7. Same protocol — parallel dispatch, per-category reports at .slop-cleanup/wave-2/<subagent>.md, dedicated commits.
Wait for all four to finish. Run tests and typecheck. Stop on failure.
Read each subagent's category report and produce SLOP_CLEANUP.md at the repo root with this structure:
# Slop Cleanup Report
**Branch:** chore/slop-cleanup-YYYYMMDD
**Commits:** N (list with category and one-line summary)
**Tests:** ✓ passing | **Typecheck:** ✓ clean
## Summary
- Files deleted: N
- Lines removed: N
- Lines added: N
- Types consolidated: N
- Duplicates merged: N
- Try/catch removed: N
- Circular deps broken: N
- Weak types replaced: N
- Slop comments removed: N
## By Category
### 1. Unused Code (subagent 3)
...one-line commit summary, then findings table with file/line/what/why...
### 2. Circular Dependencies (subagent 4)
...
### (etc for all 8 categories)
## Risk Flags
Anything each subagent flagged as "delete at your own risk" (external callers unknown, reflective access, dynamic imports).
## Next Steps
- Review the branch
- Run a full regression suite
- Merge or cherry-pick categories
Show the report path, the branch name, and summarize: "Cleaned up N categories across M files, removed L lines, tests passing on branch X. Review SLOP_CLEANUP.md and merge when ready."
All subagents share these editing conventions:
// removed legacy handler. The git log is the explanation.if (!x) throw check.After each wave and at the end, output a status report in this format:
◆ Wave 1 (step 1 of 3 — parallel cleanup)
··································································
Unused code killer: √ pass (removed 47 symbols, 12 files)
Circular dep untangler: √ pass (broke 3 cycles)
Weak type strengthener: √ pass (replaced 89 anys with specific types)
Slop comment cleaner: √ pass (removed 234 slop comments)
Tests after wave: √ pass
Typecheck after wave: √ pass
____________________________
Result: PASS
◆ Wave 2 (step 2 of 3 — structural consolidation)
··································································
Deduplicator: √ pass (merged 18 duplicate blocks)
Type consolidator: √ pass (moved 23 types to shared/)
Defensive programming remover: × fail — 3 tests broke, reverted
Legacy code remover: √ pass (deleted 2 fallback paths)
Tests after wave: × fail — blocked by defensive remover revert
____________________________
Result: PARTIAL
◆ Final Report (step 3 of 3 — assembly)
··································································
SLOP_CLEANUP.md written: √ pass
All commits have messages: √ pass
Branch pushed: √ pass
Summary delivered to user: √ pass
____________________________
Result: PASS
Use √ for pass, × for fail. Keep the adapted check names specific to what actually ran.
After a full run on a TypeScript monorepo, the final SLOP_CLEANUP.md summary looks like:
# Slop Cleanup Report
**Branch:** chore/slop-cleanup-20260419
**Commits:** 8 (one per category)
**Tests:** passing | **Typecheck:** clean
## Summary
- Files deleted: 12
- Lines removed: 847
- Lines added: 134
- Types consolidated: 9
- Duplicates merged: 23
- Try/catch removed: 17
- Circular deps broken: 4
- Weak types replaced: 61
- Slop comments removed: 198
And the terminal handoff message: "Cleaned up 8 categories across 43 files, removed 847 lines, tests passing on branch chore/slop-cleanup-20260419. Review SLOP_CLEANUP.md and merge when ready."
A run passes when all of the following are true:
chore/slop-cleanup-YYYYMMDD), not on main/master.SLOP_CLEANUP.md report exists and lists per-category counts (files touched, lines removed, deletions skipped).documentation
Manage software releases end-to-end: bump version, generate changelog, tag, push, GitHub release, publish to PyPI/npm. Use when user asks to ship, cut a release, tag a version, or list changes since last tag. Skip routine commits and marketplace publishing.
development
Review UI for usability issues using Steve Krug's principles and produce a scannable report. Use when asked for a usability audit, UX review, or UI feedback on screenshots, URLs, or code. Don't use for visual/brand design critique, accessibility (WCAG) audits, or backend/API review.
development
Validate app/startup ideas with market, feasibility, commercial, and open-source competitor analysis. Use when asked to evaluate, validate, or score a product idea. Don't use for PRDs, go-to-market plans, or investor decks.
testing
Install local-first security hardening: pre-commit secret detection, offline dependency scans, static analysis, reports, and gated free CI. Use when hardening repos or adding security hooks. Don't use for incident response or cloud security reviews.