name: code-janitor description: Scan source code for dead code, duplicate logic, zombie functions, and semantic clones. AI-powered code cleanup recommendations. trigger: /janitor
Code Janitor
Detects dead code, duplicate logic, and zombie patterns in JavaScript/TypeScript projects.
Commands
/janitor scan [path] -- Full scan of project (default: current dir)
/janitor scan --layer=dead -- Dead code detection only (wraps Knip)
/janitor scan --layer=clones -- Clone detection only (wraps jscpd)
/janitor scan --layer=zombie -- Zombie logic patterns only
/janitor scan --layer=semantic -- Semantic clone detection (LLM-assisted)
/janitor report [path] -- Generate markdown report from last scan
Instructions
When the user invokes /janitor scan, follow this flow:
1. Detect Project Type
- Check for
package.json,tsconfig.jsonin the target path - Identify JS/TS project structure
2. Layer 1: Dead Code (--layer=dead)
- Run:
npx knip --reporter json 2>/dev/null - If knip not installed, run
npx knip(npx auto-installs) - Parse JSON output for unused exports, files, dependencies
- If knip fails or is unavailable, skip this layer with a note
3. Layer 2: Clone Detection (--layer=clones)
- Run:
npx jscpd --reporters json --output /tmp/janitor-clones/ [path] 2>/dev/null - Parse JSON output for Type 1-3 code clones
- If jscpd fails or is unavailable, skip this layer with a note
4. Layer 3: Zombie Logic (--layer=zombie)
- Run:
node /Users/rafiimanggalajapamel/.claude/skills/code-janitor/zombie-scanner.mjs [path] - Detects: empty catch blocks, console.log debris, no-op functions, commented-out code, unreachable code after return, TODO/FIXME markers
- Always available (zero dependencies)
5. Layer 4: Semantic Clones (--layer=semantic)
- Run:
node /Users/rafiimanggalajapamel/.claude/skills/code-janitor/function-extractor.mjs [path] - Pipe output to:
node /Users/rafiimanggalajapamel/.claude/skills/code-janitor/similarity.mjs - Review top candidate pairs yourself (Claude) and judge if they are semantically equivalent
- This layer is optional and LLM-assisted
6. Aggregate Results
- Pipe all layer outputs as JSON to:
node /Users/rafiimanggalajapamel/.claude/skills/code-janitor/reporter.mjs - Input format:
{"project":"name","scannedAt":"ISO","dead":{...},"clones":{...},"zombie":{...},"semantic":{...}} - Output: formatted markdown report
7. Present Report
- Show the markdown report to the user
- Highlight high-severity findings first
- Offer to help fix specific findings
Default Scan
When no --layer is specified, run all layers sequentially (1-4) and aggregate.
Path Handling
- Default path: current working directory
- Skip: node_modules, .git, dist, build, coverage, .next, .nuxt
Notes
- All scanner scripts are zero-dependency (Node.js stdlib only)
- Zombie scanner and function extractor work via regex (no tree-sitter needed)
- Layer 4 (semantic) requires Claude judgment for final determination
Related skills
Next.js App Router Expert
Development
A skill that turns Claude into a Next.js App Router expert.
Claude CodeCursoradvanced
890
234
3,222
README Generator
Development
Creates professional and comprehensive README.md files for your projects.
claudeCursorWindsurfbeginner
259
72
1,128
API Documentation Writer
Development
Generates comprehensive API documentation in OpenAPI/Swagger format.
claudeCursorWindsurfintermediate
156
44
996