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 artifactsoutputs/directory - Compiler output files and AST snapshots
- Source code in
src/ - Project manifest
program.json - Environment file
.env - Dependencies directory (cache remains intact)
Examples
Basic Clean
Before Clean
Project structure:After Clean
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:- Build artifacts might be corrupted
- Dependencies have changed
- Switching between branches
2. Disk Space
Reclaim disk space:3. Before Deployment
Ensure clean build before deploying:4. After Switching Branches
Clean when switching git branches:5. Troubleshooting Build Issues
Resolve build inconsistencies:--no-cache flag also clears dependency cache.
What Gets Removed
build/ Directory
Contains:main.aleo- Compiled program bytecodemain.abi.json- Application Binary Interfaceprogram.json- Build manifest
outputs/ Directory
Contains:initial_ast.json- AST snapshot after parsingtype_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
| Command | Effect | Cache | Dependencies |
|---|---|---|---|
leo clean | Removes build/ and outputs/ | Preserved | Preserved |
leo build | Builds program | Uses cache | Downloads if needed |
leo build --no-cache | Builds program | Clears & rebuilds | Re-downloads |
Troubleshooting
Clean Has No Effect
Ifleo clean reports no changes:
- Fresh checkout
- Never built before
- Already cleaned
Directories Recreated Immediately
Runningleo build after clean recreates directories:
Permission Errors
-
Check file permissions:
-
Ensure files aren’t locked:
- Close editors
- Stop running processes
- Check file system
-
Use elevated permissions (if appropriate):
Partial Clean
If only one directory is removed:build/ directory might not exist. This is normal.
Manual Clean
You can manually clean without Leo:Clean and Reset
For a complete reset: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+
- Can be 2-5x larger