Skip to main content
The leo clean command removes build artifacts and output directories from your Leo project.

Syntax

Description

The clean command removes:
  • build/ directory - Compiled bytecode and build artifacts
  • outputs/ directory - Compiler output files and AST snapshots
It does not remove:
  • Source code in src/
  • Project manifest program.json
  • Environment file .env
  • Dependencies directory (cache remains intact)

Examples

Basic Clean

Output:

Before Clean

Project structure:

After Clean

Project structure:
The build/ and outputs/ directories are removed.
The imports/ directory is preserved. It contains dependency bytecode that will be reused on rebuild.

When to Use Clean

1. Fresh Build

Start with a clean slate:
Useful when:
  • Build artifacts might be corrupted
  • Dependencies have changed
  • Switching between branches

2. Disk Space

Reclaim disk space:
Build artifacts can be large, especially for complex programs.

3. Before Deployment

Ensure clean build before deploying:

4. After Switching Branches

Clean when switching git branches:

5. Troubleshooting Build Issues

Resolve build inconsistencies:
The --no-cache flag also clears dependency cache.

What Gets Removed

build/ Directory

Contains:
  • main.aleo - Compiled program bytecode
  • main.abi.json - Application Binary Interface
  • program.json - Build manifest

outputs/ Directory

Contains:
  • initial_ast.json - AST snapshot after parsing
  • type_checked_ast.json - AST after type checking
  • *.ast - AST snapshots from each compiler pass
  • Intermediate compiler output

What Doesn’t Get Removed

Source Code

Project Configuration

Dependencies

To also clear dependency cache, use leo build --no-cache after cleaning.

Clean Workflow

Typical Development Cycle

Before Committing

Continuous Integration

Comparison with Other Commands

Troubleshooting

Clean Has No Effect

If leo clean reports no changes:
No output means directories already don’t exist. This is normal after:
  • Fresh checkout
  • Never built before
  • Already cleaned

Directories Recreated Immediately

Running leo build after clean recreates directories:
This is expected behavior.

Permission Errors

Solutions:
  1. Check file permissions:
  2. Ensure files aren’t locked:
    • Close editors
    • Stop running processes
    • Check file system
  3. Use elevated permissions (if appropriate):

Partial Clean

If only one directory is removed:
The build/ directory might not exist. This is normal.

Manual Clean

You can manually clean without Leo:
Equivalent to:

Clean and Reset

For a complete reset:
Removing global cache affects all Leo projects on your system.

Best Practices

1. Clean Before Important Builds

2. Don’t Commit Build Artifacts

Ensure .gitignore contains:

3. Clean After Dependency Changes

4. Periodic Cleanup

Clean old projects:

5. CI/CD Integration

Always clean in CI:

Disk Space Considerations

Build artifacts size:
  • Small program: ~100 KB - 1 MB
  • Medium program: 1 MB - 10 MB
  • Large program: 10 MB - 100 MB+
With AST snapshots enabled:
  • Can be 2-5x larger
For multiple projects:

Next Steps