/poka-yoke:designfrom Poka-Yoke
Designs APIs, schemas, types, and state machines so misuse cannot be expressed. Covers branded types, discriminated unions, typestate, parse-don't-validate. Use when writing new interfaces.
Ships in Poka-Yoke. 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.
None: SKILL.md is the whole skill.
Mistake-proofing is cheapest before the code exists. Once an interface has callers, every device you add is a migration; before it has callers, a device is free. So the work here is front-loaded: decide how this thing will be misused, then pick the shape that makes the misuse unsayable.
This is Shingo's source inspection: checking the conditions that produce errors rather than the errors themselves, and it is the strongest of his three inspection types, because the error never gets the chance to happen.
Before writing an interface, spend real effort on this list. It takes two minutes and it determines the design.
Write the answers down where the user can see them, briefly. Then design against them.
Reach for the highest one the language and situation allow. Each rung down is a real concession, take it consciously and say why.
The strongest move: change the type so the bad value has no spelling.
UserId and OrderId are not both string.
Money is not a float. A timeout is not a bare number. Branded types / newtypes / value
objects cost almost nothing and kill an entire class of swap-and-mix-up bugs.{status, error?, data?, retryAt?} permits states
like "succeeded with an error and a retry time." A discriminated union permits exactly the
states that exist. If your struct has N optional fields, it claims 2^N states are legal;
ask how many actually are.Validation returns a boolean and throws the knowledge away; parsing returns a new type that
carries the proof. validateEmail(s: string): boolean leaves every downstream function still
holding an unvalidated string. parseEmail(s: string): Email | Error means downstream
functions that take Email cannot receive garbage: the type system carries the guarantee
for you, forever, for free.
Do this once, at the system's edge: HTTP handlers, queue consumers, config loading, file parsing, and every third-party response. Inside the boundary, work only with parsed types.
When steps must happen in sequence, encode the sequence in types rather than in prose:
.commit() does
not exist on an uncommitted-and-unvalidated value.build() until required steps have run, enforced by the type,
not by a runtime check, where the language allows it.init() must be called before use, the
constructor is doing the wrong job. Give it a static factory that does both.defer, RAII, using. Never "remember to close."When the type system genuinely cannot express the constraint, assert at the boundary and throw. This is a real poka-yoke, one rung down. Make the message name the mistake and the fix.
Two rules that decide whether this rung works at all:
catch {}, except: pass, || defaultValue, unwrap_or_default()
on an error path. These are devices removed. They convert a loud mistake into a quiet
one, which is exactly backwards. If a fallback is genuinely correct, the comment must say
which failure it is absorbing and why that failure is expected.deleteUsers(filter) with an empty
filter should raise, not truncate the table.The database is a type system that all your services share. NOT NULL, CHECK, UNIQUE,
foreign keys, and partial unique indexes are Control-rung devices that hold even when someone
writes a script, connects with psql, or ships a service in another language. When
application-level enforcement is the only thing standing between you and corrupt data, push
it down.
You were asked for code, so write the code. But narrate the mistake-proofing in a few lines, because the reasoning is what stops it being undone later:
That last bullet matters most. Every design leaves something possible; naming it is the difference between a considered tradeoff and an oversight.
Mistake-proofing has a cost, and past a point it stops paying. Signs you have gone too far: five wrapper types for one function, a builder for a two-field struct, a type parameter no caller will ever understand. The test is whether the device prevents a mistake someone would plausibly make, weighted by what happens when they do. An internal helper with two callers and a trivial failure mode does not need a newtype; a public payments API does.
Sean Goedecke's critique of the maximalist version is worth taking seriously: types that model every invariant can become harder to change than the bugs they prevent. Aim the strongest devices at the highest blast radius, and leave low-stakes code readable.
Read ../../references/hazard-catalog.md for the misuse shapes worth
enumerating, and the matching references/lang-*.md for what your language can actually
express: the moves above are only as strong as the type system underneath them.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub rainmanjam/poka-yoke --plugin poka-yoke11 skills in this plugin
/agent-guardrailsStop an AI agent damaging your repo: PreToolUse hooks, permission deny rules, protected paths, verification gates. Use when "claude keeps force pushing", "CLAUDE.md says X but it still does Y", "stop the agent touching prod or .env", or making a repo safe for unattended agent work. For AI features you ship to users use llm./auditFind footguns in code that already exists: swappable arguments, silent fallbacks, unguarded deletes, signatures that are easy to misuse. Use when someone asks "what could bite us here", "what is easy to misuse", "poka-yoke this repo", or wants a diff or PR reviewed for ways to get it wrong. Ranks by blast radius. For code not yet written use design; for something that already broke use retro./Other plugins' skills for the same job