uv cache prune
Prune all unreachable objects from the cache.Usage
Description
Remove unreachable cache entries while preserving data that may still be useful. This is a more selective alternative touv cache clean.
Pruning removes:
- Unused package versions
- Outdated builds
- Orphaned cache entries
- Pre-built wheels (when using
--cimode)
- Cache entries for currently installed packages
- Recent package downloads
- Wheels built from source (in
--cimode)
uv cache prune will block until no process is reading the cache. Use --force to bypass this check.
Options
--ci
Optimize the cache for persistence in a continuous integration environment, like GitHub Actions.
By default, uv caches both the wheels that it builds from source and the pre-built wheels that it downloads directly, to enable high-performance package installation. In some scenarios, though, persisting pre-built wheels may be undesirable. For example, in GitHub Actions, it’s faster to omit pre-built wheels from the cache and instead have re-download them on each run. However, it typically is faster to cache wheels that are built from source, since the wheel building process can be expensive, especially for extension modules.
In --ci mode, uv will prune any pre-built wheels from the cache, but retain any wheels that were built from source.
--force
Force removal of the cache, ignoring in-use checks.
By default, uv cache prune will block until no process is reading the cache. When --force is used, uv cache prune will proceed without taking a lock.
--force while other uv processes are running may lead to cache corruption or unexpected behavior.
Examples
Prune unreachable entries
Prune for CI environments
Force prune without waiting
Combine CI mode with force
Use cases
CI/CD cache optimization
In GitHub Actions or similar CI systems:Regular maintenance
Periodically prune cache to maintain optimal size:After project cleanup
After removing projects or changing dependencies:Disk space management
When running low on disk space:Behavior details
What gets pruned
Standard prune:- Package versions no longer referenced
- Temporary build artifacts
- Stale lock files
- Orphaned cache entries
--ci):
- All pre-built wheels downloaded from indexes
- Preserves wheels built from source distributions
- Preserves source distributions
What gets preserved
Standard prune:- Packages in active virtual environments
- Recently accessed cache entries
- Package metadata
--ci):
- Wheels built from source (often contain compiled extensions)
- Source distributions
- Build dependencies
Performance considerations
After pruning:- Cache size is reduced
- No impact on currently installed packages
- Some packages may need re-downloading
- Smaller cache to upload/download
- Faster CI job startup
- Pre-built wheels download quickly anyway
- Source-built wheels are expensive to rebuild
When to use prune vs clean
Use uv cache prune:
- Regular maintenance
- CI/CD optimization
- Gradual disk space recovery
- When you want to keep useful cache entries
Use uv cache clean:
- Need maximum disk space immediately
- Corrupted cache entries
- Complete cache reset
- Testing clean-slate installations
CI mode details
Why CI mode is faster
In CI environments:- Download speed: CI runners typically have fast internet connections
- Cache overhead: Uploading/downloading large caches takes time
- Build cost: Building from source is expensive (compiling C extensions)
- Removing fast-to-download pre-built wheels
- Keeping expensive-to-build source wheels
Example cache sizes
Typical project before pruning:uv cache prune --ci:
GitHub Actions example
Before optimization:--ci:
Related commands
uv cache clean- Remove all cache entries or specific packagesuv cache dir- Show the cache directoryuv cache size- Show the cache size
Notes
- Pruning is safer than cleaning (preserves useful entries)
--cimode is specifically designed for continuous integration- Pruning does not affect currently installed packages
- The cache will automatically repopulate as needed
--forceshould be used carefully to avoid cache corruption- Regular pruning can help maintain optimal cache performance
- CI mode can significantly reduce CI/CD cache sizes and restore times