AITP 2026

From Prompts to Protocols: lean4-skills for AI-Assisted Lean Formalization

Cameron Freer
Massachusetts Institute of Technology
11th Conference on Artificial Intelligence and Theorem Proving
CNRS Paul-Langevin Centre · Aussois, France
Monday, 31 August 2026
cameronfreer.github.io/slides

Concretely: a Lean toolkit (skill, commands, scripts) for your coding agent

lean4-skills GitHub repository

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

A lot has changed in the past year

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.

late 2025Tool tutor
  • remember recurring failure modes
  • use Lean’s own feedback and Mathlib search through lean-lsp-mcp
early 2026Proof engineer
  • search: the library, before attempting a proof
  • testing: try tactics in parallel before editing
  • repair: fix broken proofs, in stages
  • quality: golf working proofs shorter and clearer
  • hygiene: eliminate stray axioms, minimize imports
  • performance: profile slow elaboration
mid 2026Protocol layer
  • statement fences and budgets
  • checkpointed builds
  • stop when stuck: obstruction reports
  • a trail: what was searched, what Lean verified, who signed off
now / next?Mathematical
thought partner
  • hybrid human–AI collaboration on open-ended mathematical exploration
    • Lean formalization continuously in the loop
  • external tools search: SAT/SMT, first-order provers, Python, computer algebra
    • Lean certifies their witnesses and counterexamples

From project diary to shared infrastructure

October 2025
  • a personal reference file from the exchangeability project (three proofs of de Finetti)
  • notes to reinforce good patterns and ward off antipatterns
  • released as a Claude Code skill
refined the skill
as I used it
  • PRs to Sphere-Packing-Lean and Noperthedron
  • my own public libraries: exchangeability · graphons · infinitary logic · Loeb measure · computable model theory · computable analysis · algorithmic randomness · reverse mathematics · Hilbert’s tenth · forcing
  • TauCeti roadmaps and PRs
new features by
myself & others
  • Codex as a first-class host
  • domain references: measure theory, typeclasses, performance
  • workflows with their own permissions and stop conditions
  • subagents, hooks, and scripts
  • /learn pedagogy
  • /disprove counterexamples
  • bounded debate

What lean4-skills contains

Human mathematicianchooses meaning and priorities; owns statements & sign-off
Coding agent:
Claude Code or Codex or …
explores, searches, proposes, edits, explains
lean4-skills protocol layer
Referencesconventions, idioms, failure modes, read on demand
Workflows/draft · /prove · /disprove · /review · /refactor · /learn …
each with its own permissions and stop conditions
Bounded proof loop: plan, work, checkpoint, review, replan, continue? yes back to plan, no to handoff summary
Lean kernelauthoritative judge
Mathlib + TauCeti
+ other projects + the current project
reusable APIs, at every layer
lean-lsp-mcpgoals, diagnostics, search

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.

Protocols beyond proving: teaching, refuting, exploring

prove a fixed statement
→ a proof, or a useful obstruction report
teach a person
→ checked understanding, not merely code
refute a conjecture
→ a certified counterexample, or an honest INCONCLUSIVE
explore an open question
→ better definitions, conjectures, evidence, and new questions

Trust comes from declaring the permissions, evidence, and stopping condition for each kind of interaction.

Lean-backed Socratic teaching: /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).

Certified counterexample search: /disprove

Outside 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.

Search: anything goes

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]

Certification: Lean only

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).

Interleaving exploration and formalization

formal firstsearch inside Lean (the IMO systems of 2024);
an open question whether discovery works this way
informal firstreason in natural language, formalize at the end;
the current default
intertwinedformalize fragments as you go;
for some problems, better than either
understand
propose definitions
examine examples
conjecture
interpret
prove / refute
formalize fragments
attack
possible outputs
  • a theorem
  • a certified counterexample
  • an obstruction report
  • a better definition
  • a reusable API
  • a sharper question

Formalization can begin before the theorem is fixed.

Definitions, conjectures, counterexamples, and proofs develop together in one checked workspace.

From formalization assistant to mathematical thought partner

Cameron Freer
MIT · AITP 2026 · 31 August 2026
cameronfreer.github.io/slides

+

Optional slides

Rendered candidates for the deck above, not part of the 20 minutes. Delete, promote, or merge.

Q&A What to build next: better detectives, one court of appeal

Certify, on its ownPull certification out of /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.
Specialists as separate skillsSAT · SMT · first-order saturation · model finding · symbolic and numeric searchEach its own skill with its own evidence format. The protocol’s job is to choose which one to ask, record what was asked, and bring back an artifact whose status is clear. Lean should be the court of final appeal, not necessarily the best detective.
Useful, not just trueWhich true intermediate claim is worth saying now?Neural conjecturing for saturation provers: about 61% of generated lemmas are provable, but only 5–6% speed up the search (largest reduction 77×). A thought partner must learn the difference, and the exploratory loop needs a way to score it.

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).

opt N Three ways “verified” can still be inadequate

checked ≠ intended
A checker accepts what the environment encodes, not what you meant. An agent can satisfy it by quietly inventing the theory it needs, even a false axiom. The fix is a contract, not a weaker model: preserve the theory; fill this proof.
provable ≠ useful
Neurally generated lemmas for a saturation prover: about 61% provable, only 5–6% actually speed up the search (largest reduction 77×). Which true intermediate claim is worth saying now?
correct ≠ good
Kernel acceptance is a binary floor; quality is multidimensional: right statement and hypotheses, library reuse, readability, small imports, and can the human explain what the agent did?

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.

opt J Fences, not sandboxes (and not guardrails)

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.

Statement fence
the theorem does not change silently; changing it is a human decision
Epistemic fence
only Lean-checked claims get a certified verdict; uncertainty is labelled, never hidden
Operational fence
permissions, budgets, checkpoints, axiom and import gates, stop conditions

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.”

opt K Open-ended mathematics with Lean in the loop

formal firstsearch inside Lean (the IMO systems of 2024); an open question whether discovery works this way
informal firstreason in natural language, formalize at the end; currently winning
intertwinedformalize fragments as you go; for some problems, better than either

Mathematical exploration

  1. definitions
  2. examples and analogies
  3. conjectures
  4. proof architecture

Formal experiment

  1. encode one fragment
  2. query Lean; search the libraries
  3. check, or refute
  4. preserve what survived

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.

opt L When agents are cheap and plentiful, spend them on diversity

Scout
searches libraries, tools, analogies
Builder
formalizes the surviving branch
Skeptic
attacks claims and definitions; hunts counterexamples
Referee
target fidelity; proof gap vs. false claim; quality
Teacher
explains; diagnoses what human or agent misunderstood

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.

opt M Independent evidence

Used lean4-skills directly

Agentic Proving for Program Verification
Claude Code + lean4-skills on CLEVER: 98.1% end-to-end on entries with self-consistent premises; diagnosed defects in the benchmark itself. Sosso, Arora, Spitters · ICLR 2026 workshop · here on Tuesday
Ramanujan–Nagell · QFT · Numina-Lean-Agent
number theory, physics, and an open agentic reasoning system use the same protocol layer. Banwait 2026 · Douglas, Hoback, Mei, Nissim 2026 · Project Numina

Independent convergence: not users of the package

LeanMarathon
parallel recoverable transactions over an evolving blueprint: 258 lemmas toward seven targets, no sorry. Zhang, Sun, Suzuki, Lee, Liu 2026
Proof-Refactor
generated proofs refactored into modular artifacts, scored by rubric and readability, against a strong Claude Code baseline. Fu, Liu, Wang, Yuan 2026
417 stars44 forks710 unique cloners in 14 daysthe cited benchmark tested Claude; my own work now relies at least as much on Codex

opt O Parallel exploration over shared formal state

Around 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.

statement fence
no theorem changes silently; changing one is a human decision
evidence labels
certified, uncertified, and speculative claims never mix in the record
checked handoffs
budgets, checkpointed builds, obstruction reports between agents

“Fences, not sandboxes”: Steve Yegge, 2026: a capable agent “just needs to be told what you want: its role in the moment.”

opt P Current evidence and the next experiment

Evidence to date

  • used across number theory (Ramanujan–Nagell), physics (QFT), and Numina-Lean-Agent
  • 98.1% end-to-end on the self-consistent CLEVER subset; the agent also diagnosed defects in the benchmark itself
  • sustained use across my own projects: probability, combinatorics, logic, computability, geometry

