Read-only code review of Lean proofs
Reviews Lean 4 proofs for correctness, style, and optimization opportunities without modifying files.
npx claudepluginhub cameronfreer/lean4-skillsRead-only review of Lean proofs for quality, style, and optimization opportunities.
Non-destructive: Files are restored after analysis.
/lean4:review # Review changed files (default)
/lean4:review File.lean # Review specific file
/lean4:review File.lean --line=89 # Review single sorry
/lean4:review File.lean --line=89 --scope=deps # Review sorry + its dependencies
/lean4:review --scope=project # Review entire project (prompts)
| Arg | Required | Description |
|---|---|---|
| target | No | File or directory to review |
| --scope | No | sorry, deps, file, changed, or project |
| --line | No | Line number for single-sorry scope |
| --codex | No | External review via Codex (interactive handoff) |
| --llm | No | Use llm CLI with model |
| --hook | No | Run custom analysis script |
| --json | No | Output structured JSON for external tools |
| --mode | No | batch (default) or stuck (triage) |
Scope levels:
| Scope | Description |
|---|---|
sorry | Single sorry at --line (requires target file + --line) |
deps | Sorry + same-file helpers and directly referenced lemmas (requires target file + --line) |
file | All sorries in target file |
changed | Files modified since last commit (git diff) |
project | Entire project (requires confirmation) |
Defaults:
--scope=changed--scope=file--line → --scope=sorrysorry or file)Note: Scope filtering is implemented by the reviewing agent, not the underlying scripts. The agent reads script output and filters results to match the requested scope.
Project-wide confirmation:
⚠️ This will review the entire project.
Proceed? (yes / no)
Output header always shows scope:
## Lean4 Review Report
**Scope:** Core.lean:89 (single sorry)
Batch mode (default):
Stuck mode:
Stuck mode output format:
## Stuck Review — Core.lean:89
**Top 3 blockers:**
1. Missing lemma about tendsto_atTop → search Mathlib.Topology.Order
2. Typeclass instance missing for MeasurableSpace β → add `haveI`
3. Proof too long (38 lines) → extract helper lemma first
**Flag:** Statement may be false (optional — see below)
**Recommended next action:** Search for tendsto variants in Topology/Order
Falsification flag: Include when analysis suggests statement may be false:
decide or native_decideExample: **Flag:** Statement may be false (decidable goal failed decide)
Blocker priority (stuck mode):
decide, repeated proof failures)The agent selects files based on scope, then runs these analyses (per file or directory):
lake build (project-wide); for scoped review (--scope=file), use lean_diagnostic_messages(file) + lake env lean <path/to/File.lean> (run from project root) first${LEAN4_PYTHON_BIN:-python3} "$LEAN4_SCRIPTS/sorry_analyzer.py" <target> --format=json --report-onlybash "$LEAN4_SCRIPTS/check_axioms_inline.sh" <target> --report-only${LEAN4_PYTHON_BIN:-python3} "$LEAN4_SCRIPTS/find_golfable.py" <target> --filter-false-positivesStuck mode: Steps 5–6 are skipped; focus is on blockers (steps 1–4) for quick triage.
## Lean4 Review Report
**Scope:** Core.lean:89 (single sorry)
### Build Status
✓ Project compiles
### Sorry Audit (N remaining)
| File | Line | Theorem | Suggestion |
|------|------|---------|------------|
| ... | ... | ... | ... |
### Axiom Status
✓ Standard axioms only
### Style Notes
- [file:line] - [suggestion]
### Golfing Opportunities
- [pattern] → [optimization]
### Recommendations
1. [action item]
Custom hooks receive structured JSON on stdin with file information, sorries, axioms, and build status. They return JSON with a suggestions array.
See review-hook-schema.md for full input/output schemas, examples, and performance tips for rate-limited APIs.
When --codex is specified, display context for external review:
─────────────────────────────────────────────────────────
CODEX REVIEW — {scope description}
─────────────────────────────────────────────────────────
[Context based on scope:]
- sorry: ±50 lines around the target sorry
- deps: Target sorry + referenced helpers/lemmas
- file: Full file content
- changed: All modified files (git diff)
- project: Full project (requires confirmation)
If no sorries in scope:
- file: Include top-level definitions + relevant sections
- changed: Include diff + changed file list
To review in Codex CLI:
1. Run `codex` in project directory
2. Type `/review` → select "Review uncommitted changes"
3. Or paste the above context and ask for review
Return suggestions as JSON:
{"suggestions": [{"file": "...", "line": N, "severity": "hint|warning", "message": "..."}]}
─────────────────────────────────────────────────────────
After review completes (internal or external), prompt:
## Review Complete
Would you like me to create an action plan from the review findings?
- [yes] — Enter plan mode with 3-6 step implementation plan
- [no] — End review, return to conversation
If "yes":
/lean4:prove to apply fixes (review itself remains read-only)Note: When --mode=stuck is triggered by prove/autoprove, skip this prompt—the proving command handles the follow-up with its own "Apply this plan? [yes/no]" prompt.
When using --json, output follows this structure:
{
"version": "1.0",
"build_status": "passing" | "failing",
"sorries": [
{"file": "Core.lean", "line": 89, "theorem": "convergence_main", "goal": "..."}
],
"axioms": {
"standard": ["propext", "Classical.choice", "Quot.sound"],
"custom": []
},
"style_notes": [
{"file": "Core.lean", "line": 42, "message": "Consider using field syntax"}
],
"golfing_opportunities": [
{"file": "Core.lean", "line": 78, "pattern": "have chain", "suggestion": "Inline or extract"}
],
"summary": {
"total_sorries": 3,
"total_custom_axioms": 0,
"style_issues": 2,
"golf_opportunities": 5
}
}
Note: Codex CLI's /review command is interactive-only. There's no codex review <sha> CLI command for automation. Two approaches are available:
codex in the project directory/review and select:
Tip: Use /diff after /review to see exact file changes.
codex exec)For CI or scripted reviews, use codex exec with a review prompt:
codex exec "Review this Lean 4 proof for correctness, focusing on:
1. Incomplete sorries and proof gaps
2. Type mismatches or missing instances
3. Non-standard axiom usage
$(cat Core.lean)
" --output-schema lean4-review-schema.json -o review-output.json
Schema file (lean4-review-schema.json):
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"suggestions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"file": {"type": "string"},
"line": {"type": "integer"},
"severity": {"enum": ["hint", "warning"]},
"category": {"enum": ["sorry", "axiom", "style", "structure"]},
"message": {"type": "string"}
},
"required": ["file", "line", "severity", "message"]
}
}
},
"required": ["suggestions"]
}
See Codex SDK Cookbook for CI integration patterns.
Future autonomous external review: External review is currently manual-handoff only. Future versions may support autonomous external review via non-interactive CLI execution (e.g.,
codex exec) behind an explicit opt-in flag (--external-autonomous). Until then, unattended autoprove runs default to internal review.Requirements for autonomous external review:
- Stable JSON input/output contract
- Timeout + retry + cost budgets
- Safe fallback to internal review on external failure
- Explicit opt-in flag, not default behavior
#print axioms, then restores/lean4:prove - Guided cycle-by-cycle proving/lean4:autoprove - Autonomous multi-cycle proving/lean4:golf - Apply golfing optimizations/reviewPerform exhaustive code reviews using multi-agent analysis, ultra-thinking, and worktrees
/review[DEPRECATED] Use /ce:review instead — renamed for clarity.