If you've been working with Rust for a while, you've probably noticed something alarming: your target directories are massive. A single project can easily have a 5-10GB target folder. Multiple projects? You might be looking at 50GB or more.
Let's break down what's actually in there and what you can safely delete.
What's Inside target/
The target directory contains everything Cargo generates during compilation:
target/
├── debug/ # Debug build artifacts
├── release/ # Release build artifacts
├── doc/ # Generated documentation
├── package/ # Packaged crates
└── .fingerprint/ # Incremental build tracking
debug/ and release/
These contain your compiled binaries and intermediate artifacts:
- deps/: Compiled dependencies (this is the big one)
- build/: Build script outputs
- incremental/: Incremental compilation data
- Your actual binary or library
Why Dependencies Are So Large
When Cargo compiles your project, it compiles every dependency from source. A typical project might have:
- 200+ transitive dependencies
- Each compiled to native code
- Debug symbols included (in debug builds)
- Multiple versions of the same crate
A debug build of a web framework project often exceeds 2GB just in the deps folder.
The Hidden Multipliers
Several factors make target directories grow even larger:
Multiple Build Profiles
target/
├── debug/ # Default debug build
├── release/ # Release builds
├── custom/ # Custom profiles
Each profile has its own complete set of dependencies.
Cross-Compilation
If you build for multiple targets:
target/
├── x86_64-unknown-linux-gnu/
├── aarch64-apple-darwin/
├── wasm32-unknown-unknown/
Each target triples (or more) your disk usage.
Workspaces
Cargo workspaces share a target directory, which is efficient for builds but means one massive folder that includes artifacts from all workspace members.
When Is It Safe to Delete?
The target directory is always safe to delete. It contains only generated files that Cargo can recreate.
The Cost of Deletion
After deleting target:
- First compile: Full recompilation, 30 seconds to several minutes
- Subsequent compiles: Fast incremental builds resume
If you're not actively working on a project, there's no reason to keep its target folder.
Cargo's Built-in Cleanup
Cargo provides some cleanup commands:
# Remove the target directory
cargo clean
# Remove a specific profile
cargo clean --release
# Remove package artifacts only
cargo clean --package my-crate
The Limitation
cargo clean removes the entire target directory. There's no built-in way to:
- Clean only old/unused dependencies
- Clean across multiple projects
- Identify which projects are active
Better Approaches
cargo-cache
cargo install cargo-cache
cargo cache --autoclean
This can clean unused crates from the registry cache, but doesn't handle per-project target directories.
Manual Approach
# Find all target directories
find ~/projects -name "target" -type d
# Check sizes
find ~/projects -name "target" -type d -exec du -sh {} \;
This works but is tedious for regular maintenance.
Cluttered
Cluttered automates this process:
- Scans for all Rust projects
- Shows target directory sizes
- Indicates which projects are active
- Cleans with one click
- Moves to Trash for safety
Best Practices
1. Clean Dormant Projects
If you haven't touched a project in months, clean its target folder. Recompilation takes a few minutes, but you'll recover gigabytes.
2. Use sccache
cargo install sccache
export RUSTC_WRAPPER=sccache
sccache shares compiled artifacts between projects, reducing duplication.
3. Limit Target Sizes
In your .cargo/config.toml:
[build]
# Reduce debug symbols
debug = 1
# Faster links, smaller artifacts
[profile.dev]
split-debuginfo = "unpacked"
4. Clean Before Archiving
If you're storing projects in Git or backups, always run cargo clean first. There's no reason to store gigabytes of regenerable data.
How Much Can You Recover?
From our testing across developer machines:
| Developer Type | Rust Projects | Average target Size | Total Recoverable |
|---|---|---|---|
| Hobbyist | 5-10 | 2GB | 10-20GB |
| Professional | 10-20 | 3GB | 30-60GB |
| Heavy User | 20+ | 4GB | 80-100GB+ |
Most developers can recover 20-50GB just from Rust target directories.
Conclusion
Rust's target directory is a necessary part of the build process, but it doesn't need to live forever. For projects you're not actively working on, cleaning the target folder is safe, simple, and recovers significant disk space.
Whether you use Cargo's built-in clean command, a tool like Cluttered, or manual shell commands, regular cleanup of target directories should be part of your development workflow.
Try Cluttered to automate Rust cleanup along with 11 other ecosystems.