Lean 4 and mathlib in Cloud VS Code
August 9, 2026 · Oyren AI Team (AI-written)
Recommendation: A local Lean 4 project with mathlib needs elan, lake, the VS Code extension and a download of compiled mathlib files before the first goal appears. An Oyren Codespace with the Lean 4 + Mathlib add-on starts with the toolchain, the Mathlib cache and the infoview already installed, in VS Code in the browser.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
Local setup and the Codespace add-on
Both routes end at the same place: a Lean file open beside the infoview, which shows the current goal.
The local route (orange) follows the mathlib project instructions:
lake +v4.24.0 new my_project math
cd my_project
lake update
lake exe cache get
lake +v4.24.0 new my_project math:+v4.24.0asks elan, the Lean toolchain manager, for that Lean version (the one the instructions name at the time of writing).new my_projectcreates the project folder, andmathis the template that declares mathlib as a dependency.lake updatefetches mathlib and the other dependencies. According to the instructions, updating mathlib this way also downloads the matching cache.lake exe cache getdownloads compiled mathlib files into~/.cache/mathlibinstead of compiling mathlib from source. It only works in projects that depend on mathlib, andlake exe cache get!forces a fresh download after a failed one.
The Lean 4 extension for VS Code then starts the language server and the infoview.
The Codespace route (blue) skips those steps. An Oyren Codespace is a cloud dev machine with VS Code in the browser, a terminal and coding agents. For one-file exercises without a repository, compare the Lean web editor and cloud options. The launch wizard has three fields that matter here. The Lean 4 + Mathlib add-on is a checkbox; ticked, it boots a machine image with the Lean toolchain, the Mathlib cache and the editor's infoview already installed, so nothing is downloaded at launch, and the session appears as Codespace (Lean). A first prompt is optional: with one, the session opens on Chat with the agent already working on it; without one, it opens on the editor. A repository is optional too: a selected repository is cloned onto the machine, and without one the session starts in an empty /workspace.
The official Lean web playground is a shared scratchpad for one file at a time, without persisted project files. A project with its own files, mathlib and a repository needs one of the two routes above.
A first proof in the infoview
The Lean demo on oyren.ai uses a small pricing lemma:
theorem uplift_le_cap (h : u ≤ cap) :
applyUplift u ≤ applyCap cap := by
unfold applyUplift applyCap
exact mul_le_mul_of_nonneg_left h base.le
(h : u ≤ cap): the hypothesis, available inside the proof under the nameh.applyUplift u ≤ applyCap cap: the statement the proof has to establish.unfold applyUplift applyCap: replaces both function names with their definitions, so the goal becomes an inequality between two products.exact mul_le_mul_of_nonneg_left h base.le: closes the goal with the mathlib lemmamul_le_mul_of_nonneg_left, which states that multiplying both sides of an inequality by a nonnegative factor keeps it.hsuppliesu ≤ cap, andbase.lesupplies that the factor is nonnegative.
While the cursor is inside the proof, the infoview lists the hypotheses above the turnstile and the goal after it: ⊢ applyUplift u ≤ applyCap cap. After the last tactic it shows No goals, which means Lean accepted the proof of this statement.
Coding agents and the kernel check
The statement (yellow) is the theorem a person wants proved; the agent works on the proof, not on the statement. A coding agent in the Codespace terminal (blue), such as Claude Code (claude), Codex (codex) or Gemini CLI (gemini), edits the Lean file; the Codespace image also carries opencode, Qwen Code, Cursor CLI and the Antigravity CLI. Lean checks every edit and the kernel checks the finished proof (green). The infoview (orange) reports the remaining goals, which send the agent back to drafting, until No goals ends the loop. A human review (gray) closes it: a proof that closes its goal can still prove the wrong statement, for example after a hypothesis was added that makes the theorem trivial, so the statement and the diff need a person's review.
The opencode in the cloud use case shows the same agent workflow outside Lean.
Typical first projects
- Students starting with
rflandsimpon small definitions. - Researchers formalizing a result against mathlib's existing lemmas.
- Engineers checking a property of business logic, such as the pricing cap above.
- Project Euler problems in Lean 4, using mathlib's number theory.
Limits
Local configuration does not carry over: a new Codespace has none of a laptop's keybindings, extension forks or shell aliases until they are added. The preinstalled cache matches one mathlib version, so a cloned repository that pins a different mathlib commit needs its own lake exe cache get, or a build when no cache exists for that commit.
A Codespace with the Lean 4 + Mathlib add-on starts from the workspace launcher.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
Set up Lean 4 in a Codespace