/vivswan-skills:no-invalid-statesfrom Vivswan Skills
Use when code or a design guards invariants with repeated runtime checks, lifecycle flags, or the same guard at every consumer, or when asked to make invalid states unrepresentable or parse-don't-validate.
Ships in Vivswan Skills. 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.
Read when SKILL.md points to them.
Review and refactor a codebase so that correctness constraints are carried by the strongest mechanism the language provides. Scattered defensive checks are not that mechanism.
The core principle:
Validate at boundaries, convert into stronger representations, and make invalid internal states difficult or impossible to construct.
This is the "parse, don't validate" discipline:
Use this skill when the code shows any of these signals:
if !initialized, if value is None, assert ready)Do not use this skill to add abstraction to code that is already simple, or in place of a bug hunt. It improves representation, not behavior.
Before adding another defensive check, ask: can this invalid state be removed from the program's representation instead? Use the strongest idiomatic mechanism the language offers. Keep the design simpler, not more complicated, than the problem itself.
Search for the telltale patterns:
if !initialized if value is None state === ...
if !connected if value === undefined is_ready / is_valid
assert ready has_loaded instanceof / isinstance chains
Also inspect:
For each candidate, write the invariant as one sentence. For example: "a connection may only send data after it has successfully connected."
If you cannot state the invariant, you cannot encode it. Skip it.
The target shape is a one-way pipeline:
untrusted or raw value
-> validate / parse once, at the boundary
-> strong internal representation
-> trusted internal APIs (no re-checking)
Before choosing a representation, find who mutates the state behind the invariant. The resolution belongs at those mutation points, not at the consumers.
The telltale: N call sites carrying the same guard, or a flag that every consumer must remember to honor. That is validation at N read points where prevention at the few write points would do.
Worked example: a stored credential goes stale when its associated endpoint URL changes.
staleCredential flag before using it. Six guards, six error surfaces, and every future request path must remember the check.Two rules make the owner-side fix sound:
Pick by situation, not by favorite mechanism:
| Situation | Representation |
|---|---|
| State changes at runtime and code inspects which state it is in | Sum type: enum with data, discriminated union, sealed class |
| Available operations depend on state; wrong ordering should fail to compile | Typestate: state-parameterized types, consuming transitions |
| A primitive has special meaning or is validated once then trusted | Newtype or branded type behind a smart constructor |
| Two states carry meaningfully different data; optionals encode which one | Separate types per state |
| An invariant spans construction (fields must agree) | Private fields, factory or constructor that validates, immutability |
| The invariant is really about the data store | Schema constraints: NOT NULL, CHECK, foreign keys, unique |
Detailed, idiomatic guidance with code examples lives in the per-language references:
PhantomData, consuming self, TryFrom boundaries, unsafe behind a safe APInever checks, boundary schemasLiteral unions, NewType, assert_never, strict typingIf the language at hand is not covered, map the situation table onto whatever the language offers. Sealed hierarchies, smart constructors, immutability, and module privacy exist almost everywhere in some form.
For each accepted candidate, work through this checklist:
/code-standards skill's rule; an existing boundary keeps its behaviour under this refactor, per the rule below.Rules while refactoring:
validate -> use, validate -> use becomes parse once -> use, use, use.any, non-null assertions, or ignore comments to force a refactor through.Update or add tests for:
Add compile-fail or type-level tests only if the project already has a mechanism for them.
Then run the repository's own tooling. Inspect the project configuration (package.json scripts, Makefile, Cargo.toml, pyproject.toml, CI workflows) rather than assuming command names. Typical gates:
cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspaceDo not introduce a new type checker or dependency just for this skill unless that is genuinely appropriate for the repository.
When asked to modify code, implement the changes rather than describing them. At completion, report:
Skills that run code reviews (such as /rubber-duck-review) expand this section into their reviewer prompt when this skill is installed. Ask the reviewer to flag:
Triage the resulting findings with the workflow above.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub vivswan/skills --plugin vivswan-skillsOther plugins' skills for the same job
19 skills in this plugin
/claude-remote-peersUse when this Claude Code session must message, ping, or coordinate with a Claude Code session running on another machine, or when a peer the user names is on a different host and ListAgents does not show it./code-standardsUse when writing code changes, sweeping or shortening comments (including file-size or comment-cap findings), or asked to apply the code standards./codex-browser-fixUse when Codex on macOS must drive the user's Chromium browser (Brave, Vivaldi, Opera, Edge, Chrome) through the bundled Chrome plugin, or that plugin fails with "Codex auth token is unavailable", a missing extension connection, or a stale plugin cache after a desktop app update. Codex only.