dry-consolidation
БесплатноБез исполняемых скриптовНе проверенFind and extract duplicated code into shared abstractions. Use when seeing repeated utilities, copy-pasted components, duplicated hooks, or boilerplate…
от laurigates★ 61 звезда на GitHubОб этом скилле
DRY Consolidation
Systematic extraction of duplicated code into shared, tested abstractions.
When to Use This Skill
| Use this skill when... | Use these instead when... |
|---|---|
| Multiple files have identical/near-identical code blocks | Single file needs cleanup → /code:refactor |
| Copy-pasted utility functions across components | Looking for anti-patterns without fixing → /code:antipatterns |
| Repeated UI patterns (dialogs, pagination, error states) | Functional refactoring of a file or directory → /code:refactor |
| Duplicated hooks or state management boilerplate | Structural code search only → ast-grep-search |
| Near-duplicate copy-paste with renamed vars needs enumerating (jscpd finds the clusters here) | Matching one known structural pattern → ast-grep-search |
| Import blocks are bloated from repeated inline patterns | Linting/formatting issues → /code:lint |
Context
- Target path: !
echo "$1" - Project type: !
find . -maxdepth 1 \( -name "package.json" -o -name "Cargo.toml" -o -name "pyproject.toml" -o -name "go.mod" \) - Source directories: !
find . -maxdepth 1 -type d \( -name "src" -o -name "lib" -o -name "app" -o -name "components" -o -name "packages" \) - Test framework: !
find . -maxdepth 2 \( -name "vitest.config.*" -o -name "jest.config.*" -o -name "pytest.ini" -o -name "conftest.py" \) - Existing shared utilities: !
find . \( -path "*/lib/*" -o -path "*/utils/*" -o -path "*/shared/*" -o -path "*/common/*" -o -path "*/hooks/*" \) -type f -print -quit
Parameters
$1: Path or directory to scan (defaults tosrc/)--scope: Focus on a specific extraction type:utilities,components,hooks, orall(default:all)--dry-run: Analyze and report duplications without making changes
Execution
Execute this 7-step consolidation workflow. Track each extraction as a separate task with TodoWrite when the session has the task tools (see .claude/rules/agentic-permissions.md § Task-tool availability), otherwise as a checklist in your response.
Step 1: Discover duplicate clusters (deterministic clone detection)
Enumerate duplicate ranges with a deterministic clone detector, then read only the reported ranges — not whole candidate files. This keeps discovery reproducible and cheap. Token-based detection (jscpd) finds copy-paste independent of whitespace/formatting and of the enclosing symbol name — clone pairs a name-based Grep misses when the wrapping function is renamed. ast-grep (1b) then adds tolerance for variables renamed inside the block.
1a. Token-based near-duplicates with jscpd
jscpd is a token-based copy/paste detector that supports 150+ languages despite the "js" in the name; npx runs it with no global install. Run it over the target path:
npx jscpd --reporters json --min-tokens 50 --output /tmp/jscpd-dry --silent <path>
It writes /tmp/jscpd-dry/jscpd-report.json. Read that report and parse its duplicates array — each entry gives the exact file/line ranges of a clone pair plus its size in tokens/lines:
An example of the report shape is in references/clone-report.md.
For each reported clone, Read only the line ranges (Read with offset/limit around start/end) to confirm the duplication and classify it — do not Read whole candidate files. jscpd similarity is high by construction for a reported clone (a --min-tokens match); note the tokens/lines for the Extraction Plan.
1b. Structural confirmation with ast-grep
Once jscpd surfaces a cluster, confirm it is the same shape — same call-shape / same block modulo captured variables — with ast-grep metavariables. $VAR / $INIT match any identifier/expression, so a block differing only in renamed captures still matches:
ast-grep -p 'const $VAR = useState($INIT)' --lang tsx <path>
Use this to separate a genuine extractable duplicate from a coincidental token overlap before planning the extraction. (For a standalone structural search without extraction, use the ast-grep-search skill.)
1c. Graceful fallback (Grep) when the detector is unavailable
When npx/jscpd is unavailable, or the ecosystem has no npx on PATH, fall back to agent-driven text search:
- Use Grep to find repeated function names, variable patterns, and import clusters
- Use Glob to identify files with similar structure (e.g., all
*List.tsx, all*Detail.tsx) - Read candidate files to confirm duplication and measure scope
This fallback has lower recall for near-duplicates (renamed variables, reordered params) — prefer the jscpd path when available, and reserve Grep for when it is not.
The duplication signals both paths feed into Step 2 are listed in references/duplication-signals.md.
Step 2: Classify duplications
Group discovered duplications into extraction categories:
| Category | Extract Into | Location
Установить dry-consolidation в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditGrepGlobBash(npx tsc *)Bash(npm run *)Bash(npm test *)Bash(npx *)Bash(bun *)Bash(pnpm *)Bash(yarn *)Bash(pytest *)Bash(ty *)Bash(ruff *)Bash(cargo *)Bash(ast-grep *)Bash(sg *)TaskВложенные файлы
FAQ
Что делает скилл dry-consolidation?
Find and extract duplicated code into shared abstractions. Use when seeing repeated utilities, copy-pasted components, duplicated hooks, or boilerplate repeated across files.
Как установить скилл dry-consolidation?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл dry-consolidation запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic