Write, check, prove, and debug .spock specs using a statically typed, natively compiled model checking and proof language. Validates concurrent, distributed, or stateful protocols via bounded symbolic runs, inductive proofs, and execution trace checking.
Ships in spock. 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; scripts run unread.
spock is a modern, statically typed, natively compiled model checking and proof language.
A spec says what state a system has and which steps it may take. spock check tries every
behavior of a model of the spec, and reports the shortest one that breaks an invariant or a
property. spock prove proves invariants by induction across unbounded types and constants.
spock (or spock test) runs a directory of models in parallel against each model's
expect (including bug models and unbounded proofs). spock trace checks a log of a real
run against the spec and its invariants.
spock when you want a statically typed .spock specification, native compiled model checking (spock check), unbounded inductive proofs (spock prove), bounded SMT symbolic checking (spock check --symbolic --depth N), spec refinement (refines), expect-driven regression test suites (spock test), or runtime Rust/spock_trace trace validation without needing a full-graph diagram.spock v0.10.0): spock emits only single counterexample, temporal lasso, CTI, or execution traces (human-readable text or --json); it does not dump the full reachable state graph or generate Mermaid statecharts. To render a single failing path or execution trace as a Mermaid stateDiagram-v2, pipe --json (or .jsonl) into scripts/trace_to_mermaid.py (e.g., spock check --json spec.spock | python3 scripts/trace_to_mermaid.py --diff-only).statechart when you want to check a TLA+ model (with TLC or everystate) and generate a full reachable Mermaid statechart in plain reader words (with Python views, breaks/mayBreak marks, --chart-budget/--witness, Assume_* sensitivity reruns, or embedding into an interactive code-walkthrough explainer).abstraction-discovery when diagnosing recurring failure classes, distributed writers, or caller-enforced invariants to design, prove (refines / spock prove), and enforce a deeper abstraction while deleting displaced code.implementation-simplification when applying subtractive verification (reachability witnesses, guard implication / refines proofs, boundary audits, and negative controls) to safely delete redundant guards, shadow state, locks, or premature abstractions.code-walkthrough when the deliverable is an interactive HTML explainer page.Read the reference file that fits what you are authoring or debugging:
| Reference | Read when you need |
|---|---|
| references/effective-specs-and-proofs.md | Modeling discipline (writers, atomicity, over-approximation), mutation checks, writing inductive invariants from CTIs, and avoiding solver unknowns |
| references/language-guide.md | End-to-end RFD0001 language walkthrough (lost_update.spock), Spock ↔ TLA+ operator table, actions (one_of, require let), temporal/fairness examples, and full model guide |
| references/language-reference.md | Complete keywords, EBNF grammar, operator precedence, truncating / %, container methods, canonical ordering, runtime errors, and all model settings |
| references/cli-and-json.md | All CLI options (check, prove, trace, test, skill), environment variables, exit codes (0–150), and exact --json schemas |
| references/proofs-and-symbolic.md | spock prove vs --symbolic, the 9 obligation kinds, --triage-depth, vacuity checks, and spock 0.10.0 SMT boundaries |
| references/trace-validation.md | NDJSON partial/hidden traces, coverage gates (exit 16), spock_trace Rust API (tracing::Layer, log::Logger, JSON/OTel adapters, CoverageSuite) |
| references/refinement-and-liveness.md | Multi-file use, spec & typed refines, temporal/fairness rules (leads_to, weakly_fair, strongly_fair), lassos, and symmetry traps |
| references/examples/README.md | Runnable, verified .spock reference corpus (tcommit, tcommit_unbounded proof, two_phase, allocators, ewd840, paxos tower, disruptor_spmc) |
| scripts/trace_to_mermaid.py | Render a single spock check/prove/trace --json report (or raw .jsonl trace) as a Mermaid stateDiagram-v2 |
$ cargo install --locked spock-cli
Or from npm / Bun (prebuilt binaries for macOS, Linux and Windows): bun add -D spock-cli
and then bun run spock.
The command is spock. Bare spock runs spock test on the current directory.
spock skill prints the upstream skill text. spock check --help, spock prove --help,
spock test --help and spock trace --help list every option.
Bool. Add a temporal
property only for "eventually", with the fairness it needs.require, and see spock report it. An invariant that can't fail checks nothing.symmetry for interchangeable processes,
or write an inductive invariant and run spock prove for unbounded verification.spock trace on the log, or check
them in a Rust test with the spock_trace crate.Workers take jobs from a pool and finish them. Save this as jobs.spock:
// Workers take jobs from a pool and finish them.
type Worker;
const JOBS: Int;
type Job = 0..JOBS;
type Status = | Idle | Busy(Job)
struct State {
todo: Set<Job>,
status: Map<Worker, Status>,
done: Set<Job>,
}
impl State {
action init() -> State {
State {
todo: 0..JOBS,
status: { w -> Idle for w: Worker },
done: {},
}
}
action take(self, w: Worker) -> State {
require self.status[w] == Idle;
let j = one_of(self.todo);
Self { ..self, todo: self.todo - {j}, status: self.status.update(w, Busy(j)) }
}
action finish(self, w: Worker) -> State {
require let Busy(j) = self.status[w];
Self { ..self, status: self.status.update(w, Idle), done: self.done | {j} }
}
action next(self) -> State {
any w: Worker {
any { self.take(w), self.finish(w) }
}
}
// Every job is to do, being done, or done.
fn no_job_lost(self) -> Bool {
all j: Job {
j in self.todo || j in self.done || any w: Worker { self.status[w] == Busy(j) }
}
}
// Jobs done stay done.
fn done_stays_done(self, next: State) -> Bool {
self.done <= next.done
}
fn all_done() -> Temporal {
eventually(|s: State| s.done.len() == JOBS)
}
}
model three_workers {
type Worker = {w1, w2, w3};
const JOBS = 4;
init = State::init;
next = State::next;
invariants = [State::no_job_lost];
step_properties = [State::done_stays_done];
symmetry = [Worker];
deadlock = false;
}
model finishes {
type Worker = {w1, w2};
const JOBS = 3;
init = State::init;
next = State::next;
properties = [State::all_done];
fairness = [weakly_fair(|s: State| s.next())];
deadlock = false;
}
$ spock check jobs.spock --model three_workers
three_workers: ok, 80 distinct states, depth 9 (321 generated in 0.01 s)
$ spock check jobs.spock --model finishes
finishes: ok, 44 distinct states, depth 7 (97 generated in 0.01 s)
Without require self.status[w] == Idle;, a busy worker can take a second job and drop the
first. spock check jobs_bug.spock --model three_workers reports the shortest behavior that
violates State::no_job_lost. Without fairness, finishes violates State::all_done by
stuttering immediately after State::init.
type Worker; is a set of atoms, which each model lists: type Worker = {w1, w2};.
Atoms only compare for equality. Use Map<Worker, V> (or Map<0..N, V>) for per-entity
or per-shard state rather than duplicating fields like w1_state, w2_state.type Status = | Idle | Busy(Job) | Wait { since: Int } is an enum/variant with optional
positional or named payloads (matchable with match and require let). A constructor is
written bare (Idle) when its name is unique in the file or the type expected where it
stands says which, as in self.status[w] == Idle, and as Status::Idle otherwise.struct State { .. } is a struct. A model's state type is the struct its init returns.const N: Int; is given by each model. const LAST: Int = N - 1; is derived, and may
call functions.type Job = 0..N; is a range, 0 to N - 1, and 0..=N includes N.use other { type T = T; const N = N; } uses other.spock, from the same directory,
with those values. Its names then take its prefix, as in other::State and
other::min(a, b), or a shorter one: use random_access_file as raf { .. }.Every declaration writes its type: struct fields, constants, and the parameters and result
of every function and action. A let takes the type of its value. An empty {}, [] or
None needs a place that gives its type, such as a field, a parameter, a result or the
other branch of an if.
| Type | Values |
|---|---|
Bool | true, false |
Int | 64-bit signed integers (spock check stops with error on overflow); --symbolic and spock prove use mathematical unbounded integers (model overflow, wrapping, or saturation explicitly) |
lo..hi, lo..=hi | integers in a range, with constant bounds |
Set<T>, Map<K, V>, Seq<T> | finite sets, maps and sequences; sequences index from 0 |
(A, B), Option<T> | tuples, and None or Some(x) |
A state's field whose type has a range in it is checked on every state reached, as TLC
checks TypeOK. A state where x: 0..=2 holds 3 violates the invariant State.x: 0..=2.
Functions and actions usually go in impl State { .. }, which names them State::name.
A method's first parameter is self.
fn sum(s: Seq<Int>) -> Int { // pure, and may be recursive
if s.len() == 0 { 0 } else { s.head() + sum(s.tail()) }
}
action init() -> State { .. } // no `self`: the initial states
action receive(self, p: Proc) -> State {
require self.pc[p] == Wait; // a guard: no step where it is false
require let Some(m) = self.inbox[p]; // a guard that a pattern matches
let v = one_of(self.values); // a branch for each element
let s = self.deliver(p, m); // a branch for each step of `deliver`
Self { ..s, inbox: s.inbox.update(p, None), got: s.got | {v} }
}
Self { ..self, x: 1 } or State { .. }, or a call of an action, or any, if or
match around more steps.Self { ..self, x: 1, m: self.m.update(k, v) } is self with x and m replaced.
Everything it doesn't name stays the same, so there is no UNCHANGED. ..base comes
first, Self is the type of the impl, and Self { ..self, x } is short for x: x.m.update(k, v) adds k to the map m or replaces its value, and s.update(i, v)
replaces the element at index i of the sequence s, which must have one. A part of a
part is an update in an update: self.n.update(k, N { ..self.n[k], f: 2 }).any { self.a(), self.b() } takes either step, and any p: Proc { self.a(p) } takes a
step for each process. The successors are all of theirs.self in tail
position. Reports and traces use that name.fn can't call an action, except inside enabled(..) and steps_to(..), and actions
can't be recursive. one_of, require and any around steps appear only in actions.| spock | Meaning |
|---|---|
a && b, a || b, !a, a ==> b | logic |
a == b, a != b, <, <=, +, -, *, /, % | comparison and arithmetic |
x in s, s | t, s & t, s - t, s <= t | membership, union, intersection, difference, subset |
{a, b}, {}, 0..N, 1..=N, { f(x) for x in s if p(x) } | sets |
{ k -> v for k in s }, { (a, b) -> 0 for a: A, b: B }, m[k], m.keys() | maps |
[a, b], s ++ t, s.push(x), s[i], s.head(), s.tail() | sequences |
s.len(), s.subsets(), maps(s, t) | size, all subsets, all maps from s to t |
s.min(), s.max() | the least and the greatest of a set of integers |
all x in s { p }, any x: T { p } | for all, there exists |
choose x in s { p } | the least x with p |
if c { a } else { b }, match e { P => a, .. } | conditionals; match must cover every value |
S { ..e, f: 1 }, m.update(k, v), m.remove(k), t.0 | update, tuple field |
enabled(self.a(x)) | a(x) can take a step |
x in s or x: T, or a tuple of names: { v for (b, v) in votes }.match arm, braces after => start a block, so put a set or a map value in
parentheses: None => ({}).if or a match needs parentheses.fn safe(self) -> Bool { .. } // an invariant
fn grows(self, next: State) -> Bool { .. } // a step property, of every step
fn progress() -> Temporal { // a temporal property
all p: Proc {
leads_to(|s: State| s.pc[p] == Wait, |s: State| s.pc[p] == Critical)
}
}
Temporal formulas are built with always(..), eventually(..), leads_to(a, b), !, &&,
|| and ==>, over closures of a state, |s: State| ... A closure of a step,
|s: State, next: State| .., needs always or eventually around it.
A model picks the values to check with and what must hold. A file may have several.
| Setting | Means |
|---|---|
..fixed; | first in a model: inherit fixed's types, constants and settings, overriding any redeclared |
type Worker = {w1, w2}; | the atoms of type Worker; |
const JOBS = 3; | the value of a const declared without one |
init = State::init;, next = State::next; | the initial states, and the steps |
invariants = [State::safe]; | functions of a state that must hold in every state reached |
inductive = [State::inv]; | inductive invariants stronger than invariants, proved by spock prove |
step_properties = [State::grows]; | functions of a step that must hold of every step |
properties = [State::all_done]; | temporal properties |
fairness = [weakly_fair(|s: State| s.next())]; | which actions must eventually take a step |
assumptions = [enough_jobs]; | fn() -> Bool of the constants, checked first |
constraints = [State::bounded]; | states outside one are checked, but not explored |
step_constraints = [State::fair_step]; | a step outside one is checked, but the state it reaches isn't explored |
symmetry = [Worker]; | states that differ by renaming workers count as one |
deadlock = false; | a state with no step isn't a violation; it is by default |
terminal = State::is_done; | valid terminal states (fn(self) -> Bool) when deadlock is true |
hidden = [State::lose]; | steps that a system's traces don't log |
expect = invariant(State::safe); | what spock test expects (ok by default) |
spec = main;, refines = [other::main via State::as_other]; | behavior spec and refinement checking |
..fixed;
first: model bug { ..fixed; const CHECK = false; expect = invariant(State::safe); }.
It keeps everything fixed set and replaces only what it names.weakly_fair(a) is TLA+'s WF: an action that stays enabled eventually
takes a step. strongly_fair(a) is SF: an action enabled again and again eventually
takes one. For each process, write
fairness = [all p: Proc { weakly_fair(|s: State| s.step(p)) }];.terminal = State::is_done; when valid terminal states may
stop (without writing a manual action done stutter) while unexpected deadlocks must
still fail, or deadlock = false; when any state may stop.spec main { init = ..; next = ..; fairness = [..]; } names a behavior, and
a model may say spec = main; in place of init, next and fairness.
refines = [other::main via State::as_other]; checks that this spec implements other's
main, through a function from this state to the other's.inductive = [State::inv1, ..];
when an inductive invariant is stronger than invariants. Models checked by spock prove
or spock check --symbolic may leave abstract types (type RM;) and constants
(const N: Int;) unbound to prove safety for all sizes. spock / spock test
automatically dispatches models with unbound types or constants to spock prove (matching
expect, and requiring deadlock = false; and no unchecked liveness properties to pass
expect = ok), so finite checks and unbounded proofs can live side by side in one .spock
file and both run in CI. On unbounded sets and maps in spock prove, len() == 0,
len() <= 1, len() == 1, and len() >= 2 are supported directly; for larger
cardinalities, write all/any quantifiers.| Command | Does |
|---|---|
spock | defaults to spock test across . (skips dotfiles, target, node_modules, dist) |
spock check FILE | checks the file's only model |
spock check FILE --model NAME | checks one model of several |
spock check FILE --symbolic --depth N | bounded symbolic model checking via SMT up to N steps |
spock prove FILE [--model NAME] | automatic inductive proof (pure-Rust EPR + Z3/cvc5) |
spock test [PATHS...] | runs every model in files/dirs in parallel against its expect |
spock trace FILE TRACE | checks a run log (file or - for stdin) against a model |
--filter SUBSTR | spock test: run only models whose FILE MODEL contains SUBSTR |
--workers N | uses N threads, one per core by default |
--max-distinct N | stops with an error after N distinct states |
--json | prints the report as one JSON object |
--no-cache | checks again, even when the cache has the answer |
| Exit code | Means |
|---|---|
| 0 | nothing is violated; for spock test, all match; for spock trace, a behavior matches; for spock prove, all obligations proved |
| 1 | spock test: one or more models didn't match their expect |
| 10 | an assumption is false |
| 11 | a deadlock |
| 12 | an invariant, inductive obligation, or field range is violated |
| 13 | a step property or temporal property is violated |
| 14 | spock trace: no behavior matches the trace |
| 15 | spock prove / --symbolic: solver returned unknown or timed out |
| 16 | spock trace: trace conformed to the model, but failed a coverage gate |
| 150 | an error in the spec or the trace, or while checking |
| 2 | the command line is wrong |
--no-cache when timing.--json prints version, spec, model, outcome, distinct, generated, depth,
seconds, unchecked and trace. outcome.kind is ok, assumption, invariant,
step_property, property, deadlock or error. A violation has a name, and an error
has a message and a location. trace is a list of { action, args, state }.[key, value] pairs, an atom or a constructor without fields is its name, and a
constructor with fields is { "Name": fields }, as in { "Busy": 0 }.Log each step of a real run as a line of JSON: the action, its arguments after self, and
what the code can see of the state after the step. The first line is the initial state. A
line may leave out any field, and the spec fills it in with every value it allows:
{"state":{"todo":[0,1,2],"done":[]}}
{"action":"take","args":["w1"],"state":{"todo":[1,2]}}
{"action":"take","args":["w1"],"state":{"todo":[2]}}
Run spock trace jobs.spock run.jsonl --model finishes (pass - for stdin). spock trace
also checks the model's range types, invariants and step_properties on every initial,
hidden and logged state or step along the trace (exiting 12 or 13 on a violation).
null is None in an Option (and an unknown positional argument in args),
and an error for any other state field. A line may give one key of a map as a path:
{"status[w1]": "Idle"}.hidden. Any
number of them may come between two lines.--require-all-actions, --require-actions a,b,
--require-all-fields, --require-fields f,g, and --max-stutters N (exit 16 on a
coverage failure; --json always includes "coverage").spock prove, spock automatically triages CTI pre-states up to
--triage-depth N (default 6; 0 disables): a reachable witness on a safety obligation
is a modeled bug, a reachable witness on an inductive helper means the helper is false,
and "unreachable within N steps" only means unreached within depth N (not proven
unreachable beyond N — verify semantically before strengthening inductive).In a Rust test, with spock_trace and serde_json:
use serde_json::json;
let trace = spock_trace::Trace::new();
trace.init(json!({ "todo": [0, 1, 2], "done": [] }));
// Where the code takes a step, while it holds the lock:
trace.step("take", "w1", json!({ "todo": [1, 2] }));
// At the end of the test:
spock_trace::check("jobs.spock", Some("finishes"), &trace).unwrap();
check fails with what spock trace prints. args is one value, a list, or ().
Trace::to_file(path) and Trace::for_test(name) (with SPOCK_TRACE_DIR) also write
.jsonl files for spock trace. To capture traces directly from tracing events or log
records in cargo test without changing production code, enable features = ["tracing"]
(spock_trace::tracing::{Layer, capture}) or features = ["log"]
(spock_trace::log::{Logger, capture}). To record outside tests without spock's compiler
and engine, depend on spock_trace with default-features = false.
Int that only grows makes the check
run until memory runs out. Give the field a range, add a constraint, or pass
--max-distinct.terminal = State::is_done; or deadlock = false; for a system that is
meant to stop. Use terminal when only valid final states may stop (and unexpected
deadlocks should still fail), or deadlock = false; when any state may stop.eventually that doesn't hold at the start fails there.symmetry.choose over a symmetric type. It answers the least atom, which a renaming changes, so
the check may miss states, as in TLC.{}, [] and None need a place that gives their type. Write
let e: Set<Int> = {};, or put them in a field, a parameter or a result.|s: State| { s.x > 0 } is a set of one Bool.
Write |s: State| s.x > 0, and group with parentheses. In a match arm, braces start a
block, so a set there is ({ .. }).<=.w1, but a model's
const can. min and max take only integers._ is a value only in traces, where it means unknown.view = .. isn't supported by the engine yet.| TLA+ | spock |
|---|---|
VARIABLES x, pc | struct State { x: Int, pc: Map<Proc, Pc> } |
CONSTANT Proc, and Proc <- {a, b} in the .cfg | type Proc;, and type Proc = {a, b}; in a model |
Init, Next | action init() -> State, action next(self) -> State |
\E p \in Proc : A(p) | any p: Proc { self.a(p) } |
\A p \in Proc : pc[p] = "done" | all p: Proc { self.pc[p] == Done } |
| an enabling condition | require cond; |
x' = x + 1 /\ pc' = [pc EXCEPT ![p] = "done"] /\ UNCHANGED y | Self { ..self, x: self.x + 1, pc: self.pc.update(p, Done) } |
[x \in S |-> e], DOMAIN f, [S -> T] | { x -> e for x in S }, f.keys(), maps(S, T) |
SUBSET S, Cardinality(S), CHOOSE x \in S : P | S.subsets(), S.len(), choose x in S { P } |
<<a, b>>, Append(s, x), s \o t, Head(s), Tail(s) | [a, b], s.push(x), s ++ t, s.head(), s.tail() |
[]P, <>P, P ~> Q, [][A]_vars | always(..), eventually(..), leads_to(..), a step property |
WF_vars(Next), SF_vars(A) | weakly_fair(State::next), strongly_fair(State::a) |
ASSUME, INVARIANT, PROPERTY, CONSTRAINT, SYMMETRY | assumptions, invariants, properties, constraints, symmetry in a model |
INSTANCE M WITH N <- N | use m { const N = N; } |
TypeOK | the declared types, with ranges |
Adapted from leostera/spock (crates/spock/SKILL.md), licensed under MIT (LICENSE at the plugin root), at commit afda2d8. Added the references/ suite (agent spec/proof-writing playbook, full language grammar, CLI/JSON schemas, symbolic & inductive proofs, spock_trace API/adapters, and refinement/liveness) distilled from upstream RFDs and crate sources, cross-routing to statechart and code-walkthrough, narrowed frontmatter triggers (Use when / Not for), and removed interactive emoji flourishes.
references/cli-and-json.md (opens in a new tab)references/effective-specs-and-proofs.md (opens in a new tab)references/examples/README.md (opens in a new tab)references/examples/consensus.spock (opens in a new tab)references/examples/disruptor_spmc.spock (opens in a new tab)references/examples/ewd840.spock (opens in a new tab)references/examples/paxos.spock (opens in a new tab)references/examples/scheduling_allocator.spock (opens in a new tab)references/examples/simple_allocator.spock (opens in a new tab)references/examples/sync_termination_detection.spock (opens in a new tab)references/examples/tcommit.spock (opens in a new tab)references/examples/tcommit_unbounded.spock (opens in a new tab)references/examples/two_phase.spock (opens in a new tab)references/examples/voting.spock (opens in a new tab)references/language-guide.md (opens in a new tab)references/language-reference.md (opens in a new tab)references/proofs-and-symbolic.md (opens in a new tab)references/refinement-and-liveness.md (opens in a new tab)references/trace-validation.md (opens in a new tab)scripts/trace_to_mermaid.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
/spock:spockfrom spock
npx claudepluginhub dashed/claude-marketplace --plugin spockOther plugins' skills for the same job