Skip to main content

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 to uv cache clean. Pruning removes:
  • Unused package versions
  • Outdated builds
  • Orphaned cache entries
  • Pre-built wheels (when using --ci mode)
Pruning preserves:
  • Cache entries for currently installed packages
  • Recent package downloads
  • Wheels built from source (in --ci mode)
By default, 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.
This is particularly useful in CI/CD pipelines to optimize cache size and restore time.

--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.
WARNING: Using --force while other uv processes are running may lead to cache corruption or unexpected behavior.

Examples

Prune unreachable entries

Expected output:

Prune for CI environments

Removes pre-built wheels but keeps wheels built from source. Expected output:

Force prune without waiting

Immediately prunes the cache without waiting for locks.

Combine CI mode with force

Use cases

CI/CD cache optimization

In GitHub Actions or similar CI systems:
This keeps the cache small and fast to restore.

Regular maintenance

Periodically prune cache to maintain optimal size:

After project cleanup

After removing projects or changing dependencies:
This removes cache entries no longer needed.

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 mode (--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 mode (--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
CI mode benefits:
  • 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:
  1. Download speed: CI runners typically have fast internet connections
  2. Cache overhead: Uploading/downloading large caches takes time
  3. Build cost: Building from source is expensive (compiling C extensions)
CI mode optimizes for this by:
  • Removing fast-to-download pre-built wheels
  • Keeping expensive-to-build source wheels

Example cache sizes

Typical project before pruning:
After uv cache prune --ci:

GitHub Actions example

Before optimization:
After optimization with --ci:

Notes

  • Pruning is safer than cleaning (preserves useful entries)
  • --ci mode is specifically designed for continuous integration
  • Pruning does not affect currently installed packages
  • The cache will automatically repopulate as needed
  • --force should 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