add-designpattern
Skill0 starsChanged 3 months agoMITView on GitHub
Write a standing design-pattern instruction into the project's CLAUDE.md, so before building any non-trivial unit Claude weighs the candidate patterns against the shape of the problem, names the one it picked and why, and defaults to the simplest construct when none earns its place. Invoke when the user asks to add, apply, or enforce design patterns in a project, or wants Claude to consider patterns before writing code. Skip when they want an existing design reviewed or refactored — that is code-review or simplify.
In this repository11 other files it gives its agents.
- add-owasptoptenSkill
- add-spring-structureSkill
- askSkill
- checkout-commitSkill
- check-performanceSkill
- check-securitySkill
- design-uiSkill
- discussSkill
- generate-api-docsSkill
- release-versionSkill
- testingSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 17
Default ./CLAUDE.md, so the rule travels with the repo.
- Distinctive: line 32
If the codebase has an established vocabulary, say so in your report — the block's "match what is already here" rule then has something …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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
Add Design Pattern
One job: install a durable instruction. This skill configures the project; it does not refactor it.
The instruction is written to bite in both directions — it makes Claude consider the catalog and stops it from reaching for a pattern where a function would do. A block that only said "use design patterns" would make the codebase worse.
1. Pick the target file and check for duplication
Default ./CLAUDE.md, so the rule travels with the repo. ~/.claude/CLAUDE.md only if
the user wants it everywhere.
grep -l 'design-patterns:start' CLAUDE.md ~/.claude/CLAUDE.md 2>/dev/nullAlready present? Say so and ask before adding a second copy.
2. Read what the project already uses
git grep -lE 'Factory|Strategy|Repository|Builder|Adapter|Observer|Decorator' -- src app lib 2>/dev/null | headIf the codebase has an established vocabulary, say so in your report — the block's "match what is already here" rule then has something concrete to match.
3. Write the block
F=CLAUDE.md
[ -f $F ] && sed -i '/<!-- design-patterns:start -->/,/<!-- design-patterns:end -->/d' $F
cat >> $F <<'MD'
<!-- design-patterns:start -->
## Design patterns: choose deliberately
Before writing any non-trivial unit — a new class, module, or a branch point that will
grow — state in one or two lines: the shape of the problem, the candidate patterns, the
one chosen, and why. Not an essay, and not silence either.
Match the problem shape, not the pattern name:
| The problem | Candidates |
|---|---|
| Construction is conditional, or the concrete type varies | Factory Method, Abstract Factory |
| An object needs many optional parts, or must be built step by step | Builder |
| One instance must be shared | container-scoped singleton — never a static global |
| Two incompatible interfaces must meet | Adapter, Bridge |
| Behavior must be added without touching the original | Decorator, Proxy |
| A subsystem needs one simple entry point | Facade |
| Part and whole must be treated alike | Composite |
| One algorithm, several interchangeable variants | Strategy |
| The steps are fixed, the details vary | Template Method |
| Something must react to change elsewhere | Observer, Mediator |
| An action must be queued, logged, or undone | Command, Memento |
| Behavior depends on which state the object is in | State |
| An input passes through ordered, optional handlers | Chain of Responsibility |
| Persistence must be swappable or testable | Repository, Unit of Work |
| A failure path must be explicit, not thrown | Result / Either, Null Object |
| A remote dependency can fail or stall | Circuit Breaker, Retry with backoff |
| Reads and writes have diverging models | CQRS |
Rules
- **The simplest construct that works, wins.** A function, a plain class, a language
feature, or a `match` beats a pattern. A pattern earns its place when there are already
two real variants, or a known axis of change — never on one hypothetical future one.
- **Write the language's idiom, not the 1994 diagram.** A first-class function is Strategy
in most languages; a decorator, a context manager, an enum with behavior, or a
discriminated union may be the local spelling. Do not build an interface hierarchy the
language does not need.
- **Match the vocabulary already in this codebase** over introducing a new one. Consistency
beats a marginally better fit.
- **Name it where it lands** — class or module name, or one line of doc — so the next
reader sees the pattern without inferring it.
- **Do not retrofit** patterns into working code that nobody asked you to change.
- Say when a pattern was considered and rejected, and why. That is a design decision worth
one line in the commit body or the PR.
<!-- design-patterns:end -->
MDThe block lands at the end; anything already in the file stays put. Creates CLAUDE.md if
it does not exist.
4. Report
Name the file, whether it was created or updated, and any pattern vocabulary you found
already in use. Say that it takes effect next session, since CLAUDE.md loads at session
start. Then stop — no refactor, no commit.
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.

