skills/code-quality/cleanup-dedupe/SKILL.md
Detect duplicated code blocks and refactor to DRY where it reduces complexity. Runs jscpd (multi-language), filters by signal-to-noise, and auto-extracts only token-identical blocks ≥30 LOC. Use when the user asks to deduplicate, DRY up, find copy-paste, or consolidate repeated logic.
npx skillsauth add raintree-technology/claude-starter cleanup-dedupeInstall 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.
Find duplicated code and consolidate where it reduces complexity. Auto-extract only token-identical, sizeable blocks. Smaller or divergent duplicates often shouldn't be DRY'd — premature abstraction is worse than 3 similar lines.
.claude/cleanup-reports/ exists.lib/, utils/, shared/, common/, package directories. Extracted code goes there.# jscpd - the standard for cross-language clone detection
npx jscpd --min-tokens 70 --min-lines 30 --threshold 0 --reporters json --output /tmp/jscpd-out .
Parse /tmp/jscpd-out/jscpd-report.json. Each duplication entry has firstFile, secondFile, lines, tokens, and the actual fragment.
Filter the noise before further analysis:
node_modules/, dist/, build/, .next/, __generated__/, *.generated.*.cleanup-types.Write .claude/cleanup-reports/cleanup-dedupe-{YYYY-MM-DD}.md:
# Duplication Assessment — YYYY-MM-DD
## Summary
- Total clones found: N (after filtering noise)
- HIGH confidence (auto-extractable): X
- MEDIUM (similar but divergent): Y
- LOW (structural similarity, intentional): Z
- Estimated LOC saved (HIGH only): ~N
## Clones
### Clone 1 — HIGH (extract to `packages/utils/src/format.ts`)
- Files: `apps/app/features/holdings/format.ts:15-67`, `apps/admin/features/users/format.ts:22-74`
- 52 lines, 380 tokens, identical
- Both implement `formatCompactNumber(n: number): string`
- Extract to: `packages/utils/src/formatCompactNumber.ts`, both sites import.
### Clone 2 — MEDIUM
- Files: A and B
- Similar structure but divergent in 3 spots — the formatting differs by locale, the rounding by precision.
- Recommendation: don't extract yet — the abstraction needs a parameterization design that the human should decide.
## Critical Assessment
[2-3 paragraphs: are duplicates concentrated in one area? Is there a missing shared package? Are the duplicates a sign that an early abstraction would have been wrong, OR that a missing abstraction is hurting?]
Auto-extract HIGH-confidence only.
HIGH (auto-apply):
MEDIUM (report only):
LOW (note, no action):
lib/ or utils/ directory.packages/utils/), else escalate to MEDIUM (don't auto-create new packages).chore(cleanup): cleanup-dedupe — extracted N shared utilities.npm run check 2>&1 || (npx tsc --noEmit && npx eslint .)
npm test 2>&1 || pytest 2>&1
# Re-run jscpd to confirm reduction
npx jscpd --min-tokens 70 --min-lines 30 . 2>&1
If verify fails: revert and downgrade all to MEDIUM.
.d.ts/migration files.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.