/lean4:formalize [topic] [--rigor=checked|sketch|axiomatic] [--source=PATH] [--output=chat|scratch|file]from lean4
Drafts Lean 4 skeletons from informal claims and runs guided proof cycles. Accepts topic, rigor level, source file, and output destination.
Ships in lean4. Installing the plugin adds it to Claude Code.
Interactive formalization: draft Lean skeletons from informal claims, then prove them with guided cycles. Combines /lean4:draft and /lean4:prove in a single human-in-the-loop workflow.
Compatibility: Accepts all flags from old formalize (v4.3.x). Semantics are broader — new formalize runs a full prove cycle after drafting. Users wanting the old lighter-weight "draft + shallow proof attempt" behavior should use /lean4:draft --mode=attempt. Users wanting skeletons only should use /lean4:draft.
/lean4:formalize "Every continuous function on a compact set is bounded"
/lean4:formalize --rigor=axiomatic "Zorn's lemma implies AC"
/lean4:formalize --source ./paper.pdf # Ingest, pick claims, formalize
/lean4:formalize --source ./paper.pdf "Theorem 3.2" # Source as context, topic as claim
/lean4:formalize --output=file --out=MyTheorem.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
drafting or proving.
Startup requirements:
| Arg | Required | Default | Description |
|---|---|---|---|
| topic | no | — | Informal claim to formalize. Optional when --source provides it (source-led flow). At least one of topic or --source must be given; omitting both is a startup validation error. |
| --rigor | no | checked | checked | sketch | axiomatic |
| --verify | no | best-effort | best-effort | strict. Verification strictness for key claims. See learn-pathways.md. |
| --level | no | intermediate | beginner | intermediate | expert |
| --output | no | chat | chat | scratch | file |
| --out | no | — | Output path. Required when --output=file; startup validation error if missing. |
| --overwrite | no | false | Allow overwriting existing files with --output=file. Without flag, existing target → startup validation error. |
| --mathlib-template | no | false | Emit the mathlib module-system file header on --output=file writes regardless of detected project context. Requires --output=file; mutually exclusive with --no-mathlib-template. |
| --no-mathlib-template | no | false | Never emit the mathlib module-system file header on --output=file writes, regardless of detected project context. Requires --output=file; mutually exclusive with --mathlib-template. |
| --source | no | — | File path, URL, or PDF to seed formalization. See learn-pathways.md. |
| --intent | no | math | auto | usage | math. See learn-pathways.md. |
| --presentation | no | auto | informal | supporting | formal | auto. Controls user-facing display, not Lean backing. See learn-pathways.md. |
| --claim-select | no | — | first | named:"..." | regex:"...". Noninteractive claim selection from --source. |
| --draft-mode | no | attempt | skeleton | attempt. Mode for the draft phase (default is attempt in formalize context). |
| --draft-elab-check | no | best-effort | best-effort | strict. Elaboration check for the draft phase. |
| --deep | no | never | never | ask | stuck | always. Deep mode for prove phase. |
| --deep-sorry-budget | no | 1 | Max sorries per deep invocation |
| --deep-time-budget | no | 10m | Advisory: scopes deep-mode subagent work. Not tracked or enforced. |
| --commit | no | ask | ask | auto | never |
| --golf | no | prompt | prompt | auto | never |
--output=file without --out → startup validation error--output=scratch → .scratch/lean4/formalize-<timestamp>.lean (workspace-local). Auto-create .scratch/lean4/ if missing; warn if .scratch/ is not in .gitignore.--output=file with existing target and no --overwrite → startup validation error--mathlib-template with --no-mathlib-template → startup validation error (mutually exclusive)--mathlib-template or --no-mathlib-template without --output=file → startup validation error (either flag only affects whole-file writes)--intent, --presentation, or --verify with invalid value → startup validation error.--intent=auto inference: apply the shared inference rules, then coerce internals → usage and authoring → usage (formalize does not define behavior for those intents).--source + unreadable format → warn + ask for text excerpt.--claim-select without --source → startup validation error (nothing to select from).| Policy | Behavior |
|---|---|
first | Select the first extractable claim from --source |
named:"..." | Match claims by title/label substring (e.g. named:"Theorem 3.2") |
regex:"..." | Match claims by regex on extracted claim text |
Standalone formalize processes one claim per invocation (batch-size is 1).
Applies to --output=file whole-file writes only; chat and scratch modes are unchanged. Formalize follows the same gate contract as draft — see Mathlib Template Gate for the full resolution rules. Summary:
--mathlib-template → emit the mathlib module-system file header (mathlib-style.md); --no-mathlib-template → do not. Only a flag resolving to true participates in precedence; explicit false is equivalent to omission.lean4-skills-project-context --from <dir> from the nearest existing parent directory of the --out target, require schema equal to project-context/v1, and read intent.contributing_upstream: yes → emit the header; no → existing generic behavior; unknown → existing generic behavior plus a one-line advisory (pass --mathlib-template if this file targets mathlib).schema, or a malformed intent record) degrades to unknown with source helper-failure; the gate never blocks a write.public section after the module docstring — declarations in a module are private by default, and public import alone does not export them.flag, the helper's intent.source, or helper-failure) in the Resolved Inputs block.Formalize does not run lake exe mk_all; it emits the correct file shape and reminds the user to run it after adding files. Checkpoint-time mk_all enforcement is #111's scope.
Invoke draft logic (same algorithm as /lean4:draft):
--intent and --presentation.--source.lean_diagnostic_messages on skeleton.--draft-mode=attempt, default) — lean_goal + lean_multi_attempt loop.Invoke prove logic (same algorithm as /lean4:prove):
--rigor.Rigor completion criteria:
| Rigor | sorry | Diagnostics | Non-standard axiom | Silent global axiom |
|---|---|---|---|---|
checked | FAIL | FAIL | FAIL | FAIL |
axiomatic | FAIL | FAIL | allowed if in ledger | FAIL |
sketch | allowed | allowed | allowed | FAIL |
sketch: never fails finalization, but always prints -- ⚠ NOT VERIFIED — sketch only banner.axiomatic: allows explicit assumptions but hard-fails on any silently introduced global axiom not in the ledger.If proof blocked (no counterexample found), offer in order: local assumptions as parameters (preferred) → explicit axiomatic draft with assumption ledger + warning.
If the prove phase concludes the statement is wrong (deep mode emits next_action = redraft), present to user:
T_salvaged with weaker statementPermission boundary: Formalize owns the right to change declaration headers. The prove phase itself cannot — it recommends redraft, and formalize executes the change with user approval.
Offer the depth-check menu:
Output format follows --presentation: informal → prose with math notation (no Lean blocks unless user requests "show Lean backing"); supporting → prose with selective Lean snippets; formal → Lean code blocks as primary content. In scratch or file mode, additionally write a .lean file regardless of presentation.
-- Assumption Ledger
-- ┌──────────────────────────┬────────────────────┬───────────┬─────────────────────┐
-- │ Assumption │ Justification │ Scope │ Introduced by │
-- ├──────────────────────────┼────────────────────┼───────────┼─────────────────────┤
-- │ h_cont : Continuous f │ stated in claim │ parameter │ user-stated │
-- │ h_bdd : IsBounded S │ needed for compact │ parameter │ assistant-inferred │
-- └──────────────────────────┴────────────────────┴───────────┴─────────────────────┘
propext, Classical.choice, Quot.sound — not flagged. All others reported as non-standard.
Always run lean4-skills-check-axioms-inline <target> --report-only before presenting final results.
--output requests it.lean_goal) over file writes for compilation checks. If LSP unavailable and temp file needed for internal compilation, write only under /tmp/lean4-formalize/, auto-cleanup after use, warn user before writing./formalize never commits in standalone mode (--commit is accepted for prove-phase compatibility but inert — no staging, no committing). --output=file writes but does not stage or commit.--output=file, --output=scratch) restricted to workspace root (scratch uses .scratch/lean4/). Reject path traversal (../) or absolute paths outside workspace. Internal temp files may use /tmp/lean4-formalize/.--output=file with existing target requires --overwrite; otherwise startup validation error.namespace Assumptions. Always verified with lean4-skills-check-axioms-inline <target> --report-only.guardrails.sh rules apply./lean4:draft — skeleton-only drafting (no prove phase)/lean4:autoformalize — autonomous synthesis (unattended)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
/autoformalizeAutonomous end-to-end formalization from informal sources/autoproveAutonomous multi-cycle theorem proving with explicit stop budgets/checkpointSave progress with a safe commit checkpoint/diagnoseDiagnostics, cleanup, and migration help/disproveGuided counterexample search with certified refutation/draftDraft Lean declaration skeletons from informal claimsOther plugins' commands for the same job