Model-checks state machines, product flows, protocols, or services with TLA+ and draws a Mermaid statechart showing the shortest path to each rule violation. Use for verifying state transitions and surfacing bugs as paths through states.
Ships in statechart. 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.
The chart shows how a system moves between states, in the words of the person who reads it. That person, the reader, decides whether the behavior is right.
spock insteadPrefer the spock skill over TLA+ / statechart when you do not need a Mermaid statechart and any of these apply:
spock prove): bugs appear only beyond small finite constants (N = 4+, arbitrary items/workers/leases) and you want an inductive proof across all sizes rather than fixed-bound enumeration.spock check --symbolic): checking large integer thresholds, timeouts (Duration::MAX), or overflow/wraparound/saturation properties that finite enumeration must shrink away. Because --symbolic and spock prove use mathematical unbounded integers (Int) rather than machine integers, explicitly model the production code's overflow bounds, modular wrapping, or saturating clamp semantics in the spec before claiming overflow, wraparound, or saturation is verified.spock_trace + tracing::Layer + coverage gates): asserting inside cargo test or simulation suites that runtime executions match a spec and cover every action and field (--require-all-actions, --require-all-fields, exit 16).refines, spock test): ensuring two implementations refine one canonical spec and running fast natively compiled model + proof regression suites in CI.Read the reference guide that matches your task before writing specs or views:
| Reference | Read when you need |
|---|---|
| references/effective-tla-specs.md | Authoring accurate TLA+ specs from code: writer lists, guard provenance, non-atomic gaps, Assume_* refusal probes, mutation checks, safety vs liveness, and common TLA+ traps |
| references/large-models-and-views.md | Over-budget strategies (two-config, --chart-budget/--max-chart-states, --witness, layered splits), writing readable Python view.py modules, parent lifting, parallel regions, and full-clause labels |
| references/everystate-and-conformance.md | Engine selection (--engine auto|everystate|tlc), verified TLC parity differences, everystate -simulate, and everystate conform -trace run.jsonl schema/flags |
| references/examples/README.md | Locally verified tlaplus/Examples TLA+ reference specs (TCommit, TwoPhase, allocators, EWD840, Simple, Paxos tower) |
| references/render.md | Rendering .mmd files to light/dark SVGs with [email protected] and styling breaks, mayBreak, bugPath, and repeats |
Work in a scratch folder outside the repo. Write a TLA+ spec and its config. Then run:
uv run --no-config --quiet --script <skill dir>/scripts/statechart.py SPEC.tla [--config FILE] [--view FILE] [--out DIR] [--chart-budget N] [--max-chart-states N] [--witness PRED] [--engine auto|everystate|tlc]
scripts/statechart.py is a Python 3.10 script with no dependencies, and uv finds or installs a Python for it. On macOS and Linux, <skill dir>/scripts/statechart runs the same command.
Engine selection (--engine): auto (default) prefers a working native everystate binary first (EVERYSTATE env var or everystate on PATH supporting everystate java -version), otherwise uses TLA2TOOLS (plus JAVA) when TLA2TOOLS is set, and otherwise installs or runs TLC and Java with mise (needing the network on first run). Pass --engine everystate to require the optional fast native Rust engine (brew install mattzcarey/tap/everystate, npm install -g everystate, or cargo install everystate) without JVM startup overhead, or --engine tlc to force Java TLC even when everystate is installed. Set EVERYSTATE=/path/to/everystate, or TLA2TOOLS=/path/to/tla2tools.jar and JAVA=/path/to/java (Java 11+).
Over-budget options:
--chart-budget N raises the raw distinct-state cap for full graph.dot exploration (default 500). When --chart-budget exceeds 500, streaming projection caps the rendered quotient diagram at --max-chart-states N (default 200) so a coarse --view collapses large models into a small chart without loading raw states into RAM.--witness PRED names a zero-arity state predicate in SPEC.tla. The command checks ~PRED to find a shortest witness trace (## Witness: PRED in report.md), and merges it into the diagram when the model falls back to path-only charts.~>, such as Gone ~> check # "running". As an INVARIANT it breaks in each state between the event and the step that answers it. Define Spec == Init /\ [][Next]_vars /\ WF_vars(Cleanup) with WF_vars for each step that must happen when it can, and give SPECIFICATION Spec in the config. The report then gives TLC's counterexample, which ends in the states that repeat forever.Next as a disjunction of the actions, such as YouPressPlay \/ YouPressStop. If you do not, TLC names every step Next.NoDeadlock, also when it is a correct end state. When an INVARIANT or a PROPERTY already has that name, the rule is CHECK_DEADLOCK. Add to Next an action that is true only in the end states and changes nothing, such as Done == phase \in {"paid", "failed"} /\ UNCHANGED vars, and give it a label in step().Spec.cfg for full exhaustive verification (e.g., larger bounds, no lossy symmetry) and a smaller SpecChart.cfg (--config SpecChart.cfg) with tighter constants or sound SYMMETRY to draw a full readable chart; (2) write a coarse --view that projects out sub-chart details and raise --chart-budget N with --max-chart-states N; or (3) add --witness PRED (a zero-arity happy-path predicate) or split the spec into an abstract layer and a detailed lifecycle.Assume_* operator (such as Assume_NoUpgradeDuringTrial == ~trial).Assume_* operators only in positive guard position (as a conjunct that relaxes the action when replaced with TRUE; parameterized operators such as Assume_CanUpgrade(p) work too). For each Assume_* operator, the command reruns TLC on every base-holding rule with that operator overridden to TRUE (bounded at 100,000 distinct states, plus a combined rerun for rules that survive every single relaxation when two or more Assume_* operators exist) and lists dependencies under ## Assumptions.You do the work that needs judgment: the words on each state and arrow, the phases and their colors, the title, and the report to the reader. Put your work in a Python view module, such as view.py, and give it with --view.
To show the reader's words, the view defines state(vars). The value that state() returns picks the form:
def state(v): return "The card is charged" if v["paid"] else "You are paying, and the card is not charged yet"def state(v): return v["main"].split(".")def state(v): return {"Playback": v["playback"], "Volume": v["volume"]}vars is the state as JSON: a record, a sequence, or a function is a dict with string keys, so v["pc"]["1"] is pc[1], and a set is a list. Write each label as "Write the labels" says.
The view can also define step(action, from_, to). It gets the TLC action name and the values before and after the step, and it returns the label of the arrow. The steps between the same two chart states, with the same condition, share one arrow, and the command joins their labels with "or". Give two actions the same label when the reader does not need to tell them apart.
When a step can occur only in some conditions, end its label with the condition in brackets, in the reader's words, such as you press play [while the file loads]. In a regions chart, the command writes the condition on the other regions on the arrow, in the words of their labels, such as [when Offline]. Your brackets replace it, and two arrows from one state can then look the same. So in a regions chart, do not write brackets for a condition on another region. When a value that no label shows decides where a step goes, name the result in the label, such as "the roster read fails".
The view can also define these:
group(vars) returns the name of a phase. Each chart state gets the color of its group. When the model states behind one chart state are in different groups, that state gets no color.colors is a dict that gives each group name a color class.title is a string that the chart shows at the top.Start any other name in the view with _, such as _LABELS, or list the five names in __all__. The command refuses a view that defines a name it does not read. Imports do not count.
The command calls state() and group() at most once for each model state, and step() at most once for each step. The chart and the report both use those answers. So make each function depend only on its arguments.
The chart does not draw a step that stays in one label. Split a label when the reader must see such a step.
Aim for about 20 arrows or fewer, because a busier chart is hard to read. First return fewer states from state(). Give one label to values that act the same, and leave out a detail that the reader does not need, such as a call in flight whose return changes nothing. Keep each state of a bug path, and keep each mark. When a merge changes a breaks state to mayBreak, it hides where a rule breaks. Do not merge two states that break different rules, because the reader then cannot see which rule breaks where. When one step goes from many states to the same state, such as a crash that can happen at any time, put those states under one parent: state() returns a list such as ["The command is alive", "The command waits for TLC to finish"], and when each state under the parent takes the step, the command draws it once, from the parent. Do not shorten labels to make a chart less busy: a short label removes no state and no arrow. If the chart is still too busy, return None from step() for the steps that the reader does not need, such as a reset that every state has, or a step whose arrow repeats what other arrows show. Obey these rules when you hide steps:
The reader reads the chart, and the paths in the report, without the spec or the code. A label of one or two words, such as "Killed" or "Cleaning up", makes the reader guess what was killed and what is cleaned up. Write each label as a clause of about 4 to 12 words:
Pele and Mermaid 11 wrap a label at about 200 pixels, so a full label makes a taller box, not a wider chart. Mermaid 10 does not wrap: render with Pele or Mermaid 11, or break the lines before you render, as the code-walkthrough template does. The chart text writes a semicolon as #59;, so use a comma.
breaks. When only some model states behind it break the rule, it has the class mayBreak. The Legend names the rules of each mark. When two rules break, it names both on one mark, so say in the hand-off which state breaks which rule. In a regions chart, a state gets a mark when each combination of region states that includes it can break a rule. When a combination can break a rule and none of its states has a mark, each state in that combination gets a mark.SYMMETRY only when the modeled values are truly interchangeable: an unsound symmetry assumption can hide bugs, and TLC's liveness (PROPERTY) checks are unsound under SYMMETRY — check PROPERTY rules without it.tlc.out is what TLC printed on the config as written. When the chart does not show the bug path of a rule that breaks, tlc-RULE.out is what TLC printed for the run that found it. When TLC repeats its first warning, plain TLC prints it twice, but tlc.out shows it once, because TLC leaves the second copy out of the output that this command reads. That happens only when Java runs with -XX:+UseParallelGC, since otherwise TLC's first warning is its advice to pass that flag, which it prints once.Show chart.mmd to the user as a mermaid code block. By default, the chart has a budget of 500 states, counted on the config as written. Above that, the chart draws only the bug paths (plus the witness path when --witness PRED is passed), and when neither exists, the command writes no chart.mmd. It still checks each rule, and the report gives the state count and each path.
To handle larger state spaces:
Spec.cfg for full verification and run --config SpecChart.cfg with smaller constants for a full chart.--chart-budget N with a coarse --view so streaming projection merges raw states into at most --max-chart-states diagram states (default 200).--witness PRED so over-budget runs include the shortest happy-path trace in both chart.mmd and report.md.everystate): for huge specs beyond exhaustive checking, everystate -simulate num=N Spec.tla samples random behaviors; to check real implementation execution logs against the spec, run everystate conform -trace run.jsonl Spec.tla (supporting -hidden N, -stutter, -behavior, -json).In an explainer page, the code-walkthrough skill embeds chart.mmd unchanged, teaches the reader to read it, and walks each bug path; its references/state-models.md gives the steps.
Render charts with Pele. When the user asks for an image, or a chart is too large to read as text, follow references/render.md. Do not use a different renderer unless the user asks for it.
Give each chart and its Mermaid text to the person who must decide. Add one line for each bug: the rule, the reader's sentence for that rule, and the path as the report numbers it. Say what the model leaves out, list each guard still marked as an assumption (and whether a refusal probe covered it), and list each omitted variable writer. Give the command that makes the files again, with a new --out folder.
When the model describes code, replay each bug path against the real code, as a test or a live repro, one step for each action (or validate recorded JSONL traces automatically with everystate conform -trace run.jsonl Spec.tla). If a bug does not occur, think that the model is wrong until you show that it is not.
A clean run has the opposite trap: every rule holding in the model does not prove the code is bug-free. It holds only for the finite constants and assumptions in the spec, and a rule can pass vacuously if an overly tight guard stops the risky action or state from ever being reached. Pair bug-path replay with refusal probes: for each guard marked as an assumption — starting with any Assume_* operator that report.md shows a rule depends on under ## Assumptions — test the action against the real code in a state the guard excludes; if the code allows it, drop the guard and rerun. Check the chart as well to confirm that the expected states and failure actions actually appear (when a rule passes suspiciously cleanly, temporarily break the design or add a reachability check to verify the risky path is reachable, or run --witness PRED), and state the model's key assumptions (such as atomicity, bounds, or unmodeled failures) in the hand-off.
When checking a fix or follow-up change, read the changed code again rather than patching the old spec, and re-audit every guard on, and every writer of, any variable that the fix newly reads.
Use the spock skill instead when the user prefers writing statically typed .spock specs with native compilation (spock check), unbounded inductive proofs (spock prove), bounded SMT symbolic checks (--symbolic), spec refinement checks (refines), or spock trace / spock_trace validation without needing a Mermaid statechart diagram.
Use the abstraction-discovery skill when multiple bugs, distributed writers, or caller-enforced guards point to redesigning and enforcing a deeper abstraction (combining statechart, spock refinement/proofs, and code deletion) rather than applying a piecemeal fix.
Use the implementation-simplification skill when using Assume_* sensitivity, --witness reachability checks, and spock implication/refinement proofs to verify that redundant guards, derived state, locks, or premature abstractions can be safely deleted.
Adapted from the statechart skill in Lauren Tan's pstack plugin for Cursor, licensed under MIT (LICENSE at the plugin root), at commit b7b93c36be. This repository maintains its own version. Its command is Python rather than TypeScript, its views are Python modules, and step() hides a step by returning None. Its process lifecycle was changed after checking a model of it with this skill (notes): the janitor starts before the command makes its folders, the worker stops its own check when the command dies, and a reader of stdout that goes away no longer changes the exit code. It also adds optional native everystate engine support (--engine, streaming quotient projection via --chart-budget/--max-chart-states, and --witness), trace conformance guidance, cross-routing to spock, "Use when" triggers in place of disable-model-invocation: true, and guidance on rules that must hold in the end, layered models and SYMMETRY, false negatives / vacuous passes, full labels, guard provenance, writer lists, refusal probes, and Assume_* sensitivity reruns.
references/effective-tla-specs.md (opens in a new tab)references/everystate-and-conformance.md (opens in a new tab)references/examples/Paxos/Consensus.tla (opens in a new tab)references/examples/Paxos/MCConsensus.cfg (opens in a new tab)references/examples/Paxos/MCConsensus.tla (opens in a new tab)references/examples/Paxos/MCPaxos.cfg (opens in a new tab)references/examples/Paxos/MCPaxos.tla (opens in a new tab)references/examples/Paxos/MCVoting.cfg (opens in a new tab)references/examples/Paxos/MCVoting.tla (opens in a new tab)references/examples/Paxos/Paxos.tla (opens in a new tab)references/examples/Paxos/Voting.tla (opens in a new tab)references/examples/README.md (opens in a new tab)references/examples/TeachingConcurrency/Simple.cfg (opens in a new tab)references/examples/TeachingConcurrency/Simple.tla (opens in a new tab)references/examples/allocator/AllocatorRefinement.cfg (opens in a new tab)references/examples/allocator/AllocatorRefinement.tla (opens in a new tab)references/examples/allocator/SchedulingAllocator.cfg (opens in a new tab)references/examples/allocator/SchedulingAllocator.tla (opens in a new tab)references/examples/allocator/SimpleAllocator.cfg (opens in a new tab)references/examples/allocator/SimpleAllocator.tla (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
tla-plus, model-checking, state-machine, mermaid, formal-verification
/statechart:statechartfrom statechart
npx claudepluginhub dashed/claude-marketplace --plugin statechartOther plugins' skills for the same job