LLM-powered automation for Lean.
Installation · Providers · Usage · Demo · Configuration
LLMLean integrates LLMs and Lean for tactic suggestions and proof completion.
You can use an LLM running on your laptop or in the cloud.
Usage
LLMLean is used interactively in VS Code with the Lean extension. Suggestions appear in Lean's Infoview.
Suggest the next step
Use llmstep for a tactic that makes progress on the current goals:
example (n : Nat) : n + 0 = n := by
llmstep
You can also give a prefix, such as llmstep "apply ".
Complete a proof
Use llmqed for a completion that closes all remaining goals:
example (P Q : Prop) (h : P ∧ Q) : Q ∧ P := by
llmqed
Both tactics check suggestions in Lean and can retry with Lean's error messages. Click Try this in the Infoview to insert a suggestion into your proof.
The demo project has examples to try in VS Code, with worked solutions.
Installation
Requires Lean 4.35.0.
-
Add LLMLean to your project's
lakefile.lean:require llmlean from git "https://github.com/cmu-l3/llmlean.git" -
Run
lake update llmleanfrom your project directory. -
Import LLMLean in your Lean file:
import LLMlean
Setup
OpenAI with gpt-6-luna is the default.
OpenAI · Cloud models · Default
Get an OpenAI API key and set it in your terminal:
export OPENAI_API_KEY="<your-api-key>"
No configuration file is needed. To customize the model, create llmlean.toml
in your project directory:
provider = "openai"
model = "gpt-6-luna"
Quit VS Code, then open your project from the same terminal so that it picks up the key:
code .
OpenRouter · Cloud models
Set your OpenRouter key in your terminal:
export OPENROUTER_API_KEY="<your-api-key>"
Create llmlean.toml in your project directory, using a model identifier from OpenRouter:
provider = "openrouter"
model = "<model-id-listed-by-the-provider>"
Quit VS Code, then run code . from the same terminal so that it picks up the key.
LM Studio · Local models
Load a model in LM Studio and start its local server. Create llmlean.toml in your
project directory, using the model identifier shown in the Developer tab:
provider = "local"
base_url = "http://localhost:1234/v1"
model = "qwen/qwen3.5-9b"
reasoning_effort = "none"
No API key is needed for the default local server. For this model,
reasoning_effort = "none" turns thinking off for LLMLean requests.
Ollama · Local models
Install and start Ollama, then pull a model:
ollama pull qwen3.5:9b-q4_K_M
Create llmlean.toml in your project directory:
provider = "local"
model = "qwen3.5:9b-q4_K_M"
No API key is needed.
For other servers and connection details, see the provider guide. Local servers must support the Responses API.
Project context
LLMLean uses context from both the current file and imported files in your project. Along with the current goals and proof so far, it includes earlier definitions, lemma statements, and notation to help the model use results you have already proved.
Use llmcontext inside a proof to preview the prompt without making a model request.
See context selection for budgets and comparison modes.
Documentation
| Guide | Contents |
|---|---|
| Demo project | Examples and worked solutions in VS Code |
| Configuration | Models, generation budgets, project context, and Lean options |
| Benchmarks | Experiments comparing context policies and proof completion |
| Providers | Cloud APIs and local server configuration |
| Migration | Updating from older versions |
Development
Issues and pull requests are welcome. To run the checks from the repository directory:
lake build llmlean
lake test
python3 scripts/test_transport.py
Mathlib examples are in LLMleanTest.
Run python3 scripts/benchmark_context.py for offline context benchmarks covering
long proofs, many declarations, and direct/transitive imports. --prove opts into
model-backed comparisons using your configured provider.
Citation
LLMLean evolved from llmstep. If you would like to cite LLMLean in an academic context, please cite the llmstep paper (NeurIPS 2023 Workshop on MATH-AI):
@inproceedings{welleck2023llmstep,
title = {{LLMSTEP}: {LLM} proofstep suggestions in {Lean}},
author = {Welleck, Sean and Saha, Rahul},
booktitle = {NeurIPS 2023 Workshop on MATH-AI},
year = {2023},
url = {https://mathai2023.github.io/papers/40.pdf}
}
License
MIT.