Agent skill

Lean4 Theorem Proving

by benchflow-ai in benchflow-ai/skillsbench

A skill your agent uses when working with Lean 4 (.lean files), writing mathematical proofs, seeing "failed to synthesize instance" errors, managing sorry/axiom elimination, or searching mathlib for…

Apache-2.0Auto-check passedAgent Workflows

Install Lean4 Theorem Proving

skills CLI
$ npx skills add benchflow-ai/skillsbench --skill lean4-theorem-proving -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install benchflow-ai/skillsbench lean4-theorem-proving --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/benchflow-ai/skillsbench.git skills-src && mkdir -p .claude/skills && cp -r skills-src/tasks/lean4-proof/environment/skills/lean4-theorem-proving .claude/skills/lean4-theorem-proving && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
lean4-theorem-proving
GitHub stars
1.8k
Token cost
~2.2k tokens
SKILL.md length
849 words
Files
21 (incl. references)
Skills in repo
189
Repo updated
First seen
Licence
Apache-2.0

At a glance

A skill your agent uses when working with Lean 4 (.lean files), writing mathematical proofs, seeing "failed to synthesize instance" errors, managing sorry/axiom elimination, or searching mathlib for…

  • Works in 4 steps: Structure Before Solving - Outline proof… → Helper Lemmas First - Build… → Incremental Filling - Fill ONE sorry at… → …
  • Working with Lean 4 (.lean files)
  • SKILL.md covers Core Principle, Quick Reference, When to Use and Tools & Workflows, plus 11 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Lean4 Theorem Proving is an agent skill from benchflow-ai/skillsbench. Use when working with Lean 4 (.lean files), writing mathematical proofs, seeing "failed to synthesize instance" errors, managing sorry/axiom elimination, or searching mathlib for lemmas - provides build-first workflow, haveI/letI patterns, compiler-guided repair, and LSP integration

Its SKILL.md is about 2.2k tokens, which your agent loads only when the skill is triggered. The skill folder holds 21 other files, including reference files (for example `references/axiom-elimination.md`, `references/calc-patterns.md` and `references/compilation-errors.md`).

It sits in Agent Workflows. The repository describes itself as: SkillsBench evaluates how well skills work and how effective agents are at using them. The licence is Apache-2.0.

When your agent uses it

  • Working with Lean 4 (.lean files)
  • Writing mathematical proofs
  • Seeing failed to synthesize instance errors
  • Managing sorry/axiom elimination

Example prompts

  • “failed to synthesize instance”
  • “/lean4-theorem-proving”

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. Structure Before Solving - Outline proof strategy with have statements and documented sorries before writing tactics
  2. Helper Lemmas First - Build infrastructure bottom-up, extract reusable components as separate lemmas
  3. Incremental Filling - Fill ONE sorry at a time, compile after each, commit working code
  4. Type Class Management - Add explicit instances with haveI/letI when synthesis fails, respect binder order for sub-structures

What it can do on your machine

Read from SKILL.md and the folder at commit 9a1f4dd. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • arxiv.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Lean4 Theorem Proving loads about 2.2k tokens when it runs, and up to ~78k if it reads all its reference files. Until then it costs about 76 tokens; SKILL.md has 849 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~76
When it runs · the whole SKILL.md, loaded when a task matches
~2.2k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~78k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from benchflow-ai/skillsbench at commit 9a1f4dd, republished under its Apache-2.0 licence (© benchflow-ai). 849 words, ~2,245 tokens.

