| name | finding-duplicate-functions |
| description | Use when auditing a codebase for semantic duplication — functions that do the same thing but have different names or implementations, especially common in LLM-generated codebases |
| when_to_use | after syntactic duplicate detection (jscpd), during codebase audits, or before major refactoring to find consolidation opportunities |
| version | 1.0.0 |
| category | debugging |
| author | Jesse Vincent |
| license | MIT |
| source | https://github.com/obra/superpowers-lab/tree/main/skills/finding-duplicate-functions |
| tags | ["debugging","refactoring","duplication","code-quality","analysis"] |
| effort | medium |
Finding Duplicate-Intent Functions
Overview
LLM-generated codebases accumulate semantic duplicates: functions that serve the same purpose but were implemented independently. Classical copy-paste detectors (jscpd) find syntactic duplicates but miss "same intent, different implementation."
This skill uses a two-phase approach: classical extraction followed by LLM-powered intent clustering.
When to Use
- Codebase has grown organically with multiple contributors (human or LLM)
- You suspect utility functions have been reimplemented multiple times
- Before major refactoring to identify consolidation opportunities
- After jscpd has been run and syntactic duplicates are already handled
Quick Reference
| Phase | Tool | Model | Output |
|---|
| 1. Extract | Extract function catalog | - | catalog.json |
| 2. Categorize | Categorize by domain | haiku model | categorized.json |
| 3. Split | Split by category | - | categories/*.json |
| 4. Detect | Find duplicates per category | opus model | duplicates/*.json |
| 5. Report | Generate prioritized report | - | report.md |
Process
Phase 1: Extract Function Catalog
Extract all functions from source files. Focus on:
- Exported functions and public methods
- Files in utility/helper directories
- Excluding test files (
*.test.*, *.spec.*, __tests__/**)
For each function capture:
- Function name and signature
- File path and location
- ~15 lines of context (enough to understand intent)
Phase 2: Categorize by Domain
Dispatch a haiku subagent to categorize functions by domain.
Insert the function catalog into the prompt. Save output as categorized.json with functions grouped into domains like:
- String manipulation
- Validation
- Path operations