/lean4:autoformalize --source=PATH --claim-select=POLICY --out=PATH [--max-cycles=N] [--commit=auto|never]from lean4
Extracts mathematical claims from informal sources (PDF, URL, markdown), drafts Lean 4 skeletons, and proves them autonomously. Supports claim selection policies and cycle limits.
Ships in lean4. Installing the plugin adds it to Claude Code.
Autonomous end-to-end formalization: extracts claims from a source, drafts Lean skeletons, and proves them — all unattended. Combines /lean4:draft and /lean4:autoprove in a single command.
/lean4:autoformalize --source ./paper.pdf --claim-select=first --out=Paper.lean
/lean4:autoformalize --source ./paper.pdf --claim-select=regex:"Theorem.*" --out=Paper.lean --rigor=checked
/lean4:autoformalize --source ./notes.md --claim-select=named:"Main Lemma" --out=Lemma.lean
Interpret this command's inputs per the Command Invocation Contract.
Primary path (hook-validated): If a validated-invocation block for this
command appears in context, treat it as the authoritative interpretation of
parser-decidable inputs and do not re-parse the raw invocation text for
those inputs. Start by reading all parser-decided fields from the block. Emit
the final Resolved Inputs summary from the block values.
See Validated Invocation Block.
Fallback path (other hosts): If no validated-invocation block is present,
parse the raw invocation text against this command's input table before
extracting claims or drafting anything.
Startup requirements:
lean4-skills-cycle-tracker init with resolved numeric
values for --max-cycles, --max-stuck-cycles, --max-total-runtime,
and --max-deep-per-cycle.
A failed init (exit 2) is a startup validation error — do not proceed.tick/status output, not from conversational memory.--max-cycles and --max-stuck-cycles are per-claim;
--max-total-runtime is per-session. Before each claim, call start-claim.
After each claim completes or stops (before the next), call reset-claim.
The final claim does not need reset-claim — totals are accumulated live.
See Claim Boundary Protocol.| Arg | Required | Default | Description |
|---|---|---|---|
| --source | yes | — | File path, URL, or PDF for claim extraction. |
| --claim-select | yes | — | first | named:"..." | regex:"...". Queue-extraction filter applied once at startup. |
| --out | yes | — | Target file for formalized claims. |
| --statement-policy | no | rewrite-generated-only | preserve | rewrite-generated-only | adjacent-drafts. |
| --rigor | no | sketch | sketch | checked. Rigor for drafted skeletons. |
| --draft-mode | no | skeleton | skeleton | attempt. Passed to draft phase. |
| --draft-elab-check | no | best-effort | best-effort | strict. Passed to draft phase. |
| --max-cycles | no | 20 | Session stop budget: max total cycles per claim |
| --max-total-runtime | no | 120m | Best-effort wall-clock session budget |
| --max-stuck-cycles | no | 3 | Session stop budget: max consecutive stuck cycles per claim |
| --deep | no | stuck | never, stuck, or always |
| --deep-sorry-budget | no | 2 | Max sorries per deep invocation |
| --deep-time-budget | no | 20m | Advisory: scopes deep-mode subagent work. Not tracked or enforced by session tracker. |
| --max-deep-per-cycle | no | 1 | Max deep invocations per cycle |
| --deep-snapshot | no | stash | V1: stash only |
| --deep-rollback | no | on-regression | on-regression | on-no-improvement | always | never |
| --deep-scope | no | target | target | cross-file |
| --deep-max-files | no | 2 | Max files per deep invocation |
| --deep-max-lines | no | 200 | Max added+deleted lines per deep invocation |
| --deep-regression-gate | no | strict | strict | off |
| --commit | no | auto | auto | never |
| --golf | no | never | prompt | auto | never |
| --review-source | no | internal | internal | none (coerced from external/both — see autoprove) |
| --review-every | no | checkpoint | N (sorries) | checkpoint | never |
--source is required; error if missing.--claim-select is required; error if missing (no unattended guessing).--out is required when no existing target file is in scope; error if missing.--statement-policy=preserve is respected but warns: stuck redraft path becomes manual intervention, not automatic rewrite.The synthesis outer loop is the single source of truth for the algorithm. See cycle-engine.md for the full algorithm, provenance tracking, claim queue, and file assembly contract.
Summary:
--source (filtered by --claim-select) at startupnext_action=redraft: re-draft (check provenance + statement-policy); commit if allowedAutoformalize checks stop budgets at cycle boundaries via lean4-skills-cycle-tracker tick --stuck=yes|no.
Limits are checked at cycle boundaries only — a long-running tool call within a cycle
will not be interrupted.
Autoformalize stops when the first of these is satisfied:
--max-stuck-cycles consecutive stuck cycles on current claim. Session-enforced via lean4-skills-cycle-tracker.--max-cycles total cycles reached on current claim. Session-enforced via lean4-skills-cycle-tracker.--max-total-runtime). Checked at cycle boundaries and deep preflight.See Session Tracking for the cycle boundary protocol and enforcement levels.
When autoformalize stops, emit:
## Autoformalize Summary
**Reason stopped:** [queue-empty | max-stuck | max-cycles | max-runtime | user-stop]
| Metric | Value | Source |
|--------|-------|--------|
| Claims attempted | N/M | `claims_attempted` from `status` (includes in-progress claim) |
| Sorries before | 0 | |
| Sorries after | S | |
| Cycles run | C | `cycles_total` from `status` (session total across all claims) |
| Stuck cycles | K | `stuck_cycles_total` from `status` (session total) |
| Deep invocations | D | `deep_total` from `status` (session total) |
| Time elapsed | T | `elapsed_display` from `status` |
| Drafts | F (R redrafted) | |
**Handoff recommendations:**
- [If incomplete: "Run /lean4:formalize for guided work on remaining claims"]
- [If stuck: "Review stuck blockers: file:line, file:line"]
- [If clean: "All sorries filled. Run /lean4:checkpoint to save."]
- [If claims remaining: "N claims remaining in queue. Re-run with same --source and --out to continue."]
guardrails.sh rules apply./lean4:draft — Skeleton-only drafting (standalone)/lean4:formalize — Interactive synthesis (human-in-the-loop)/lean4:autoprove — Autonomous proving (no drafting)/lean4:disprove — Guided counterexample search with certified refutation (alternative path when a claim is suspected false)What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub cameronfreer/lean4-skills --plugin lean412 commands in this plugin
/disproveGuided counterexample search with certified refutationOther plugins' commands for the same job