Download SKILL.mdSave it as .claude/skills/lean4-theorem-proving/SKILL.md (or your agent's skills folder). This skill also uses 20 other files; get the full folder from GitHub.
name
lean4-theorem-proving
description
Use when working with Lean 4 (.lean files), writing mathematical proofs, seeing "failed to synthesize instance" errors, managing sorry/axiom elimination, or searching mathlib for lemmas - provides build-first workflow, haveI/letI patterns, compiler-guided repair, and LSP integration

Lean 4 Theorem Proving

Core Principle

Build incrementally, structure before solving, trust the type checker. Lean's type checker is your test suite.

Success = lake build passes + zero sorries + zero custom axioms. Theorems with sorries/axioms are scaffolding, not results.

Quick Reference

ResourceWhat You GetWhere to Find
Interactive Commands10 slash commands for search, analysis, optimization, repairType /lean in Claude Code (full guide)
Automation Scripts19 tools for search, verification, refactoring, repairPlugin scripts/ directory (scripts/README.md)
Subagents4 specialized agents for batch tasks (optional)subagent-workflows.md
LSP Server30x faster feedback with instant proof state (optional)lean-lsp-server.md
Reference Files18 detailed guides (phrasebook, tactics, patterns, errors, repair, performance)List below

When to Use

Use for ANY Lean 4 development: pure/applied math, program verification, mathlib contributions.

Critical for: Type class synthesis errors, sorry/axiom management, mathlib search, measure theory/probability work.

Tools & Workflows

7 slash commands for search, analysis, and optimization - type /lean in Claude Code. See COMMANDS.md for full guide with examples and workflows.

16 automation scripts for search, verification, and refactoring. See scripts/README.md for complete documentation.

Lean LSP Server (optional) provides 30x faster feedback with instant proof state and parallel tactic testing. See lean-lsp-server.md for setup and workflows.

Subagent delegation (optional, Claude Code users) enables batch automation. See subagent-workflows.md for patterns.

Build-First Principle

ALWAYS compile before committing. Run lake build to verify. "Compiles" ≠ "Complete" - files can compile with sorries/axioms but aren't done until those are eliminated.

The 4-Phase Workflow

  1. Structure Before Solving - Outline proof strategy with have statements and documented sorries before writing tactics
  2. Helper Lemmas First - Build infrastructure bottom-up, extract reusable components as separate lemmas
  3. Incremental Filling - Fill ONE sorry at a time, compile after each, commit working code
  4. Type Class Management - Add explicit instances with haveI/letI when synthesis fails, respect binder order for sub-structures

Finding and Using Mathlib Lemmas

Philosophy: Search before prove. Mathlib has 100,000+ theorems.

Use /search-mathlib slash command, LSP server search tools, or automation scripts. See mathlib-guide.md for detailed search techniques, naming conventions, and import organization.

Essential Tactics

Key tactics: simp only, rw, apply, exact, refine, by_cases, rcases, ext/funext. See tactics-reference.md for comprehensive guide with examples and decision trees.

Domain-Specific Patterns

Analysis & Topology: Integrability, continuity, compactness patterns. Tactics: continuity, fun_prop.

Algebra: Instance building, quotient constructions. Tactics: ring, field_simp, group.

Measure Theory & Probability (emphasis in this skill): Conditional expectation, sub-σ-algebras, a.e. properties. Tactics: measurability, positivity. See measure-theory.md for detailed patterns.

Complete domain guide: domain-patterns.md

Managing Incomplete Proofs

Standard mathlib axioms (acceptable): Classical.choice, propext, quot.sound. Check with #print axioms theorem_name or /check-axioms.

CRITICAL: Sorries/axioms are NOT complete work. A theorem that compiles with sorries is scaffolding, not a result. Document every sorry with concrete strategy and dependencies. Search mathlib exhaustively before adding custom axioms.

When sorries are acceptable: (1) Active work in progress with documented plan, (2) User explicitly approves temporary axioms with elimination strategy.

Not acceptable: "Should be in mathlib", "infrastructure lemma", "will prove later" without concrete plan.

Show full SKILL.md (364 more words)Show less

Compiler-Guided Proof Repair

When proofs fail to compile, use iterative compiler-guided repair instead of blind resampling.

Quick repair: /lean4-theorem-proving:repair-file FILE.lean

How it works:

  1. Compile → extract structured error (type, location, goal, context)
  2. Try automated solver cascade first (many simple cases handled mechanically, zero LLM cost)
    • Order: rfl → simp → ring → linarith → nlinarith → omega → exact? → apply? → aesop
  3. If solvers fail → call lean4-proof-repair agent:
    • Stage 1: Haiku (fast, most common cases) - 6 attempts
    • Stage 2: Sonnet (precise, complex cases) - 18 attempts
  4. Apply minimal patch (1-5 lines), recompile, repeat (max 24 attempts)

Key benefits:

  • Low sampling budget (K=1 per attempt, not K=100)
  • Error-driven action selection (specific fix per error type, not random guessing)
  • Fast model first (Haiku), escalate only when needed (Sonnet)
  • Solver cascade handles simple cases mechanically (zero LLM cost)
  • Early stopping prevents runaway costs (bail after 3 identical errors)

Expected outcomes: Success improves over time as structured logging enables learning from attempts. Cost optimized through solver cascade (free) and multi-stage escalation.

Commands:

  • /repair-file FILE.lean - Full file repair
  • /repair-goal FILE.lean LINE - Specific goal repair
  • /repair-interactive FILE.lean - Interactive with confirmations

Detailed guide: compiler-guided-repair.md

Inspired by: APOLLO (https://arxiv.org/abs/2505.05758) - compiler-guided repair with multi-stage models and low sampling budgets.

Common Compilation Errors

ErrorFix
"failed to synthesize instance"Add haveI : Instance := ...
"maximum recursion depth"Provide manually: letI := ...
"type mismatch"Use coercion: (x : ℝ) or ↑x
"unknown identifier"Add import

See compilation-errors.md for detailed debugging workflows.

Documentation Conventions

  • Write timeless documentation (describe what code is, not development history)
  • Don't highlight "axiom-free" status after proofs are complete
  • Mark internal helpers as private or in dedicated sections
  • Use example for educational code, not lemma/theorem

Quality Checklist

Before commit:

  • lake build succeeds on full project
  • All sorries documented with concrete strategy
  • No new axioms without elimination plan
  • Imports minimal

Doing it right: Sorries/axioms decrease over time, each commit completes one lemma, proofs build on mathlib.

Red flags: Sorries multiply, claiming "complete" with sorries/axioms, fighting type checker for hours, monolithic proofs (>100 lines), long have blocks (>30 lines should be extracted as lemmas - see proof-refactoring.md).

Reference Files

Core references: lean-phrasebook.md, mathlib-guide.md, tactics-reference.md, compilation-errors.md

Domain-specific: domain-patterns.md, measure-theory.md, instance-pollution.md, calc-patterns.md

Incomplete proofs: sorry-filling.md, axiom-elimination.md

Optimization & refactoring: performance-optimization.md, proof-golfing.md, proof-refactoring.md, mathlib-style.md

Automation: compiler-guided-repair.md, lean-lsp-server.md, lean-lsp-tools-api.md, subagent-workflows.md

© benchflow-ai, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 20 other files (references) in tasks/lean4-proof/environment/skills/lean4-theorem-proving of benchflow-ai/skillsbench.

  • SKILL.md
  • references/axiom-elimination.md
  • references/calc-patterns.md
  • references/compilation-errors.md
  • references/compiler-guided-repair.md
  • references/domain-patterns.md
  • references/instance-pollution.md
  • references/lean-lsp-server.md
  • references/lean-lsp-tools-api.md
  • references/lean-phrasebook.md
  • references/mathlib-guide.md
  • references/mathlib-style.md
  • references/measure-theory.md
  • references/performance-optimization.md
  • references/proof-golfing-patterns.md
  • references/proof-golfing-safety.md
  • references/proof-golfing.md
  • references/proof-refactoring.md
  • references/sorry-filling.md
  • references/subagent-workflows.md
  • … and 1 more

Open the folder on GitHubat commit 9a1f4dd

Compare with similar skills

Lean4 Theorem Proving next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Lean4 Theorem Proving compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Lean4 Theorem Proving this skillbenchflow-ai/skillsbench1.8k—~2.2kAutomated safety check: PassApache-2.0
Orca CLIstablyai/orca88k2 repos~593Automated safety check: PassMIT
OpenSpec Guided OnboardingFission-AI/OpenSpec71k1 repos~4.5kAutomated safety check: PassMIT
Claude Code Plugin Structureanthropics/claude-plugins-official38k10 repos~3.4kAutomated safety check: PassApache-2.0
Neat-Freak Knowledge CloseoutKKKKhazix/khazix-skills21k—~1.9kAutomated safety check: PassMIT
O2 Review Loopopenobserve/openobserve22k—~3.7kAutomated safety check: PassAGPL-3.0

Similar skills

  • Orca CLI

    stablyai/orca

    Operate Orca-managed worktrees, folder contexts, terminals, repos, automations, artifacts, skill sharing, worktree comments, and Orca's embedded browser…

    88k GitHub starsUsed in 2 repos~593 tokens
    Agent WorkflowsAuto-check passed
  • OpenSpec Guided Onboarding

    Fission-AI/OpenSpec

    Walks you through a complete OpenSpec workflow cycle with narration while doing real work in your codebase.

    71k GitHub starsUsed in 1 repo~4.5k tokens
    Agent WorkflowsAuto-check passed
  • Claude Code Plugin Structure

    anthropics/claude-plugins-official

    Official

    Explains the directory layout, plugin.json manifest and component organization of a Claude Code plugin, including auto-discovery and portable paths.

    38k GitHub starsUsed in 10 repos~3.4k tokens
    Agent WorkflowsAuto-check passed
  • Neat-Freak Knowledge Closeout

    KKKKhazix/khazix-skills

    Brings project docs, agent rule files, authorized memory and leftover workspace files back in line with what the code and runtime actually do at the end of a work session.

    21k GitHub stars~1.9k tokensUpdated 7 days ago
    Agent WorkflowsAuto-check passed
  • O2 Review Loop

    openobserve/openobserve

    Splits a change into planner, coder and independent reviewer roles: you confirm a spec, a subagent implements it, and a separate reviewer checks each round's local WIP commit.

    22k GitHub stars~3.7k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • Autoresearch Iteration Loop

    uditgoenka/autoresearch

    Runs an autonomous modify, verify, keep-or-discard loop against any metric, with subcommands for planning, debugging, fixing, security audits, shipping and more.

    6.5k GitHub starsUsed in 1 repo~2k tokens
    Agent WorkflowsAuto-check passed

More from benchflow-ai/skillsbench

All 189 skills in this repo
  • Lean4 Memories

    benchflow-ai/skillsbench

    This skill should be used when working on Lean 4 formalization projects to maintain persistent memory of successful proof patterns, failed approaches, project conventions, and user preferences…

    1.8k GitHub stars~3.2k tokensUpdated 2 mo ago
    Auto-check passed
  • Senior Data Engineer

    benchflow-ai/skillsbench

    World-class data engineering skill for building scalable data pipelines, ETL/ELT systems, real-time streaming, and data infrastructure.

    1.8k GitHub stars~5.9k tokensUpdated 2 mo ago
    Auto-check passed
  • Ac Branch Pi Model

    benchflow-ai/skillsbench

    AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching acopf-math-model.md and MATPOWER branch fields.

    1.8k GitHub stars~1.1k tokensUpdated 2 mo ago
    Auto-check passed
  • Civ6lib

    benchflow-ai/skillsbench

    Civilization 6 district mechanics library. An agent skill from benchflow-ai/skillsbench.

    1.8k GitHub stars~1.7k tokensUpdated 2 mo ago
    Auto-check passed
  • D3 Visualization

    benchflow-ai/skillsbench

    Build deterministic, verifiable data visualizations with D3.js (v6).

    1.8k GitHub stars~1.5k tokensUpdated 2 mo ago
    Auto-check passed
  • Dc Power Flow

    benchflow-ai/skillsbench

    DC power flow analysis for power systems. An agent skill from benchflow-ai/skillsbench.

    1.8k GitHub stars~717 tokensUpdated 2 mo ago
    Auto-check passed

Questions about Lean4 Theorem Proving

What does Lean4 Theorem Proving do?

A skill your agent uses when working with Lean 4 (.lean files), writing mathematical proofs, seeing "failed to synthesize instance" errors, managing sorry/axiom elimination, or searching mathlib for…. Lean4 Theorem Proving is an agent skill from benchflow-ai/skillsbench.

When should I use Lean4 Theorem Proving?

Lean4 Theorem Proving fits situations like: working with Lean 4 (.lean files); writing mathematical proofs; seeing failed to synthesize instance errors; managing sorry/axiom elimination.

How do I install Lean4 Theorem Proving in Claude Code?

Run `npx skills add benchflow-ai/skillsbench --skill lean4-theorem-proving -a claude-code`. Or copy the skill folder (tasks/lean4-proof/environment/skills/lean4-theorem-proving in benchflow-ai/skillsbench) into .claude/skills/lean4-theorem-proving in your project. Claude Code loads it when a task matches its description.

How do I install Lean4 Theorem Proving in Codex?

Run `npx skills add benchflow-ai/skillsbench --skill lean4-theorem-proving -a codex`. Or copy the skill folder (tasks/lean4-proof/environment/skills/lean4-theorem-proving in benchflow-ai/skillsbench) into .agents/skills/lean4-theorem-proving in your project. Codex loads it when a task matches its description.

Can I use Lean4 Theorem Proving in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add benchflow-ai/skillsbench --skill lean4-theorem-proving -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/lean4-theorem-proving, .gemini/skills/lean4-theorem-proving, .github/skills/lean4-theorem-proving and .opencode/skills/lean4-theorem-proving in your project.

What does Lean4 Theorem Proving need to run?

SKILL.md names no scripts, command-line tools or credentials: Lean4 Theorem Proving is instructions for the agent only.

Does Lean4 Theorem Proving access the network?

SKILL.md names 1 domain. As links in the text: arxiv.org. This is read from the text; nothing was executed.

Is Lean4 Theorem Proving safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Lean4 Theorem Proving use?

Lean4 Theorem Proving is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Lean4 Theorem Proving use?

About 2.2k tokens (SKILL.md is roughly 9k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 76k tokens, read only when the agent opens those files.

What are the alternatives to Lean4 Theorem Proving?

Skills that share tags, products or a category with Lean4 Theorem Proving: Orca CLI (stablyai/orca, 88k stars), OpenSpec Guided Onboarding (Fission-AI/OpenSpec, 71k stars), Claude Code Plugin Structure (anthropics/claude-plugins-official, 38k stars) and Neat-Freak Knowledge Closeout (KKKKhazix/khazix-skills, 21k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Lean4 Theorem Proving?

benchflow-ai (a GitHub organization) maintains it in benchflow-ai/skillsbench, which has 1,834 GitHub stars. The repository holds 189 skills in this directory. The repository was last updated on July 23, 2026.

Source: benchflow-ai/skillsbench on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.