Skip to content

MrAMS/bazel-cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Bazel Cache Cleaner

A lightweight Bash utility to analyze local Bazel caches, visualize disk usage, and automatically clean up "Zombie Caches" (build artifacts from projects that have been deleted or moved).

Why?

Bazel creates a unique cache directory for every workspace path. If you delete a project folder or rename it, Bazel does not automatically delete the corresponding 10GB+ cache. Over time, this leads to massive disk space waste ("Zombie Caches").

This script:

  1. Scans your ~/.cache/bazel directory.
  2. Identifies which cache belongs to which project.
  3. Detects if the source project still exists.
  4. Safely removes caches for missing projects.

Installation

Linux

# Clone the repo
git clone https://github.com/MrAMS/bazel-cleaner.git
cd bazel-cleaner

# Make executable
chmod +x bazel-cleaner.sh
./bazel-cleaner.sh

Example

> ./bazel-cleaner.sh
======================================================
            Bazel Cache Analyzer & Cleaner
======================================================
Scanning cache root: /home/xxx/.cache/bazel/_bazel_xxx

[ ACTIVE PROJECTS ] (Source code exists)
SIZE       HASH                               WORKSPACE PATH
--------------------------------------------------------------------------------
18G        3d3f0bf4c054c1a0e344c65347031846   /path1
11G        4c1ab9ffe96429c4bed7b28c86d3ca11   /path2
568M       4cbc11659a14a9b9a6ba3215d0ca2852   /path3

[ ZOMBIE CACHES ] (Source code deleted/moved)
SIZE       HASH                               MISSING PATH
--------------------------------------------------------------------------------
109M       01aec6312cf6a6f6d6c435fd3cda7ff0   /path4
21M        baba25190f7866ee22ffd482bcc1b8e3   /path5

--------------------------------------------------------------------------------
Found 2 zombie caches occupying approx .12 GB.
These caches correspond to projects that no longer exist at their original path.
Do you want to delete these zombie caches? [y/N] y

Cleaning up...
Deleting 01aec6312cf6a6f6d6c435fd3cda7ff0... [sudo] password for xxx:
Done.
Deleting baba25190f7866ee22ffd482bcc1b8e3... Done.

Cleanup complete! Reclaimed .12 GB.

About

A lightweight Bash utility to analyze local Bazel caches, visualize disk usage, and automatically clean up "Zombie Caches"

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages