lean4-proof-repair

lean4-proof-repair is an agent for Claude Code from frenzymath/Archon. It costs 37 tokens per session (1,014 once invoked), scanned A, original, Apache-2.0.

A Lean 4 proof-fixing agent that uses compiler errors to suggest small code changes. Lean 4 is a programming language for writing machine-checked mathematical proofs.

In plain words
What is it for?
Use it to repair type mismatches, unfinished goals, missing names, missing instances, and timeouts in Lean files.
Why use it?
It helps fix common proof errors without manually searching through the whole project. It tries quick repairs first and escalates to deeper reasoning when needed.

Agent for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter.

Part of the lean4 plugin — 1 skill, 11 commands, 4 agents, 3 hooks shipped together

Good fit Use it to repair type mismatches, unfinished goals, missing names, missing instances, and timeouts in Lean files.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/frenzymath/archon/lean4-proof-repair
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.

Clone the repo
git clone --depth 1 https://github.com/frenzymath/Archon

Made for: Claude Code.

Or install lean4, the plugin that ships this one along with the rest of its 1 skill, 11 commands, 4 agents, 3 hooks.

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-proof-repair

README.md
[![agentmods](https://agentmods.dev/badge/agents/frenzymath/archon/lean4-proof-repair.svg)](https://agentmods.dev/agents/frenzymath/archon/lean4-proof-repair)
Your own site
<a href="https://agentmods.dev/agents/frenzymath/archon/lean4-proof-repair"><img src="https://agentmods.dev/badge/agents/frenzymath/archon/lean4-proof-repair.svg" alt="Measured on agentmods" height="20"></a>
Per session 37 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,014 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00037 $0.01014
Opus 5 $0.00018 $0.00507
Sonnet 5 $0.00007 $0.00203
Haiku 4.5 $0.00004 $0.00101

Measured 8d ago against content hash 7c07450d2cf3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

lean4-proof-repair 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 8d 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.

src/archon/.archon-src/skills/lean4/agents/lean4-proof-repair.md · 108 lines

How it starts

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

Inputs

Structured error context (JSON):

{
  "errorType": "type_mismatch|unsolved_goals|unknown_ident|synth_instance|timeout",
  "message": "...",
  "file": "Foo.lean",
  "line": 42,
  "goal": "⊢ Continuous f",
  "localContext": ["h1 : Measurable f"]
}

Actions

  1. Classify errorlean_goal(file, line) + lean_diagnostic_messages(file) first, then match errorType
  2. Apply error-specific strategy (see table below)
  3. Search if needed (LSP-first; fall back to scripts only when LSP is unavailable, rate-limited, or inconclusive after bounded attempts):
    • lean_leanfinder("query") or lean_local_search("keyword") first
    • Script fallback: $LEAN4_SCRIPTS/search_mathlib.sh only after LSP exhausted
  4. Generate minimal diff (1-5 lines)
  5. Output unified diff ONLY - no explanations

Two-Stage Approach

Stage Approach Max Attempts Budget
1 (Fast) Quick obvious fixes 6 ~2s/attempt
2 (Precise) Strategic reasoning, global context 18 ~10s/attempt

Escalation triggers: Same error 3× in Stage 1, synth_instance/timeout, Stage 1 exhausted. Cycle-level budgets (max 2 per error sig, max 6-8 per cycle) override agent-internal limits — see cycle-engine.md.

Repair Strategies

Error Strategy
type_mismatch convert _ using N, type annotation, refine, rw
unsolved_goals simp?, exact?, intro, use, constructor
unknown_ident Search mathlib, add import, fix namespace
synth_instance haveI/letI, open scoped, reorder arguments
timeout simp only [...], clear, explicit instances

Output

ONLY unified diff. Nothing else.

--- Foo.lean
+++ Foo.lean
@@ -42,1 +42,1 @@
-  exact h1
+  convert continuous_of_measurable h1 using 2

Constraints

  • Output ONLY unified diff (no explanations)
  • Change ONLY 1-5 lines per call
  • Stay within stage budget
  • May NOT rewrite entire functions
  • May NOT try random tactics
  • May NOT skip mathlib search
  • Use lean_diagnostic_messages(file) for per-edit validation before any Bash-based file gate; prefer lean_run_code over temporary .lean files for isolated scratch probes

Read the full file on GitHub · 108 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. 8d ago First seen · 108 lines · 37 tokens per session scan A 7c07450d2cf3

Subscribe to this mod's changes

lean4-proof-repair is an agent published in the GitHub repository frenzymath/Archon (216 stars, last pushed 21d ago), licensed Apache-2.0. It adds 37 tokens to every session and 1,014 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-08-30.