lean4-skills for AI-Assisted Lean Formalization
github.com/cameronfreer/lean4-skills
MIT License · v4.7.0
13 contributors
2,577 clones by 733 unique cloners, 16–29 Aug 2026
# Claude Code (in chat)
❯ /plugin marketplace add cameronfreer/lean4-skills
❯ /plugin install lean4
# Codex (in your shell)
$ codex plugin marketplace add
cameronfreer/lean4-skills --ref main
$ codex plugin add lean4@lean4-skills
# then, in the coding agent
# on your Lean project
❯ /prove the sorries in CutDistance.lean
and then /golf whatever you touched
❯ Can we /disprove that for all x and y,
2x² − 3y² ≠ 5?
❯ I want to interactively /learn how
graphons are formalized in this repo
The role of lean4-skills has shifted: partly as the package grew in scope, and partly as the underlying coding agents (LLMs + harnesses) improved and different things became the bottleneck.
Relevant at different levels of autonomy: assisting a human coder, full autoformalization, or human–AI hybrid work.
lean-lsp-mcp/learn pedagogy/disprove counterexampleslean4-skills containslean4-skills protocol layer
Progressive disclosure: the agent carries only a small core. Measure-theory advice loads when the task reaches measure theory; Lean supplies goals and diagnostics on demand.
Workflow contracts: each workflow declares its permissions, its budgets, and when it must stop or hand back control.
Division of labor: the layer shapes what the agent does. Lean stays external, and stays the authority.
INCONCLUSIVETrust comes from declaring the permissions, evidence, and stopping condition for each kind of interaction.
/learn❯ show proof socratically
Pedagogy: Switching to Socratic mode on sq_trick_sound — I'll start with the question whose
answer carries the whole design insight rather than walking the tactics linearly.
theorem sq_trick_sound (dot t ε : ℚ)
(hpos : t < dot) (hsq : 2 * ε ^ 2 < (dot - t) ^ 2) :
(dot : ℝ) > √2 * (ε : ℝ) + (t : ℝ) := by
… by_contra; push_neg; nlinarith [sq_nonneg (√2·ε − d), Real.sq_sqrt …]
First question. Squaring is where the radical disappears — so why is
hpos : t < dot there at all? Can you give values where 2ε² < (dot − t)² holds
but the conclusion is false?
❯ t could be > dot but by more than sqrt(2)epsilon in magnitude
● Exactly right. Squaring forgets sign: d² > 2ε² only says |d| > √2·|ε|. Concrete witness:
dot = 0, t = 10, ε = 1 — then 2ε² = 2 < 100 = d², but 0 > √2 + 10 is false. So hpos is
what restores the sign information that squaring destroyed.
… the exchange continues: which two hypotheses nlinarith must multiply, and why the
chain breaks when d ≤ 0
✻ Churned for 21s
The interaction is informal, but claims can be checked on the backend in Lean.
Live session, Noperthedron project, June 2026, trimmed. Pedagogy mode and self-debate by Romir Patel (PR #43; debate engine PR #186, open).
/disproveOutside of decidable settings, proof search alone cannot distinguish a difficult theorem from a false statement.
Sometimes the useful output is a counterexample: test a conjecture before spending a week trying to prove it. The search can use anything; the verdict comes only from Lean.
theorem smt_bad : ∀ x y : ℤ,
2 * x ^ 2 - 3 * y ^ 2 ≠ 5 := by sorry
decide not applicable (infinite domain)
omega nonlinear
enumerate one-dimensional only
external/Z3 sat: x = -4, y = 3 [untrusted]
theorem T_counterexample : ∃ x y : ℤ,
2 * x ^ 2 - 3 * y ^ 2 = 5 :=
⟨-4, 3, by norm_num⟩
checked wrapper ¬ TARGET ✓
lake env lean typechecks ✓
axiom gate whitelist ✓
REFUTED
REFUTED means Lean typechecked a proof of ¬ TARGET and its axioms passed the gate. A witness that fails that check is reported WITNESS_UNCERTIFIED; a search that finds nothing, INCONCLUSIVE.
Janko Ondras & C.F., Lean Disprove: Certified Counterexample Search, AI4Math @ ICML 2026 (lean4-skills PR #134).
Formalization can begin before the theorem is fixed.
Definitions, conjectures, counterexamples, and proofs develop together in one checked workspace.
+
Rendered candidates for the deck above, not part of the 20 minutes. Delete, promote, or merge.
/disproveExamples and counterexamples alike: a candidate object (a witness, a finite model, a solver assignment, a derivation) goes in; a Lean-checked artifact with an unambiguous status comes out. Candidate counterexamples are cheap; certified ones are precious.Three open interfaces: external reasoners behind a certification boundary, a persistent checked state that many agents can share, and evaluation beyond kernel acceptance.
Conjecturing numbers: Jakubův, Olšák, Suda, Urban, Neural Conjecturing for Saturation Theorem Provers, AITP 2026 (3,161 Mizar40 problems, 122,356 evaluated cuts; architectures coded with Codex).
So measure more than completion: did the interaction sharpen a definition or conjecture? find revealing counterexamples or missing hypotheses? leave reusable API? leave the human able to explain, audit, and continue?
The strongest public evidence is still about formalization and proof quality. The missing evidence for the fourth role is a public case study where Lean-backed interaction changes the mathematics being discovered. That is the next experiment.
Koepke & Wirtz, Naproche Natural Language Formalizations with LLMs; Jakubův, Olšák, Suda, Urban, Neural Conjecturing for Saturation Theorem Provers, both AITP 2026.
Guardrails and sandboxes assume the agent will wander: narrow the scope, ration the context, wall off every action. Cheap capability is spent making the agent do less.
A fence is a written rule that a capable agent will read and respect. The question stops being “how do we keep it safe?” and becomes “how do we tell it what we want?”: its role, the workflow, what may change, what counts as done.
Once the fence is text, you can ask for more: a skeptic attacking a definition overnight; many agents on one blueprint, checkpoints as the coordination.
And Lean is not only the fence. It is laboratory equipment: a failed elaboration exposes a missing hypothesis; a finite model kills a conjecture; an awkward formalization reveals the wrong definition.
Steve Yegge, Fences, not Sandboxes (2026): a capable agent “just needs to be told what you want: its role in the moment.”
Formal feedback can change the question, not merely certify the answer.
The statement need not be fixed at the start; a counterexample may be the most useful result; an awkward proof may expose the missing abstraction, and not every true claim is worth saying now. Trustworthy means conjectures, evidence, failures, and certified claims stay distinguishable.
Current working practice and a research direction, not yet a public case study. Where it pays: heavy bookkeeping, long chains of small lemmas, definitions still being chosen: the projects on slide 3.
All around one shared Lean repository: checked state, a blueprint, CI-gated handoffs, and a human editor who owns meaning and decides which questions matter.
Parallelism should buy different questions, not twenty copies of one attempt.
Five agreeing agents are not a proof. Five agents producing independently checkable artifacts may be useful. Overnight autonomous runs with obstruction reports as the morning’s reading; roadmaps executed by many hands.
lean4-skills directlysorry. Zhang, Sun, Suzuki, Lee, Liu 2026Around a shared Lean state: scouts propose competing definitions and analogies; builders formalize the promising branches; skeptics attack them; referees compare evidence and target fidelity; teachers explain what was learned. The human chooses which questions matter.
Parallelism supplies competing hypotheses; Lean makes their evidence comparable.
“Fences, not sandboxes”: Steve Yegge, 2026: a capable agent “just needs to be told what you want: its role in the moment.”
Completion is measurable today; mathematical contribution is the open evaluation problem.
CLEVER: Sosso, Arora, Spitters, ICLR 2026 workshop; here on Tuesday; tested Claude Code, while my current work relies at least as much on Codex. Lemma-usefulness numbers: Jakubův, Olšák, Suda, Urban, AITP 2026.
Which aspects matter next?
One direction: trustworthy thought partners via Lean + coding agents.
An agentic system produced a self-contained Naproche file, accepted by the checker, superficially following the Wikipedia proof, while over-relying on axioms it invented, including one false in the standard model.
Axiom. Assume a < n and n*q = a*b and b is positive.
Then n-a | a*(b-q) and b-q is positive and a*(b-q) < a*b.
Restricted to supplying a proof within an existing axiomatic theory (Cantor–Schröder–Bernstein, proof removed), the same kind of system did much better.
The repair was not a weaker model. It was a fence: preserve the theory; fill this proof.
Verification answers the question encoded by the current environment. Protocols preserve the question the human actually meant.
Koepke & Wirtz, Naproche Natural Language Formalizations with LLMs, AITP 2026. Compare the statement fence and the axiom gate on slide 6.
| Failure mode | Mechanism | Evidence left behind |
|---|---|---|
| Mathlib reinvention | LSP-first search ladder | queries and candidates tried |
| Imagined goal state | goal / hover / diagnostics inspection | exact state and messages |
| Statement drift | immutable headers in /prove mode | explicit redraft recommendation |
| Instance pollution | reference guidance + review | instance source and ambiguity diagnosis |
| Repeated stalled path | cycle and wall-clock budgets | stop reason + obstruction report |
| Opaque success | /review, /refactor, /golf | quality findings and verified diff |
propose and explore: definitions, conjectures, proof plans, searches, edits, explanations
Codex, Claude Code, others: interchangeable participants in the protocol
checks exact formal claims: typechecking, diagnostics, axiom audit, certified refutations
necessary, not sufficient
choose the question, the intended statement, the interpretation, and what counts as acceptable evidence
attribution · independent verification · bounded autonomy
The same checkpoints that keep a formalization reviewable are what make an exploration trustworthy.
| Question | Tool / mode | What it contributes |
|---|---|---|
| “What is my exact goal?” | lean_goal | ground truth for planning |
| “What does this name actually require?” | hover | full signature, including instance arguments |
| “Is there a declaration with this name?” | lean_local_search | environment-aware name lookup |
| “What theorem matches this informal idea?” | lean_leanfinder / lean_leansearch | semantic retrieval |
| “What has this type shape?” | lean_loogle | structural search |
| “What could feed automation?” | lean_hammer_premise | goal-conditioned premises |
| “Which candidate actually works?” | lean_multi_attempt | parallel tactic validation |
| “Did the edit leave errors?” | lean_diagnostic_messages | fast post-edit check |
lean_goal, hover, diagnostics, and lean_multi_attempt surface Lean elaborator and LSP results through MCP. Search results stay hypotheses until Lean tests the candidate.Correctness and speed are the easy measurements. API quality, maintainability, and whether a reviewer can follow what happened show up across weeks and projects, not in one file’s sorry count.
A benchmark that scores only the bottom band can rank a lucky, unreviewable proof above a stopped run with a good obstruction report.
| Workflow | Primary job | Interaction / boundary |
|---|---|---|
/draft | declaration skeletons | no full /prove run |
/formalize | interactive synthesis | statement changes permitted with user involvement |
/autoformalize | autonomous synthesis | draft + bounded proof engine |
/prove | guided theorem proving | header immutable; pauses between cycles |
/autoprove | autonomous theorem proving | header immutable; stop budgets |
/disprove | counterexample / negation search | reports refuted only with a Lean-checked proof |
/review | quality assessment | read-only |
/refactor | API reuse and structure | preserve behavior; improve architecture |
/golf | directness, clarity, performance | shorter only when it remains better |
/checkpoint | save point | file/project build, axiom check, commit |
/learn | teaching and exploration | checked explanations and tested claims |
/diagnose | diagnostics and migration | repair environment / tooling blockers |
/learn: teach the material, catch up on a session, or talk informally with Lean under the hood❯ show proof socratically
Pedagogy: Switching to Socratic mode on sq_trick_sound — I'll start with the question whose
answer carries the whole design insight rather than walking the tactics linearly.
theorem sq_trick_sound (dot t ε : ℚ)
(hpos : t < dot) (hsq : 2 * ε ^ 2 < (dot - t) ^ 2) :
(dot : ℝ) > √2 * (ε : ℝ) + (t : ℝ) := by
… by_contra; push_neg; nlinarith [sq_nonneg (√2·ε − d), Real.sq_sqrt …]
First question. Squaring is where the radical disappears — so why is
hpos : t < dot there at all? Can you give values where 2ε² < (dot − t)² holds
but the conclusion is false?
❯ t could be > dot but by more than sqrt(2)epsilon in magnitude
● Exactly right. Squaring forgets sign: d² > 2ε² only says |d| > √2·|ε|. Concrete witness:
dot = 0, t = 10, ε = 1 — then 2ε² = 2 < 100 = d², but 0 > √2 + 10 is false. So hpos is
what restores the sign information that squaring destroyed.
… the exchange continues: which two hypotheses nlinarith must multiply, and why the
chain breaks when d ≤ 0
✻ Churned for 21s
Live session, Noperthedron project, June 2026, trimmed; pedagogy mode by Romir Patel.
/disprove: search broadly, certify only in LeanIts own workflow, not a fallback: test a conjecture, check a generalization, turn a solver’s guess into a checked artifact. The target is never weakened.
theorem smt_bad : ∀ x y : ℤ,
2 * x ^ 2 - 3 * y ^ 2 ≠ 5 := by sorry
decide not applicable (infinite domain)
omega nonlinear
enumerate one-dimensional only
external/Z3 sat: x = -4, y = 3 [untrusted]
theorem T_counterexample : ∃ x y : ℤ,
2 * x ^ 2 - 3 * y ^ 2 = 5 :=
⟨-4, 3, by norm_num⟩
checked wrapper ¬ TARGET ✓
lake env lean typechecks ✓
axiom gate whitelist ✓
REFUTED
The search may be heuristic or external; the verdict may not be. REFUTED needs a closed Lean term of ¬ TARGET past the axiom gate; otherwise WITNESS_UNCERTIFIED or INCONCLUSIVE.
The counterexample is appended as a separate artifact. Janko Ondras, AI4Math @ ICML 2026; PR #134.