code-deduplication
Prevent semantic code duplication with capability index and check-before-write
By alinaqi · 527 installs
npx skills add alinaqi/maggy --skill code-deduplication
Source repository · Upstream listing
Code Deduplication Skill
Purpose: Prevent semantic duplication and code bloat. Maintain a capability index so Claude always knows what exists before writing something new.
Core Philosophy
Code Index Structure
Maintain CODE INDEX.md in project root, organized by capability not file location:
File Header Format
Every file should have a summary header:
TypeScript/JavaScript
Python
Function Documentation
Every function needs a one line summary:
TypeScript
Python
Check Before Write Process
Before Creating ANY New Function
Decision Tree
Common Duplication Patterns
Pattern 1: Utility Function Reimplementation
❌ Bad: Creating validateEmail() when isEmail() exists
✅ Good: Check index first, use existing
Pattern 2: Slightly Different Versions
❌ Bad: Multiple date formatters with slight variations
✅ Good: One function with options
Pattern 3: Inline Logic That Should Be Extracted
❌ Bad: Same validation logic scattered across files
✅ Good: Extract once, import everywhere
Periodic Audit
Run /audit duplicates periodically to catch semantic overlap:
Audit Checklist
[ ] Utility functions : Any functions doing similar things?
[ ] API calls : Multiple ways to fetch same data?
[ ] Validation : Scattered inline validation logic?
[ ] Error handling : Inconsistent error patterns?
[ ] Components : Similar UI components that could merge?
[ ] Hooks : Custom hooks with overlapping logic?
Audit Output Format
Vector DB Integration (Optional)
For large codebases (100+ files), add vector search:
Setup with ChromaDB
Setup with LanceDB (Lighter)
When to Use Vector DB
Codebase Size Recommendation
< 50 files Markdown index only
50 200 files Markdown + periodic audit
200+ files Add vector DB
500+ files Vector DB essential
Claude Instructions
At Session Start
1. Read CODE INDEX.md if it exists
2. Note the categories and key functions available
3. Keep this context for the session
Before Writing New Code
1. Pause and check : "Does something like this exist?"
2. Search CODE INDEX.md for similar capabilities
3. If unsure, search the codebase: grep r "functionName\ similar term" src/
4. Only create new if confirmed nothing suitable exists
After Writing New Code
1. Immediately update CODE INDEX.md
2. Add file header if new file
3. Add function docstring
4. Commit index update with code
When User Says "Add X functionality"
Quick Reference
Update Index Command
Audit Command
File Header Template
Function Template
Index Entry Template