Command line

canolean [OPTIONS] [PATH...]

Each PATH can be a file, a directory, or - for stdin. Directories are searched recursively for *.lean files, skipping hidden directories like .git and .lake. Use -- to stop option parsing.

Modes

Flag Behavior
(none) Reads a single file (or stdin if omitted or -) and writes the formatted source to stdout.
--check Checks whether each input is already formatted, prints any unformatted paths to stdout (or <stdin> for stdin), and exits with status 1 if any differ.
-i, --in-place Formats files in place atomically, rewriting only files that change.

You can’t combine --check and --in-place. Formatting multiple files or a directory requires one of them. You can’t combine stdin (-) with other paths or pass it to --in-place.

Options

Option Meaning
-j N, --jobs N Number of parallel workers for --check and --in-place (default: available CPUs).
--bundled-only Keeps non-bundled imports in the source without loading them.
--lean-path PATH Adds project .olean search paths. PATH uses the platform PATH separator and the flag can be repeated.
--lake Loads search paths from lake env printenv LEAN_PATH.
--ext NAME Enables a built-in extension. Currently only verso is available (see Extensions).
-V, --version Prints the version and exits.
-h, --help Prints usage and exits.

--jobs, --lean-path, and --ext also accept --flag=value, and -j accepts -jN.

Imports

  • Default: imports are looked up only in the Lean toolchain. An import that isn’t found there fails with a parse error.
  • --bundled-only: keeps non-bundled imports in the file without loading them, using limited built-in parser support for a few common imports. Formatting is relative to that reduced context rather than your Lake environment, and canolean prints a notice to stderr: canolean: bundled-only context; unresolved imports were not loaded.
  • --lean-path PATH / --lake: loads compiled project .olean modules from the given search paths (or via lake env printenv LEAN_PATH). Any custom syntax brought into scope by those imports is extracted on demand by bridge/Frontend.lean, checked, and used to lay out the file.

--bundled-only cannot be combined with --lean-path or --lake.

Runtime lookup

canolean looks for its frontend helper in this order:

  1. CANOLEAN_FRONTEND
  2. A sibling canolean-frontend next to the canolean binary
  3. The build-time path
  4. The embedded helper, extracted to $XDG_CACHE_HOME/canolean (falling back to $HOME/.cache/canolean or the temp directory)

Lean’s libraries and libleanshared are resolved in this order:

  1. LEAN_SYSROOT
  2. The toolchain the binary was built with
  3. elan’s leanprover--lean4---v4.36.0 toolchain
  4. lean --print-prefix on PATH

Exit status

Status Meaning
0 Success (with --check, all inputs are already formatted).
1 --check found at least one file that needs formatting.
2 Error.

Errors

Errors go to stderr with exit status 2 and produce no formatted output. Formatting errors have the form canolean: KIND: MESSAGE:

Kind Cause
parse Lean couldn’t parse the input, or an import wasn’t found.
unsupported The file uses unsupported syntax, or a layout rule couldn’t be derived or verified (see Scope and limits).
incomplete The layout table would exceed 16,000,000 column states.
frontend The frontend helper failed to start or returned an invalid response.

In --check and --in-place modes, errors include the file path and processing continues for the remaining files:

$ canolean --check proj
canolean: proj/Macro.lean: unsupported: unsupported command Lean.Parser.Command.macro; grammar-changing and executable commands are not admitted
proj/Unformatted.lean
$ echo $?
2