Lake provides two commands for creating new packages:Documentation Index
Fetch the complete documentation index at: https://mintlify.com/leanprover/lean4/llms.txt
Use this file to discover all available pages before exploring further.
lake new creates a package in a new subdirectory, while lake init sets up a package in the current directory. Both commands generate the same set of starter files; the only difference is whether they create the directory for you.
lake new vs lake init
- lake new
- lake init
Creates a new directory named after the package, changes into it, and generates the project scaffold:This is equivalent to:
If you are using Lake through elan, you can create a package pinned to a specific Lean version using the
+ syntax:Templates
Both commands accept an optional template argument that controls which starter files are generated. The template is specified after the package name:Available Templates
| Template | What it creates |
|---|---|
std | Library and executable (default) |
exe | Executable only |
lib | Library only |
math-lax | Library only with a Mathlib dependency |
math | Library with Mathlib standards for linting and workflows |
Configuration Language Suffix
Append.toml or .lean to any template name to choose the format of the generated lakefile. The default is TOML.
Generated Directory Structure
Runninglake new hello (default std template, TOML) creates the following layout:
Lake also initialises a Git repository in the package directory via
git init. If Git is not installed, this step is skipped silently.Generated Source Files
Hello/Basic.lean — An example module with a simple definition:
Hello.lean — The library root. Downstream code imports this module:
Main.lean — The executable entry point:
Generated lakefile.toml
name— the package nameversion— the initial version (0.1.0)defaultTargets— targets built by a barelake build[[lean_lib]]— declares theHellolibrary[[lean_exe]]— declares thehelloexecutable whose root module isMain
Generated lean-toolchain
Step-by-Step Walkthrough
Create the package
hello/ directory, generates all starter files, and runs git init.Build the project
Hello library and the hello executable. Outputs go to .lake/build/.Using the math Template
For projects that depend on Mathlib, use the math or math-lax template:
lakefile.toml will already include a mathlib dependency:
Choosing a Configuration Format
If you prefer the Lean DSL over TOML, pass the.lean suffix to any template:
lakefile.lean uses the Lake.DSL syntax: