How to contribute to mathlib: a first pull request
October 16, 2026 · Oyren AI Team (AI-written)

TL;DR: A first mathlib pull request can fix one docstring or add one lemma beside related results. Build the edited module from a fork, explain the mathematical change, and disclose any AI assistance in the pull request. Free Oyren Docs holds the LaTeX notes; formal Lean 4 and Mathlib work runs in an Oyren Codespace on a managed cloud computer.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
A contribution that fits the library
The mathlib contribution overview welcomes small fixes and single-lemma additions to existing theories. A new theory needs a fit with the library's scope and maintainers; the #mathlib channel on Lean Zulip is the place to discuss that before coding.
A docstring fix may clarify a hypothesis already present in a declaration. For a missing lemma, search mathlib documentation and try exact? first; the same result may already have another name.
A fork and a branch
The contribution workflow starts with a fork of leanprover-community/mathlib4. These commands clone the fork, download compiled dependencies and isolate the change:
git clone https://github.com/<username>/mathlib4.git
cd mathlib4
lake exe cache get
git switch -c my-first-lemma
origin now points to the fork. lake exe cache get avoids rebuilding all dependencies from source. The repository's lean-toolchain pins the compiler used by elan; the Git guide covers upstream remotes.
Local compilation and library style
Build the edited module before pushing. A full build checks downstream imports and may take longer for files low in the import graph.
lake build Mathlib.Algebra.Group.Basic
lake build
The first command illustrates a targeted module build; the second is the full build. The workflow guide also allows CI to perform the full build after a targeted local check. When adding a new file, run this command to update Mathlib.lean:
lake exe mk_all
A finished contribution has no sorry placeholder; WIP marks a pull request that still needs work.
A new lemma belongs near results on the same structure, with the surrounding namespace, section and variable declarations checked first. The naming conventions, style guide and documentation guide cover searchable names, formatting and useful docstrings.
The pull request record
Open the branch against leanprover-community/mathlib4. Mathlib's commit conventions put the change type and module scope in the title:
feat(Algebra/Group/Basic): add lemma about <statement>
The description explains the gap, the new statement and the checks run. List moved or deleted declarations under Moves: or Deletions: above the --- separator. A comment containing WIP, easy, awaiting-author or LLM-generated changes the corresponding workflow label; gh pr status reports CI.
AI use and reviewer discussion
Mathlib's AI policy requires the PR description to name the AI tools used and how they affected the diff. Substantial generated code also gets the LLM-generated label. LLM-written GitHub and Zulip comments are prohibited, and the author must be able to justify every line to reviewers.
A scratch note can hold the informal argument, exact? search results and open reviewer questions. Free Oyren Docs stores that note and its LaTeX; the mathlib4 checkout and lake commands run in an Oyren Codespace on a managed cloud computer. The cloud VS Code guide covers that setup.
Choose or create a workspace, then select the Lean 4 add-on in Codespace setup.
Set up Lean 4 in a Codespace