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
Claude Instructions
At Session Start
- Read
CODE_INDEX.mdif it exists - Note the categories and key functions available
- Keep this context for the session
Before Writing New Code
- Pause and check: "Does something like this exist?"
- Search CODE_INDEX.md for similar capabilities
- If unsure, search the codebase:
grep -r "functionName\|similar_term" src/ - Only create new if confirmed nothing suitable exists
After Writing New Code
- Immediately update CODE_INDEX.md
- Add file header if new file
- Add function docstring
- Commit index update with code


