Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

dry-consolidation

БесплатноБез исполняемых скриптовНе проверен

Find and extract duplicated code into shared abstractions. Use when seeing repeated utilities, copy-pasted components, duplicated hooks, or boilerplate…

laurigatesот 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 to src/)
  • --scope: Focus on a specific extraction type: utilities, components, hooks, or all (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:

  1. Use Grep to find repeated function names, variable patterns, and import clusters
  2. Use Glob to identify files with similar structure (e.g., all *List.tsx, all *Detail.tsx)
  3. 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

Полный SKILL.md на GitHub

Установить dry-consolidation в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Write
Edit
Grep
Glob
Bash(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

Вложенные файлы

references/agentic-optimizations.mdreferences/clone-report.mdreferences/duplication-signals.mdreferences/output-summary.mdreferences/related.mdreferences/test-and-verify.md

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), без исполняемых скриптов.

Похожие скиллы

Сравнить dry-consolidation с