skills/code-quality/cleanup-unused/SKILL.md
Detect and delete unused code, exports, files, and dependencies. Runs knip/vulture/staticcheck/cargo-machete appropriate to the language, writes a critical assessment, and auto-applies HIGH-confidence deletions. Use when the user asks to remove dead code, find unused exports, clean up dependencies, or run dead-code analysis.
npx skillsauth add raintree-technology/claude-starter cleanup-unusedInstall 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.
Detect unused code, exports, files, and dependencies. Auto-delete only what's verifiably dead. Write a critical assessment with confidence ratings; defer ambiguous items to the human.
package.json (TS/JS), pyproject.toml/requirements.txt (Py), go.mod (Go), Cargo.toml (Rust). Skip languages not present.mkdir -p .claude/cleanup-reports/. Add .claude/cleanup-reports/ to .gitignore if not already present.import(, require(, eval(, Function(, __webpack_require__, dynamic route file conventions (pages/, app/)__import__, importlib, getattr, plugin entry-points in setup.py/pyproject.tomlreflect., plugin loader, build tagscfg(feature = ...) gates, proc-macros, extern crateRun the right tool per language. Install on demand only after asking.
# Knip is the gold standard for TS/JS unused-code detection.
npx knip --reporter json > /tmp/knip.json
Parse files, exports, types, dependencies, devDependencies, unlisted, binaries arrays.
uvx vulture . --min-confidence 80 --json > /tmp/vulture.json 2>/dev/null || pipx run vulture . --min-confidence 80
Vulture confidence ≥80 maps roughly to our HIGH; 60-79 = MEDIUM.
go install honnef.co/go/tools/cmd/staticcheck@latest 2>/dev/null
staticcheck -checks=U1000 ./... > /tmp/staticcheck.txt
U1000 = unused code.
cargo install cargo-machete 2>/dev/null
cargo machete --with-metadata > /tmp/machete.txt # unused deps
cargo +nightly udeps 2>/dev/null || true # optional, nightly-only
Use RUSTFLAGS="-W dead_code" and re-build for in-crate dead code if needed.
Write .claude/cleanup-reports/cleanup-unused-{YYYY-MM-DD}.md with:
# Unused Code Assessment — YYYY-MM-DD
## Scope
- Languages detected: [TS, Py, …]
- Tools run: [knip, vulture, …]
- Dynamic-import risk areas: [list paths]
## Summary
- Unused files: N (HIGH: x, MEDIUM: y)
- Unused exports: N (HIGH: x, MEDIUM: y)
- Unused dependencies: N (HIGH: x, MEDIUM: y)
- Total LOC removable (HIGH only): ~N
## Findings
| Conf | Type | Location | Tool said | Recommendation |
|------|------|----------|-----------|----------------|
| HIGH | export | src/utils/foo.ts:12 `parseDate` | knip: unused export | Delete export + function |
| MED | file | src/legacy/old.ts | knip: unused file | Defer — referenced from dynamic import area |
| ...
## Critical Assessment
[2-4 paragraphs of human-readable analysis]
- What patterns emerged? (e.g., "8 of 12 unused exports are in `lib/legacy/` — consider deleting the whole directory")
- Why were items downgraded from HIGH to MEDIUM?
- Architectural observations.
## Out of scope
- [Items the tool flagged but skill won't touch — public API surfaces, framework conventions, etc.]
Auto-apply HIGH-confidence only. Group all deletions into one commit.
HIGH (auto-apply):
index.ts, __init__.py, pub items, package main/exports)MEDIUM (report only, don't apply):
.d.ts consumed externallypeerDependencies or are used by build toolingLOW (note in report, no action):
rm <path> — but verify no .gitignore'd sibling files reference them first.Edit to remove the export keyword + drop the symbol if internal usage is also zero.package-lock.json → npm uninstall, yarn.lock → yarn remove, pnpm-lock.yaml → pnpm remove, bun.lockb → bun remove). For Python: pip uninstall <pkg> / uv remove <pkg> / poetry remove <pkg>. For Rust: cargo remove <pkg>.git add -A && git commit -m "chore(cleanup): cleanup-unused — N items removed".Run all that apply, in order. Halt and revert on first failure.
# Typecheck — prefer the project's typecheck script if defined
npm run typecheck 2>&1 || npx tsc --noEmit
mypy . 2>&1 || true
go build ./... 2>&1
cargo check 2>&1
# Tests (if scripts exist)
npm test 2>&1
pytest 2>&1
go test ./... 2>&1
cargo test 2>&1
# Lint — prefer project's lint script
npm run lint 2>&1 || npx @biomejs/biome check . 2>&1 || npx eslint . 2>&1
ruff check . 2>&1
golangci-lint run 2>&1
cargo clippy 2>&1
If any fail: git revert HEAD --no-edit, downgrade all auto-applied items to MEDIUM in the report, append a "## Verify Failure" section with the error output.
End-of-turn message (≤4 lines):
node_modules/, .next/, dist/, build/, or other generated dirs.drizzle/*.sql, alembic/, migrations/) even if they look unused — they describe history.app/, pages/, Remix routes/, etc.) — those have routing-based dynamic loads.npm install --force or any flag that bypasses lockfile integrity if a dep removal causes resolution issues.development
Whop platform expert for digital products, memberships, and community monetization. Covers memberships API, payments, courses, forums, webhooks, OAuth apps, and checkout integration. Build SaaS, course platforms, and gated communities. Triggers on Whop, memberships, digital products, course platform, community monetization, Whop API, license keys.
development
Token-Oriented Object Notation (TOON) format expert for 30-60% token savings on structured data. Auto-applies to arrays with 5+ items, tables, logs, API responses, database results. Supports tabular, inline, and expanded formats with comma/tab/pipe delimiters. Triggers on large JSON, data optimization, token reduction, structured data, arrays, tables, logs, metrics, TOON.
development
Plaid banking API expert for financial data integration. Covers Plaid Link, Auth (account/routing numbers), Transactions, Identity verification, Balance checking, and webhooks. Build fintech apps with bank connections, ACH transfers, and transaction history. Triggers on Plaid, banking API, Plaid Link, bank connection, ACH, financial data, transaction history.
development
Helius Solana RPC and API expert. High-performance infrastructure for Solana including RPC nodes, DAS API for NFTs/tokens, LaserStream real-time streaming, webhooks, Priority Fee API, Enhanced Transactions, and ZK Compression. Triggers on Helius, Solana RPC, DAS API, Digital Asset Standard, NFT metadata, Solana webhooks, priority fees, LaserStream, ZK compression.