From grimoire
Detects and consolidates duplicated code, logic, data, or knowledge across a codebase following the DRY principle.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:apply-dry-principleThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Every piece of knowledge must have a single, authoritative representation in the system.
Every piece of knowledge must have a single, authoritative representation in the system.
Adopted by: Industry-universal. Codified in "The Pragmatic Programmer" (500k+ copies sold), cited in Google Engineering Practices, Microsoft internal style guides, and Stripe's engineering handbook. No top-tier engineering org advocates for deliberate duplication. Impact: Every duplicated piece of knowledge is a latent defect — a future change must be applied N times, and the probability of missing one instance scales with N. DRY reduces the change surface proportionally. In large codebases, duplicated business logic is the leading cause of behavioral divergence between services. Why best: DRY addresses knowledge duplication, not just code copy-paste. A business rule encoded in a database constraint, an API validator, and a frontend form is triplicated knowledge — changing the rule requires three coordinated edits, each a defect opportunity. WET (Write Everything Twice) produces inconsistency at scale.
Sources: Hunt & Thomas, "The Pragmatic Programmer" ch. 7 (The Evils of Duplication); Google Engineering Practices; Martin Fowler, "Refactoring" (2018 ed.), ch. 3
| Type | Example | Risk |
|---|---|---|
| Code | Same function copy-pasted | Low — caught by linters |
| Data | Magic number repeated | Medium — one instance gets updated |
| Logic | Business rule in 3 places | High — behavioral drift |
| Knowledge | Same concept with different names | Critical — silent divergence |
Ask: "If this knowledge changes, what is the ONE place I'd update?" That location should be the source of truth. Everything else should reference it.
Match the extraction scope to the duplication scope:
| Duplication scope | Extraction |
|---|---|
| Within a function | Named constant or local variable |
| Within a module | Private function |
| Across modules in a service | Shared utility / helper |
| Across services | Shared library, schema registry, or API contract |
| Across frontend and backend | Code generation from a single schema (e.g., OpenAPI, Protobuf) |
Replace every occurrence with a reference to the extracted source. Verify with grep or your IDE's find-all-references — missing one instance recreates the problem.
Make a hypothetical change: "If this knowledge changes, how many edits are required?" The answer should be exactly one. If it's more, the extraction is incomplete.
Abstracting coincidental similarity. Two functions that compute totals for orders and invoices look the same today. Next quarter, order totals add tax; invoice totals don't. Premature merging forces an ugly split or a flag parameter.
DRY the wrong layer. Deduplicating SQL queries by sharing a query builder object couples unrelated features. The duplication was in SQL text, not in knowledge.
Forgetting knowledge duplication across systems. API documentation that duplicates the API implementation is duplicated knowledge — use code generation or contract-first design to keep one authoritative source.
npx claudepluginhub jeffreytse/grimoire --plugin grimoireEnforces universal code quality rules — KISS, DRY, clean code, code review. Use when writing or reviewing any code.
Extracts duplicated code into shared utilities, components, hooks, and modules from repeated patterns across files like identical functions, UI blocks, state management, or boilerplate.
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.