finding-duplicate-functions — скилл для Claude Code: что делает
Находит функции с одинаковым смыслом, но разными названиями и кодом. Помогает расчистить утилиты и хелперы в репозиториях, которые писали разные люди или нейросети.
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a claude-codeЧто делает finding-duplicate-functions
Скилл ищет скрытые смысловые дубли в коде на TypeScript и JavaScript. Обычные утилиты вроде jscpd ловят прямой копипаст, но пропускают ситуации, когда разные разработчики или нейросети пишут одинаковый хелпер с нуля под другим именем. Процесс начинается со скрипта ./scripts/extract-functions.sh. Он собирает каталог функций с контекстом в 15 строк и отсекает тестовые файлы вроде *.test.* и __tests__/**.
Дальше в дело вступают две модели. Для экономии токенов первичную сортировку по доменам делает быстрая Haiku по шаблону scripts/categorize-prompt.md. Затем скрипт делит функции по папкам, отбирая группы от трёх штук. Сам поиск дублей внутри каждой категории автор доверяет исключительно Opus. Haiku на этом шаге пропускает неочевидные совпадения логики. Итог работы сводится в отчёт duplicates-report.md с группировкой по уровню уверенности.
Удалять найденные дубликаты вслепую опасно. Перед удалением кода обязательно нужно проверить тесты у оставленной базовой функции и переписать места вызовов.
Какие задачи решает
- найти хелперы с одинаковым назначением и разным кодом
- собрать каталог экспортированных функций без захвата тестов
- сгруппировать методы по предметным областям
- сформировать отчёт по смысловым дублям для рефакторинга
Примеры запросов агенту
- Запусти аудит кодовой базы на скрытые дубликаты функций с помощью finding-duplicate-functions
- Выдели общие функции в src/ и проверь их на смысловые повторы через finding-duplicate-functions
Как установить finding-duplicate-functions
1Через Skills CLI (Vercel)
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a claude-code2Вручную: положить файлы
~/.claude/skills/finding-duplicate-functions/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/finding-duplicate-functions/
1Через Skills CLI (Vercel)
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a codex2Вручную: положить файлы
.agents/skills/finding-duplicate-functions/SKILL.mdДля всех проектов — ~/.agents/skills/
1Через Skills CLI (Vercel)
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a cursor2Вручную: положить файлы
.cursor/skills/finding-duplicate-functions/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1GitHub CLI
gh skill install obra/superpowers-lab finding-duplicate-functions2Вручную: положить файлы
.github/skills/finding-duplicate-functions/SKILL.md1Через Skills CLI (Vercel)
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a gemini-cli2Командой платформы
gemini skills install https://github.com/obra/superpowers-lab --path skills/finding-duplicate-functionsВручную: положить файлы
.devin/skills/finding-duplicate-functions/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Через Skills CLI (Vercel)
npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a opencodeClaude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов
Вопросы о finding-duplicate-functions
Как установить finding-duplicate-functions в Claude Code?
Выполните в терминале команду npx skills add obra/superpowers-lab --skill finding-duplicate-functions -a claude-code.
Что делает finding-duplicate-functions?
Скилл извлекает функции из проектов на JS и TS, разбивает их по категориям с помощью Haiku и находит скрытые логические повторы моделью Opus. Результат оформляется в Markdown-отчёт.
Почему для поиска дублей используются две разные модели?
Haiku дешевле и быстрее распределяет функции по доменам, но пропускает тонкие семантические совпадения. Глубокий анализ дубликатов требует точности Opus, поэтому тяжёлую проверку поручают именно ей.
Исходный текст
SKILL.md · MIT
---
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 useful for LLM-generated codebases where new functions are often created rather than reusing existing ones.
---
# 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 | `scripts/extract-functions.sh` | - | `catalog.json` |
| 2. Categorize | `scripts/categorize-prompt.md` | haiku | `categorized.json` |
| 3. Split | `scripts/prepare-category-analysis.sh` | - | `categories/*.json` |
| 4. Detect | `scripts/find-duplicates-prompt.md` | opus | `duplicates/*.json` |
| 5. Report | `scripts/generate-report.sh` | - | `report.md` |
## Process
```dot
digraph duplicate_detection {
rankdir=TB;
node [shape=box];
extract [label="1. Extract function catalog\n./scripts/extract-functions.sh"];
categorize [label="2. Categorize by domain\n(haiku subagent)"];
split [label="3. Split into categories\n./scripts/prepare-category-analysis.sh"];
detect [label="4. Find duplicates per category\n(opus subagent per category)"];
report [label="5. Generate report\n./scripts/generate-report.sh"];
review [label="6. Human review & consolidate"];
extract -> categorize -> split -> detect -> report -> review;
}
```
### Phase 1: Extract Function Catalog
```bash
./scripts/extract-functions.sh src/ -o catalog.json
```
Options:
- `-o FILE`: Output file (default: stdout)
- `-c N`: Lines of context to capture (default: 15)
- `-t GLOB`: File types (default: `*.ts,*.tsx,*.js,*.jsx`)
- `--include-tests`: Include test files (excluded by default)
Test files (`*.test.*`, `*.spec.*`, `__tests__/**`) are excluded by default since test utilities are less likely to be consolidation candidates.
### Phase 2: Categorize by Domain
Dispatch a **haiku** subagent using the prompt in `scripts/categorize-prompt.md`.
Insert the contents of `catalog.json` where indicated in the prompt template. Save output as `categorized.json`.
### Phase 3: Split into Categories
```bash
./scripts/prepare-category-analysis.sh categorized.json ./categories
```
Creates one JSON file per category. Only categories with 3+ functions are worth analyzing.
### Phase 4: Find Duplicates (Per Category)
For each category file in `./categories/`, dispatch an **opus** subagent using the prompt in `scripts/find-duplicates-prompt.md`.
Save each output as `./duplicates/{category}.json`.
### Phase 5: Generate Report
```bash
./scripts/generate-report.sh ./duplicates ./duplicates-report.md
```
Produces a prioritized markdown report grouped by confidence level.
### Phase 6: Human Review
Review the report. For HIGH confidence duplicates:
1. Verify the recommended survivor has tests
2. Update callers to use the survivor
3. Delete the duplicates
4. Run tests
## High-Risk Duplicate Zones
Focus extraction on these areas first - they accumulate duplicates fastest:
| Zone | Common Duplicates |
|------|-------------------|
| `utils/`, `helpers/`, `lib/` | General utilities reimplemented |
| Validation code | Same checks written multiple ways |
| Error formatting | Error-to-string conversions |
| Path manipulation | Joining, resolving, normalizing paths |
| String formatting | Case conversion, truncation, escaping |
| Date formatting | Same formats implemented repeatedly |
| API response shaping | Similar transformations for different endpoints |
## Common Mistakes
**Extracting too much**: Focus on exported functions and public methods. Internal helpers are less likely to be duplicated across files.
**Skipping the categorization step**: Going straight to duplicate detection on the full catalog produces noise. Categories focus the comparison.
**Using haiku for duplicate detection**: Haiku is cost-effective for categorization but misses subtle semantic duplicates. Use Opus for the actual duplicate analysis.
**Consolidating without tests**: Before deleting duplicates, ensure the survivor has tests covering all use cases of the deleted functions.
© obra · MIT · obra/superpowers-lab