/proof-skills:lean-modelfrom Proof Skills
Proves or refutes properties of real software in Lean 4: state machines, concurrency, async handlers, retries, queues, batching, graph algorithms. For guarantees over all inputs/sizes beyond testing.
Ships in Proof 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.
Lean gives three things at once, all from one language:
Agents are now good at the proof engineering. The human-level decisions are what to model and which statements to believe. This skill is organized around those decisions.
For a full bug hunt (scoping, the correspondence map, reproduction in real code, the fix, and
the Artifact report), follow formal-verify and use this skill for the model.
S=${CLAUDE_SKILL_DIR}/scripts
$S/setup_lean.sh # elan (no sudo); projects pin their own toolchain
$S/new_project.sh formal/<concern>/lean JobLease # template: Explore + System + Properties
cd formal/<concern>/lean && lake build
$S/check_trust.sh . # sorry/axiom/native_decide audit; --json for findings
The template has no Mathlib, only core Lean plus optional plausible. Software models rarely
need Mathlib: core has List, Array, Std.HashMap, omega, grind, decide,
bv_decide, simp, and Relation.TransGen. Mathlib adds about 8 GB of build cache.
See references/setup.md. lake env lean F.lean does not build dependencies, so run
lake build first.
State and steps. Write the component's state as a structure S deriving DecidableEq
and Repr. Keep only what the properties read. Write the steps as an inductive Step : S → S → Prop:
awaits, a locked section,
one SQL statement, one handler);Tag each constructor's docstring src: path:lines.
Executable twin. Write next : S → List (String × S) with action labels, and prove
next_sound (every executable move is a Step) so the twins cannot drift apart. The
template includes this.
Refute first. It is cheaper than proving.
#eval Explore.bfs next bad init returns the shortest labeled trace to a bad state.Explore.validPath_reach … (by decide) turns that trace into a kernel-checked theorem
that the bug is reachable.decide +kernel runs exhaustive bounded checks and trusts only propext.plausible does property-based testing of pure functions.Most bugs appear here, in seconds. Hand real ones to formal-verify for reproduction.
State the property and freeze it in Properties.lean, citing its source. Also write a
non-vacuity witness: a path, checked by decide, to a state where the interesting
thing happens. A safety theorem over a model where nothing can happen is worthless.
Prove by an inductive invariant.
inv_init, then inv_step (cases hs <;> grind [Inv, …]), then lift the result
with Explore.Reach.inv.grind or simp_all fails on one constructor, the leftover goal is a
counterexample to induction: a state that satisfies Inv but is unreachable, whose
successor breaks Inv. Add the missing fact to Inv and repeat. This loop is the heart
of the method, and the missing fact is often a real edge case worth checking in the code.references/proving.md.Audit trust.
check_trust.sh must report 0 problems for any theorem called "proven".propext, Classical.choice, Quot.sound) are fine.sorryAx is not a proof.native_decide trusts the compiler: allow it only with --allow-native, and disclose it.Connect to the code. Mirror fixes in the model and re-prove. Use lake exe replay
(the differential-testing driver in assets/lean-patterns/Replay.lean) to compare model
outputs with production traces (references/differential-testing.md).
assets/lean-patterns/ProofPatterns/, one file per pattern. references/patterns.md
explains each one.
| File | Shows | Headline results |
|---|---|---|
Explore.lean | Reach, invariant induction, BFS with traces, trace → theorem | Reach.inv, validPath_reach |
Counter.lean | lost update vs. mutex; interleavings as a step relation | racy_lost_update (bug as proof term), no_lost_update |
Idempotency.lean | async check-then-act across await; retries | buggy_double_apply, applied_nodup |
Queue.lean | FIFO: no loss, reordering, or duplication | recvd_prefix |
Pipeline.lean | batching stage drops its tail; generalized fold lemma | batch_lossless |
Graph.lean | acyclicity and topological order by certificate checking | acyclic_of_check |
StateMachine.lean | transition table + read-decide-write race; CAS fix | transitions_allowed |
DagScheduler.lean | dependency-respecting dispatch for every graph | deps_respected |
RedundantGuard.lean | proving a defensive check is dead, then deleting it | guard_implied, reach_iff |
Use Lean for:
Use TLA+ for:
Combined: TLA+ finds the trace fast; Lean proves the fixed invariant for every size. Keep TLC
traces as decide regression examples in Lean. See formal-verify/references/choosing-tools.md.
partial def cannot be unfolded in proofs. Use fuel (as Explore.bfs does) or
well-founded recursion for anything you reason about.id can silently resolve to a builtin. Inside match/∀, write PC.awaiting
rather than .awaiting when the expected type is unknown.obtain ⟨h1, h2, h3⟩ := h) and case-split on actor
and program counter before calling grind or simp_all.references/patterns.md — each pattern: the code shape, the bug, the proof strategy, and how to adapt it.references/proving.md — the tactic playbook, the invariant-strengthening loop, stuck-proof strategies, AI provers.references/pitfalls.md — vacuity, trust base, drift, over-abstraction, spec gaming.references/differential-testing.md — executable models against production: replay, random inputs, CI.references/setup.md — elan, lake, toolchain pinning, Mathlib trade-offs, lean-lsp-mcp for agents.assets/lean-patterns/ProofPatterns.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Counter.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/DagScheduler.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Explore.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Graph.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Idempotency.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Pipeline.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/Queue.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/RedundantGuard.lean (opens in a new tab)assets/lean-patterns/ProofPatterns/StateMachine.lean (opens in a new tab)assets/lean-patterns/Replay.lean (opens in a new tab)assets/lean-patterns/lake-manifest.json (opens in a new tab)assets/lean-patterns/lakefile.toml (opens in a new tab)assets/lean-patterns/lean-toolchain (opens in a new tab)assets/template/__PKG__.lean (opens in a new tab)assets/template/__PKG__/Explore.lean (opens in a new tab)assets/template/__PKG__/Properties.lean (opens in a new tab)assets/template/__PKG__/System.lean (opens in a new tab)assets/template/lakefile.toml (opens in a new tab)assets/template/lean-toolchain (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
proof-skills@opum is listed by opum-ai/opum-marketplace — review the source before installing
npx claudepluginhub opum-ai/opum-marketplace --plugin proof-skills4 skills in this plugin
/formal-verifyEnd-to-end formal-methods bug hunting for real codebases in any language — scope a risky concern, model it in TLA+ and/or Lean 4, check it, turn every counterexample into a failing test, fix the code, re-verify, and publish the results as an Artifact report. Use this skill whenever the user wants to find race conditions, lost updates, deadlocks, stale caches, double-applied retries, broken idempotency, message reordering or loss bugs, state-machine violations, dataflow/pipeline loss or duplication, or graph/DAG/scheduler bugs; whenever they say "formally verify", "model check", "prove", "TLA+", "Lean", "invariant", "spec this out", "is this thread-safe", "can this race", or ask for a concurrency/async/distributed review of a module or PR — even if they never name a formal-methods tool. Also the entry point for keeping specs in CI and detecting spec/code drift. Routes to tlaplus-model, lean-model, and proof-simplify for the tool-specific work./proof-simplifyUse verified TLA+ specs and Lean proofs to simplify real code safely — delete defensive checks the invariants make dead, remove locks/transactions/retries that do no work, collapse redundant states and flags, replace complex implementations with simpler ones proven equivalent, and encode invariants in types — re-verifying every change (re-check, refinement, reachable-state equivalence) before touching code. Use this skill whenever the user asks to simplify, clean up, de-risk a refactor, or reduce complexity in code that has (or could get) a formal model; asks "do we still need this lock / check / retry / state"; wants to turn proofs into code improvements; or finishes a formal-verify bug hunt and wants the payoff. If no verified model exists yet, it starts one via formal-verify first./tlaplus-modelTLA+/TLC model-checking skill. Use it whenever TLA+, PlusCal, Quint, Apalache, TLC, a .tla/.cfg file, or model-checker output appears. That includes a pasted TLC error, "Invariant X is violated", or a State 1/State 2… counterexample trace the user wants explained or triaged (real bug, model artifact, or too-strong property), even if it looks answerable by reading alone. Also use it to write, run, scale, or fix specs; debug slow or exploding TLC runs; check invariants, liveness, and fairness; replay production logs against a spec; or "model"/"exhaustively check" concurrent code, protocols, queues, caches, schedulers, leases, retries, and state machines for races, lost updates, double-spends, deadlocks, and ordering bugs, even for a design with no code yet. Not for runtime race detectors, Jepsen, Alloy, Lean/Coq proofs, or UI state-machine libraries. Pair with formal-verify for the full bug-hunt loop.Other plugins' skills for the same job