Lean 4 Proofs
You're formalizing a theorem and Lean is fighting you: the proof state isn't what you expected, you can't remember the name of the Mathlib lemma you need, and the build cache is stale. TeXRA drives a real Lean 4 language server so its agents can read compiler diagnostics, inspect the proof state at any point, search Mathlib, and manage your build — all without leaving your editor.
Prerequisites
TeXRA doesn't ship a Lean toolchain — you bring your own. It then drives Lean in one of two ways, depending on how you run TeXRA.
You always need a Lake project
Lean tools only work on .lean files that live inside a Lake project — a folder (or ancestor folder) containing a lakefile.lean or lakefile.toml. If there's no lakefile, the language server has nothing to attach to. Create one with lake new myproject or lake init.
In VS Code
- Install the official Lean 4 extension (
leanprover.lean4) from the Marketplace. - Open a folder containing a
lakefile.leanorlakefile.toml. - The Lean 4 extension auto-installs elan and the Lean toolchain on first open.
TeXRA detects the running Lean 4 extension and routes its tools through it — so you share the exact same language server, diagnostics, and proof state you see in the editor.
In the CLI
There's no Lean 4 extension to lean on, so TeXRA spawns its own server (lake env lean --server, one process per project). You need lake on your PATH:
- Install elan (the Lean version manager):bash
curl https://elan.lean-lang.org/elan-init.sh -sSf | sh - Confirm it works in a fresh shell:bash
lake --version - Open a folder containing a
lakefile.leanorlakefile.toml.
If you don't have elan yet, see the Lean community install guide.
Activating Lean
There is no switch to flip. Lean support turns on automatically the moment a Lean-capable agent runs a Lean tool on a .lean file in a Lake project. To get going, just pick a Lean-capable agent (see below) and ask it to work on your proof.
Check that it's working
Open Dashboard → Tools () → Lean 4 Proof Assistant () to confirm your setup is detected. The panel shows whether the Lean 4 extension is available (VS Code) or whether lake was found (CLI), and lists any active language servers — one per Lake project root.
Choosing an Agent
The built-in lean agent is always available. The Lean Project team adds four more agents — a leanOrchestrator plus the specialists it delegates to — which are remote agents, so sign in to sync them.
| Agent | Availability | Best for |
|---|---|---|
lean | Built-in | Writing and debugging proofs; iterating until a file compiles |
leanSearch | Remote / Lean team | Finding the right Mathlib lemma, exploring APIs, formalization questions |
leanSimplifier | Remote / Lean team | Cleaning up proofs to Mathlib-quality, upstream-ready standards |
leanBlueprint | Remote / Lean team | Building dependency-tracked LeanBlueprint LaTeX that bridges math ↔ Lean |
leanOrchestrator | Remote / Lean team | Coordinating a whole formalization project across the agents above |
To load the full set, open the Multi-Agent tab and select the Lean Project team. Formalizing a paper that's also part LaTeX? The Mathematician team bundles the lean agent alongside the LaTeX and research agents.
TIP
Pick any agent from the Agent dropdown (). Check Dashboard → Agents () to see exactly which tools each one has enabled.
What You Can Do
Just describe the task in plain language — the agent decides which tools to call. Here's what's happening under the hood.
Read Diagnostics
Check Proofs/GroupTheory.lean for errors and fix the first one.The lean_diagnostics tool reports compilation errors, type mismatches, unsolved goals, warnings, and hints with their locations. Use it to check whether a file compiles after each change.
Inspect the Proof State
What's the goal state at line 42 of Analysis/Limits.lean?The lean_inspect tool reads the tactic proof state (goal), the expected type in term mode (term_goal), or the type signature and docs of an identifier (hover) at a given position — the same information Lean shows in its infoview.
Search Mathlib
Find a Mathlib lemma that says the sum of two continuous functions is continuous.The lean_loogle tool queries Loogle to find lemmas by name, type signature, or the constants they mention — so the agent cites real Mathlib lemmas instead of inventing them.
Refresh a Stuck File
The diagnostics for this file look stale — restart the Lean server for it.The lean_file tool runs file-scoped commands: restart (reload the language server for one file) and refresh_dependencies (a lighter refresh). Reach for these when results look out of date.
Manage the Project
Download the Mathlib build cache, then build the project.The lean_project tool runs project-wide commands without a target file:
- Server:
restart_server,stop_server - Build:
build,clean,fetch_cache(whole project),fetch_file_cache(current file's imports — faster) - Setup (VS Code only):
install_elan,update_elan,install_deps,select_toolchain
Setup commands are VS Code-only
The setup commands drive the Lean 4 extension's installers, so they only work in the VS Code build. In the CLI they fail with a "run the shell command directly" message — manage your toolchain with elan and lake directly instead (for example elan self update, elan toolchain install, or lake update). See the Lean install guide.
Build output
lean_project's build command starts a build but doesn't capture its output. To see errors afterward, the agent runs lean_diagnostics on the relevant files (or lake build directly via the bash tool when it needs the raw log).
Troubleshooting
"No Lean project found" — The file isn't inside a Lake project. Make sure a lakefile.lean or lakefile.toml exists in the file's folder or an ancestor. Create one with lake new / lake init.
"Failed to spawn lake env lean --server" (CLI) — lake isn't on your PATH. Install elan and confirm lake --version works in a fresh shell.
Tools fail in VS Code — Install the Lean 4 extension (leanprover.lean4) and open the project so its language server starts.
Diagnostics look stale — Ask the agent to run lean_file with restart, or lean_project with restart_server. A missing Mathlib cache can also cause long stalls — try fetch_cache.
The Lean Project agents aren't in my list — leanSearch, leanSimplifier, leanBlueprint, and leanOrchestrator are remote agents. Sign in and select the Lean Project team to sync them. The built-in lean agent works without signing in.
Next Steps
- Built-in Agents — full reference for the
leanagent and others - Remote Agents — sign in to unlock the Lean Project specialist agents
- Research Tools — literature search, citations, and Wolfram verification
- Workflow Agents — how the orchestrator coordinates multi-agent runs