From code-quality-plugin
Extracts duplicated code into shared utilities, components, hooks, and modules from repeated patterns across files like identical functions, UI blocks, state management, or boilerplate.
How this skill is triggered — by the user, by Claude, or both
Slash command
/code-quality-plugin:dry-consolidationsonnetThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Systematic extraction of duplicated code into shared, tested abstractions.
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 |
| Import blocks are bloated from repeated inline patterns | Linting/formatting issues → /lint:check |
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. Use TodoWrite to track each extraction as a separate task.
Scan the target path for duplicated patterns. Search for these duplication signals:
Identical function bodies:
Grep for function/method signatures that appear in multiple files.
Look for identical multi-line blocks (3+ lines) across files.
Repeated inline patterns:
Search strategy:
*List.tsx, all *Detail.tsx)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]
- Estimated lines saved: [N]
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 todo list before moving to the next.
Write tests for each extracted abstraction:
| Abstraction Type | Test Approach |
|---|---|
| Utility function | Unit tests covering all input variations, edge cases |
| UI component | Render tests, prop variations, accessibility |
| Custom hook | Hook testing with mock dependencies, state transitions |
| Type definitions | Type-level tests if applicable (tsd, expect-type) |
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:
TypeScript/JavaScript projects:
npx tsc --noEmit # Type checking
npm run lint # Linting (or biome/eslint directly)
npm run test # Full test suite
Python projects:
ty check . # Type checking
ruff check . # Linting
pytest # Test suite
Rust projects:
cargo check # Type checking
cargo clippy # Linting
cargo test # Test suite
All three must pass. If any fail, fix the issues before reporting completion.
After all phases complete, report:
## DRY Consolidation Summary
### Extractions
- [Abstraction Name] (type) — replaced N blocks in M files
- ...
### New Files Created
- path/to/new/file.ts — [description]
- ...
### Tests Added
- N tests across M test files
### Net Effect
- ~N lines of duplicated code consolidated
- N reusable abstractions created
- All verified: typecheck + lint + N passing tests
| Context | Approach |
|---|---|
| Quick scan | Use --dry-run to see duplication report without changes |
| Focused extraction | Use --scope utilities to extract only utility functions |
| Large codebase | Scope to specific directory: /code:dry-consolidation src/components/ |
| Post-extraction verify | `npx tsc --noEmit 2>&1 |
| Test run (fast) | npm test -- --bail=1 --reporter=dot for quick pass/fail |
/code:refactor — Functional refactoring of a file or directory (pure functions, immutability, composition)/code:antipatterns — Detection-only analysis for code smellsast-grep-search — Structural code search for finding patternsnpx claudepluginhub laurigates/claude-plugins --plugin code-quality-pluginDetects and consolidates duplicated code, logic, data, or knowledge across a codebase following the DRY principle.
Performs safe refactoring: extract functions/components/hooks/modules/classes, rename/move/restructure symbols/files, inline code, detect dead code/smells using test-driven methods.
Audits and refactors codebases to eliminate duplication in UI components, database schemas, and workflow logic. Use for quick scans after changes or deep audits on bloated codebases post-AI development.