The next experiment

  • a public case study of exactly this: formal feedback changing a definition, conjecture, or proof architecture
  • a trace showing wrong turns caught and incorporated
  • scoring usefulness, not provability: of neurally generated prover lemmas, ~61% were provable but only 5–6% helped the search

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.

opt A The FLoC arc slide (three stages), for comparison with slide 3

Late 2025Stop repeating the same problems; teach the toolsWrite down what fixed the failures that kept recurring, and show the agent how to use Lean’s own feedback (goals, hovers, diagnostics) and Mathlib search.
Early 2026Strengthen agents; streamline large developmentsSearch before proving, test before editing, stop when stuck. Fewer dead ends, and less to undo at review.
NowEnforce desired workflows; keep the human in the loopObservability and control: what was searched, what Lean verified, who chose the statement and who signed off.

Which aspects matter next?
One direction: trustworthy thought partners via Lean + coding agents.

opt I A checker accepts what the environment encodes, not what you meant

Free rein: “formalize Euclid’s lemma”

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.

A better contract: “fill this proof inside the given theory”

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.

opt B Every failure mode gets a mechanism and leaves evidence

Failure modeMechanismEvidence left behind
Mathlib reinventionLSP-first search ladderqueries and candidates tried
Imagined goal stategoal / hover / diagnostics inspectionexact state and messages
Statement driftimmutable headers in /prove modeexplicit redraft recommendation
Instance pollutionreference guidance + reviewinstance source and ambiguity diagnosis
Repeated stalled pathcycle and wall-clock budgetsstop reason + obstruction report
Opaque success/review, /refactor, /golfquality findings and verified diff

opt C Where trust actually resides

Agents

propose and explore: definitions, conjectures, proof plans, searches, edits, explanations

Codex, Claude Code, others: interchangeable participants in the protocol

Lean

checks exact formal claims: typechecking, diagnostics, axiom audit, certified refutations

necessary, not sufficient

Humans

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.

opt D Different questions need different searches

QuestionTool / modeWhat it contributes
“What is my exact goal?”lean_goalground truth for planning
“What does this name actually require?”hoverfull signature, including instance arguments
“Is there a declaration with this name?”lean_local_searchenvironment-aware name lookup
“What theorem matches this informal idea?”lean_leanfinder / lean_leansearchsemantic retrieval
“What has this type shape?”lean_looglestructural search
“What could feed automation?”lean_hammer_premisegoal-conditioned premises
“Which candidate actually works?”lean_multi_attemptparallel tactic validation
“Did the edit leave errors?”lean_diagnostic_messagesfast post-edit check
Loogle, LeanSearch, LeanFinder, and premise selection are indexes and models over Mathlib, not part of Lean; 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.

opt E Evaluate more than correctness and speed

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.

Teaching & understandingCan the human explain what the agent did?
Workflow behaviourBounded attempts? Checkpoints? Useful obstruction reports?
MaintainabilityReadable, fast, small imports, localised instances?
Mathlib integrationDid it search first? Avoid duplicate lemmas?
Statement / API qualityRight statements, hypotheses, generality?
ReproducibilityPinned toolchain? CI? Repeatable scripts?
Kernel correctnessDoes it build? Any unintended sorries or axioms? (necessary, not sufficient)

A benchmark that scores only the bottom band can rank a lucky, unreviewable proof above a stopped run with a good obstruction report.

opt F Commands differ in autonomy, permissions, and stop conditions

WorkflowPrimary jobInteraction / boundary
/draftdeclaration skeletonsno full /prove run
/formalizeinteractive synthesisstatement changes permitted with user involvement
/autoformalizeautonomous synthesisdraft + bounded proof engine
/proveguided theorem provingheader immutable; pauses between cycles
/autoproveautonomous theorem provingheader immutable; stop budgets
/disprovecounterexample / negation searchreports refuted only with a Lean-checked proof
/reviewquality assessmentread-only
/refactorAPI reuse and structurepreserve behavior; improve architecture
/golfdirectness, clarity, performanceshorter only when it remains better
/checkpointsave pointfile/project build, axiom check, commit
/learnteaching and explorationchecked explanations and tested claims
/diagnosediagnostics and migrationrepair environment / tooling blockers

opt G /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.

opt H /disprove: search broadly, certify only in Lean

Its 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.

Search: anything goes

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]

Certification: Lean only

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.