Skip to content
Back to skills

Lean Build

ASecurity

Build, test, and debug Lean 4 projects using Lake. Use when building the ComputationalPaths project, checking for errors, running tests, cleaning artifacts, or debugging Lean 4 compilation issues.

  • 666 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added February 9, 2026
toolsgobashtestingdebugginggitperformance

Security analysis

A93/100
  • highPerforms destructive filesystem operations

Pro shows the line behind each finding and how to fix it

Scanned February 10, 2026

npx -y skills add majiayu000/claude-skill-registry --skill lean-build --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Lean Build?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Lean Build
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-lean-build/badge)](https://www.skillsdirectory.com/skills/majiayu000-lean-build)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: lean-build
description: Build, test, and debug Lean 4 projects using Lake. Use when building the ComputationalPaths project, checking for errors, running tests, cleaning artifacts, or debugging Lean 4 compilation issues.
---

# Lean 4 Build & Debug

This skill covers building, testing, and debugging the ComputationalPaths Lean 4 project using Lake (Lean's build system).

## Project Configuration

**Toolchain**: `leanprover/lean4:v4.24.0` (see `lean-toolchain`)

**Build file**: `lakefile.toml`
```toml
name = "computational_paths"
version = "0.1.0"
defaultTargets = ["computational_paths"]

[[lean_lib]]
name = "ComputationalPaths"

[[lean_exe]]
name = "computational_paths"
root = "Main"
```

## Essential Commands

### Building

```bash
# Build entire project (default targets)
lake build

# Build specific library
lake build ComputationalPaths

# Build specific module
lake build ComputationalPaths.Path.HIT.Circle

# Build executable
lake build computational_paths

# Build with verbose output
lake build -v
```

### Running

```bash
# Run the executable
lake exe computational_paths
```

### Cleaning

```bash
# Clean build artifacts
lake clean

# Full clean (removes .lake directory)
rm -rf .lake && lake build
```

### Updating Dependencies

```bash
# Update lake-manifest.json
lake update

# Resolve and fetch dependencies
lake exe cache get  # if using Mathlib cache
```

## Common Build Errors & Solutions

### 1. Type Mismatch

```
type mismatch
  h
has type
  Path a b
but is expected to have type
  Path a' b'
```

**Solution**: Check that terms have the expected types. Use `@` for explicit arguments or add type annotations.

### 2. Unknown Identifier

```
unknown identifier 'foo'
```

**Solution**:
- Check imports at the top of the file
- Verify the definition exists in the imported module
- Use fully qualified name: `ComputationalPaths.Path.foo`

### 3. Failed to Synthesize Instance

```
failed to synthesize instance
  Decidable (RwEq p q)
```

**Solution**: RwEq is not decidable. Use axioms or `noncomputable` where needed.

### 4. Universe Issues

```
universe level mismatch
```

**Solution**: Ensure consistent universe variables. HITs typically use `Type u`.

```lean
axiom MyHIT : Type u  -- not Type or Type*
```

### 5. Noncomputable Definition

```
'foo' depends on 'axiom', and therefore must be marked as 'noncomputable'
```

**Solution**: Add `noncomputable` keyword:

```lean
noncomputable def foo := ...
```

### 6. Missing Hypothesis

```
invalid 'exact' tactic, term has type ... but is expected to have type ...
```

**Solution**: The proof term doesn't match the goal. Check:
- Argument order
- Implicit vs explicit arguments
- Use `@` to make implicits explicit

### 7. Ambiguous Notation

```
ambiguous, possible interpretations: ...
```

**Solution**: Use qualified names or local `open` with hiding:

```lean
open Path hiding trans  -- if 'trans' conflicts
```

## Debugging Techniques

### Check Types

```lean
#check myTerm
#check @myFunction  -- show all arguments
#check (myTerm : ExpectedType)  -- verify type
```

### Print Definitions

```lean
#print myDefinition
#print axioms myTheorem  -- show axioms used
```

### Reduce Terms

```lean
#reduce myTerm  -- fully normalize
#eval myTerm    -- for decidable terms only
```

### Trace Tactics

```lean
set_option trace.Meta.Tactic.simp true in
theorem foo : ... := by simp
```

### Show Goals

```lean
theorem foo : ... := by
  show_term exact?  -- suggests exact term
  trace "{goal}"    -- print current goal
```

## Project Structure Validation

### Check Module Imports

Ensure `ComputationalPaths/Path.lean` imports all submodules:

```lean
import ComputationalPaths.Path.Basic
import ComputationalPaths.Path.Rewrite
import ComputationalPaths.Path.Groupoid
import ComputationalPaths.Path.Homotopy.FundamentalGroup
import ComputationalPaths.Path.HIT.Circle
-- etc.
```

### Verify File Locations

```
ComputationalPaths/
├── Basic.lean                 → import ComputationalPaths.Basic
├── Path.lean                  → import ComputationalPaths.Path
└── Path/
    ├── Basic/
    │   └── Core.lean          → import ComputationalPaths.Path.Basic.Core
    └── HIT/
        └── Circle.lean        → import ComputationalPaths.Path.HIT.Circle
```

## CI Integration

The project uses GitHub Actions with `leanprover/lean-action@v1`:

```yaml
# .github/workflows/lean_action_ci.yml
name: Lean Action CI
on: [push, pull_request, workflow_dispatch]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: leanprover/lean-action@v1
```

### Running CI Locally

Simulate CI by running:

```bash
lake clean && lake build
```

## Performance Tips

### Incremental Builds

Lake caches compilation. After changes, only affected files rebuild:

```bash
lake build  # rebuilds only changed modules
```

### Parallel Builds

Lake builds independent modules in parallel by default.

### Avoiding Recompilation

- Don't modify imports unnecessarily
- Keep module dependencies minimal
- Use `private` for internal definitions

## Lake Commands Reference

| Command | Description |
|---------|-------------|
| `lake build` | Build default targets |
| `lake build <target>` | Build specific target |
| `lake clean` | Remove build artifacts |
| `lake update` | Update dependencies |
| `lake exe <name>` | Run executable |
| `lake env <cmd>` | Run command in Lake environment |
| `lake --version` | Show Lake version |
| `lake --help` | Show help |

## Toolchain Management

### Check Current Toolchain

```bash
cat lean-toolchain
# leanprover/lean4:v4.24.0
```

### Update Toolchain

Edit `lean-toolchain`:
```
leanprover/lean4:v4.XX.Y
```

Then rebuild:
```bash
lake clean && lake build
```

## Quick Diagnostic Checklist

When builds fail:

1. **Check toolchain**: `cat lean-toolchain`
2. **Clean and rebuild**: `lake clean && lake build`
3. **Check imports**: Ensure all needed modules are imported
4. **Check file paths**: Module path must match filesystem
5. **Look for typos**: Lean is case-sensitive
6. **Check universe levels**: Ensure consistency
7. **Add `noncomputable`**: If using axioms
8. **Check CI**: Push to see if CI passes

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.