MathCode is a terminal-based AI coding agent that automates mathematical proofs. It takes a math problem written in natural language, automatically converts it into a Lean 4 theorem (Lean 4 is a programming language and interactive theorem prover), and attempts a formal proof. In Lean 4, propositions and proofs are written like code, and the compiler mechanically verifies that the logic is sound. It is backed by Mathlib, a library of more than 100,000 theorems and lemmas. In August 2026, v0.3.0 was released, completing the local WebUI workflow and expanding the tool set with the ability to ingest papers directly into a vault and a broader suite of agentic Lean tools.
Key Features
- Automatic conversion from natural language to Lean 4 theorems: Pass a problem on the command line, such as
mathcode -p "prove that the square of an even number is even", and MathCode formalizes it as a Lean 4 theorem and attempts a proof. Output is saved to theLeanFormalizations/directory - Fast compile checks via a persistent Lean REPL: By loading Mathlib once as a warm-up at startup, subsequent compile checks drop from roughly 30 seconds to about 0.4 seconds. Dedicated tools such as LeanGoal (goal inspection), LeanCheck (compilation with feedback), and LeanVerify (final strict verification) are used in combination
- Mathlib search and subgoal decomposition: Integrates with leansearch.net and Loogle to search for existing Mathlib lemmas, and breaks complex theorems into subgoals that are proved in parallel. Multiple planners compete with different proof strategies, and the best result is selected
- Accumulating a theorem and axiom library:
/theorem-storesaves proven theorems, and/axiomatizesaves assumptions that come up during conversation, as a persistent library for reuse in later proofs - Visualization with an Obsidian knowledge graph: Dependencies between proven theorems are automatically generated as an Obsidian knowledge graph, making it easier to grasp the big picture even in large-scale formalization projects
- Local WebUI and multi-LLM support: v0.3.0 completes the local WebUI workflow, available via
./run webui. For the backend, in addition to the default OpenAI Codex CLI, it supports Anthropic models by settingANTHROPIC_API_KEY, as well as models accessed via Amazon Bedrock, Google Vertex AI, Azure AI Foundry, and OpenRouter
Pricing
MathCode itself is published on GitHub as open source (Apache 2.0); clone the repository and run the setup script to get started. However, since generating proofs involves calling an LLM, you will separately incur usage fees from the model provider. The default is authentication via OpenAI’s Codex CLI (codex auth login), and by switching environment variables you can also use an Anthropic API key or models from other providers such as Bedrock, Vertex AI, Azure AI Foundry, and OpenRouter.
Pricing information is current as of August 2026. MathCode itself has no pricing plans, but fees on the LLM provider side are subject to change, so please check the official site and each provider’s documentation for details.
Pros and Cons
✅ Pros
- Handles everything in one place, from converting a natural-language math claim into a Lean 4 theorem to completing the formal proof
- The persistent Lean REPL dramatically cuts the compile wait times that tend to pile up during proof trial and error
- Accumulates proven theorems and axioms as a library that can be reused in later proofs
- Lets you search existing Mathlib lemmas through integration with leansearch.net and Loogle
- Offers a choice of multiple LLM providers, including OpenAI, Anthropic, Bedrock, Vertex AI, and OpenRouter
⚠️ Cons
- Limited to Lean 4 as the proof assistant; it cannot be used with others such as Coq or Isabelle
- Supported operating systems are macOS (arm64) and Linux (x86_64, with an AVX2-capable CPU) only; Windows is not natively supported
- While MathCode itself has no pricing plans, LLM usage fees are required separately
- Without prior knowledge of Lean 4 and Mathlib, it may be difficult to pinpoint and address the cause when a proof fails
Comparison with Similar Services
| Criteria | MathCode | Lean Copilot | Harmonic Aristotle |
|---|---|---|---|
| Provider | Math-AI | LeanDojo team (academic project) | Harmonic |
| Form | Terminal-based AI coding agent (OSS) | Tactic-assistance tool used during Lean proofs (OSS) | Commercial product offered via web, mobile, and API |
| Main use | Converts natural-language problems into Lean 4 theorems and automates proofs | Assists with tactic suggestions, lemma search, and proof search during proving | High-difficulty IMO-level proofs and formal verification for research and enterprise |
| Model handling | Switch between multiple providers such as Codex CLI and Anthropic | Runs pre-trained or bring-your-own models locally or in the cloud | Uses Harmonic’s own dedicated model |
| Pricing | Free and open (LLM fees separate) | Free and open | Commercial (contact for details) |
Beyond these, LeanDojo, a research project that provides Lean 4 proof datasets and retrieval infrastructure, and general-purpose AI coding agents such as Claude Code and Codex CLI could also be considered comparable in a broad sense. However, the latter lack the features specialized for Lean 4 formal proofs (persistent REPL, theorem library, Mathlib search integration, and so on), which is what sets MathCode apart.
Who Is It For
- Researchers and students who routinely formalize and prove mathematical theorems and propositions in Lean 4
- Anyone who wants to quickly transcribe a natural-language proposition into a Lean 4 theorem
- Those who want to automate Lean proof work as an extension of existing AI coding agents such as Codex CLI
- People managing large-scale formalization projects who want to visualize proof dependencies along the way
Summary
MathCode is a terminal-based AI agent that converts mathematical claims written in natural language into Lean 4 formal proofs. It is packed with touches that reduce friction in real Lean 4 formalization work, such as fast compile checks via a persistent Lean REPL, integration with Mathlib search, and turning proven theorems into a reusable library. On the other hand, its use is limited to Lean 4 as the proof assistant and its supported operating systems are restricted to macOS and Linux, so its target audience is narrowed to those who write Lean 4 proofs on a regular basis. As of August 2026, v0.3.0 has been released, and feature expansion continues with additions such as the WebUI.