dry-and-reuse
Skill1 starsChanged 6 months agoMITView on GitHub
Stops duplication and reinvention — the failure GitClear measures as "rework" (copy-paste up, refactoring down, the signature of AI code with a short shelf life). Use before writing any helper, util, type, constant, or component, and when reviewing a diff for repeated logic. Enforces search-before-build, consolidate- don't-clone, and DRY-as-knowledge (one rule, one authoritative place). Triggers: "is there already a function for this", "this looks duplicated", "DRY this up", "extract the common logic", "we keep rewriting this", before adding any utility.
In this repository9 other files it gives its agents.
- code-smellsSkill
- data-and-state-evolutionSkill
- effects-and-puritySkill
- naming-and-commentsSkill
- production-gradeSkill
- right-sized-designSkill
- robustness-at-boundariesSkill
- supply-chain-hygieneSkill
- trustworthy-testsSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 32
Search before you build: Before writing a helper/util/type/constant, grep the codebase (and the stdlib, and existing deps) for one that …
- Very specific: line 43
Reuse the stdlib first: Don't hand-roll what itertools/lodash/slices/Intl already gives you.
- Very specific: line 45
But don't abstract incidental similarity: If pulling two look-alikes together requires flags and special-cases to keep them apart, they …
- Distinctive: line 61
Before writing: search by intent (what it *does*), not just by name — agents miss existing helpers because they searched for the wrong noun.
- Distinctive: line 86
When the rule changes (say, editors can also edit), you change it once — not hunt three drifted copies.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
dry-and-reuse — search before you build, consolidate before you clone
Purpose: kill the duplication that gives AI code its short shelf life. GitClear's 211M-line study found copy-pasted code now exceeds refactored code for the first time ever, and duplicated blocks rose 8× — because agents reflexively add and almost never move/merge. Duplicated blocks carry 15–50% more defects. The senior move is to find what exists and reuse it.
DRY is about knowledge, not text
The real rule (Pragmatic Programmer): every piece of knowledge has a single, authoritative representation. Two consequences agents get wrong in both directions:
- Two blocks that look alike but encode different decisions are not a DRY violation — don't force them into one abstraction (that's coupling unrelated things).
- One business rule expressed in three places is a violation even if the code looks different each time — that's the dangerous kind, because the copies drift.
Reflex card
- Search before you build. Before writing a helper/util/type/constant, grep the codebase (and the stdlib, and existing deps) for one that already does it. Reuse beats rewrite, every time.
- Consolidate, don't clone. About to copy-paste a block? Extract it to one place and call it twice instead. Copy-paste is a debt you pay at every future change.
- Move/merge, don't only add. The healthiest diffs delete and relocate code as well as adding it. If your change is pure addition and you suspect overlap, look harder. The refactored-to-duplicated ratio is the #1 quality signal.
- One rule, one home. A validation rule, a tax calculation, a status enum, a magic constant — define it once and import it. Never let the same knowledge live in two files.
- Reuse the stdlib first. Don't hand-roll what
itertools/lodash/slices/Intlalready gives you. Reinventing stdlib is DRY slop and a bug farm. - But don't abstract incidental similarity. If pulling two look-alikes together
requires flags and special-cases to keep them apart, they were different rules —
leave them. (Hand the judgment to
craft:right-sized-design.)
Red flags
- A new function whose body you've seen elsewhere in the repo.
- The same constant / regex / URL / status string in 2+ files.
- A block copy-pasted and then lightly edited (the most defect-prone pattern).
- The same business rule (discount, tax, permission check) computed in several places.
- A util that re-implements
groupBy,debounce,chunk,deepEqual, date math, etc. - A "v2" of a function sitting next to "v1" with 90% overlap.
- A diff that only ever adds, never moves or deletes, across a large change.
The procedure
- Before writing: search by intent (what it does), not just by name — agents miss existing helpers because they searched for the wrong noun. Grep for the operation, the constant's value, the rule's keywords.
- On a hit: reuse it. If it's almost right, extend the existing one (carefully, without breaking its other callers) rather than forking a copy.
- On real duplication found in review: extract to a single home (hand the mechanics
to
refactoring-patterns: Extract Function, Pull Up Method, Extract Class). Place the single source where both callers can reach it without creating a bad dependency. - Confirm it's knowledge duplication, not coincidence, before merging — see the "incidental similarity" caveat above.
Inline example
# ❌ Agent clones the rule into a third place
def can_edit(user, doc):
return user.role == "admin" or user.id == doc.owner_id # rule copy #3
# ✅ One authoritative home, reused
# permissions.py
def can_edit(user, doc) -> bool:
"""Single source of truth for edit permission."""
return user.is_admin or user.id == doc.owner_id
# everywhere else: from permissions import can_editWhen the rule changes (say, editors can also edit), you change it once — not hunt three drifted copies.
Critique mode
Scan the diff for repeated logic, duplicated constants, and reinvented stdlib/existing
utilities. For each: is this knowledge duplication (consolidate) or incidental
similarity (leave it)? Tag [dry-and-reuse · duplicate-knowledge|reinvented-util · SEV].
Cross-check suspected structural duplication with dependency-analyzer.
References
- DRY-as-knowledge:
../../references/PRINCIPLES.md§A - Duplicate Code / Repetition:
../../references/SMELLS.md - The GitClear data:
../../references/EVIDENCE.md - Rules 3 & 4:
../../RULES.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

