lean4-ic3

lean4-ic3 is a command for Claude Code from rupakm/leslie. It costs 32 tokens per session (3,945 once invoked), scanned A, original, Apache-2.0.

A Lean 4 command that uses property-directed reachability to infer inductive invariants for formal proofs. Lean 4 is a programming language and proof assistant; an inductive invariant is a property that remains true after every allowed action.

In plain words
What is it for?
Use it to prove safety properties of Lean 4 state machines, provided the invariant is defined as a structure and the required specification and safety lemma are supplied.
Why use it?
It helps find missing conditions when a proposed invariant does not survive all actions. The command repeatedly examines counterexamples and adds structure fields until the invariant is preserved.

Command for Claude Code

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/rupakm/leslie/lean4-ic3
Clone the repo
git clone --depth 1 https://github.com/rupakm/leslie

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for lean4-ic3

README.md
[![agentmods](https://agentmods.dev/badge/commands/rupakm/leslie/lean4-ic3.svg)](https://agentmods.dev/commands/rupakm/leslie/lean4-ic3)
Your own site
<a href="https://agentmods.dev/commands/rupakm/leslie/lean4-ic3"><img src="https://agentmods.dev/badge/commands/rupakm/leslie/lean4-ic3.svg" alt="Measured on agentmods" height="20"></a>
Per session 32 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 3,945 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00032 $0.03945
Opus 5 $0.00016 $0.01972
Sonnet 5 $0.00006 $0.00789
Haiku 4.5 $0.00003 $0.00394

Measured 3d ago against content hash 4cd3a1a7c75f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

lean4-ic3 scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/lean4-ic3.md · 315 lines

How it starts

The opening of the file, as written. The whole thing — 315 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Lean4 IC3

Property-directed reachability for Lean4 invariant proofs. Drives a CEGAR loop over a structure-based invariant: probe each action, extract counterexamples-to-induction (CTIs) from residual goals, dispatch a generalizer subagent to propose new conjuncts, insert them as non-breaking structure fields, and iterate until inductive.

Prerequisite: The invariant MUST be a structure, not a flat . Adding fields is the whole point — it must be non-breaking for existing field accessors.

Usage

/lean4-ic3 File.lean::InvName --spec=specName --safety=safetyLemma
/lean4-ic3 ... --max-iters=8
/lean4-ic3 ... --decide-cti=auto --check-n=3
/lean4-ic3 ... --generalizer=manual        # default on first run
/lean4-ic3 ... --generalizer=agent         # dispatch ic3-generalizer

Inputs

Arg Required Default Description
target Yes File.lean::StructureName
--spec Yes Spec value used with action_cases (e.g. tlMessages)
--safety Yes Safety lemma the invariant must imply
--init-lemma No init_preserves_inv Base-case lemma name
--step-lemma No step_preserves_inv Inductive-step lemma name
--max-iters No 8 Max new conjuncts added before giving up
--generalizer No manual manual (prompt user) or agent (ic3-generalizer)
--decide-cti No auto auto / off / always — concretize CTI via decide at small n
--check-n No 3 n for decide-based CTI concretization

Refuse to start if the target invariant is not a structure declaration — flat conjunctions make non-breaking insertion impossible. Tell the user to refactor first. (See CLAUDE.md "Invariant Composition: Use Structures, Not Flat Conjunctions".)

Actions

Phase 0 — Baseline snapshot

  1. lean_diagnostic_messages(file) → record sorry count + diagnostic baseline.
  2. lean_file_outline(file) → discover invariant structure fields and action names.
  3. Verify init-lemma and step-lemma exist (may contain sorry; that is fine).
  4. Snapshot the invariant structure declaration verbatim. This is the rollback point.

Read the full file on GitHub · 315 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 315 lines · 32 tokens per session scan A 4cd3a1a7c75f

Subscribe to this mod's changes

lean4-ic3 is a command published in the GitHub repository rupakm/leslie (14 stars, last pushed 1mo ago), licensed Apache-2.0. It adds 32 tokens to every session and 3,945 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-01.