/code-quality-plugin:dry-consolidation path or directory to scan for duplicationfrom code-quality-plugin
Finds and extracts duplicated code into shared abstractions. Use when seeing repeated utilities, copy-pasted components, duplicated hooks, or boilerplate across files.
Ships in code-quality-plugin. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Systematic extraction of duplicated code into shared, tested abstractions.
| 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 |
echo "$1"find . -maxdepth 1 \( -name "package.json" -o -name "Cargo.toml" -o -name "pyproject.toml" -o -name "go.mod" \)find . -maxdepth 1 -type d \( -name "src" -o -name "lib" -o -name "app" -o -name "components" -o -name "packages" \)find . -maxdepth 2 \( -name "vitest.config.*" -o -name "jest.config.*" -o -name "pytest.ini" -o -name "conftest.py" \)find . \( -path "*/lib/*" -o -path "*/utils/*" -o -path "*/shared/*" -o -path "*/common/*" -o -path "*/hooks/*" \) -type f -print -quit$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 changesExecute 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.
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.
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.
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.)
When npx/jscpd is unavailable, or the ecosystem has no npx on PATH, fall back to agent-driven text search:
*List.tsx, all *Detail.tsx)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.
Group discovered duplications into extraction categories:
| Category | Extract Into | Location Convention |
|---|---|---|
| Utilities | Pure functions | src/lib/utils/ or src/utils/ |
| Components | Shared UI components | src/components/ui/ or src/components/shared/ |
| Hooks | Custom React/Vue hooks | src/hooks/ or src/composables/ |
| Types | Shared type definitions | src/types/ or alongside the abstraction |
Follow the project's existing conventions for shared code location. If no convention exists, propose one based on the framework.
For each duplication cluster, plan the extraction:
Present the plan to the user before proceeding (unless --dry-run was not specified and the scope is clear).
Plan format:
## Extraction Plan
### 1. [Abstraction Name] → [target file path]
- Type: utility | component | hook
- Replaces: [N] identical blocks across [M] files
- Consumers: [list of files]
- Parameters: [any variations that need to be parameterized]
- Duplicated: [N] tokens / [N] lines (from jscpd; blank when the Grep fallback was used)
- Similarity: [N]% (from jscpd; "exact" when ast-grep-confirmed as the same shape)
- Estimated lines saved: [N]
The Duplicated and Similarity fields come from jscpd's report (tokens/lines per clone, and the cluster's percentage) — a quantified --dry-run report instead of a best-effort narrative. When the Grep fallback (1c) supplied the cluster, leave them blank or note "grep-estimated".
Execute each planned extraction:
Extraction order: Start with utilities (no dependencies), then components, then hooks (may depend on utilities/components).
Mark each extraction as completed in the tracker before moving to the next.
Write tests for each extracted abstraction:
Pick the test approach per abstraction type (utility, component, hook, types) from references/test-and-verify.md.
Place test files adjacent to the abstraction or in the project's test directory, following existing conventions.
After all extractions are complete:
Run the full verification suite:
Run type checking, linting, and the full test suite with the project's tools — the TypeScript/JavaScript, Python, and Rust command sets are in references/test-and-verify.md.
All three must pass. If any fail, fix the issues before reporting completion.
After all phases complete, report using the summary template in references/output-summary.md.
Compact command forms (clone scan, shape confirm, scoped runs, fast verify) are in references/agentic-optimizations.md.
Sibling skills (/code:refactor, /code:antipatterns, ast-grep-search) and follow-ups
(/code:dead-code, /code:complexity) are listed in references/related.md.
references/agentic-optimizations.md (opens in a new tab)references/clone-report.md (opens in a new tab)references/duplication-signals.md (opens in a new tab)references/output-summary.md (opens in a new tab)references/related.md (opens in a new tab)references/test-and-verify.md (opens in a new tab)scripts/tests/test-dry-consolidation.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
opusgeneral-purpose), in the backgroundnpx claudepluginhub laurigates/claude-plugins --plugin code-quality-plugin19 skills in this plugin
/ast-grep-searchFind and replace code patterns structurally with ast-grep. Use when matching code by AST structure, finding functions with specific signatures, or detecting anti-patterns regex cannot match./bulk-sweep-classifyClassify every regex match before a bulk find-replace/syntax-modernization sweep — four match categories, scoped transform, allowlist-aware verification. Use when bulk-renaming commands/tools/paths or migrating syntax across many files./code-antipatternsAnalyze a codebase for anti-patterns using ast-grep. Use when finding magic numbers, console.logs, var usage, excessive any, eval/innerHTML security issues, or deep nesting./code-complexityAnalyze code complexity metrics (cyclomatic, cognitive, function length, coupling). Use when identifying refactoring targets, tracking codebase health, or reviewing large changes./code-context-leakageAudit a repo for names and defaults tied to one person's setup — home paths, personal channels, dated tags, OS-only commands, stale repo names. Use when preparing a project for reuse./code-dead-codeDetect dead code, unused exports, unreachable branches, and orphaned files. Use when reducing maintenance burden, cleaning up after refactors, or auditing codebase health.Other plugins' skills for the same job