Skip to main content
Bazel keeps an output base for every workspace path it has built in, a server for each one recently used, and every archive it has downloaded. None of it is collected: a machine that creates a git worktree per task, as coding agents do, gains an output base per task. Two tasks deal with it:

1. See what is there

Every output base, grouped by state, largest first: when it was last used, the memory its Bazel server holds, the repository and branch it is checked out on, and its workspace. --sort=size measures sizes, which takes a du of every base; drop it for a listing that returns at once. Two numbers usually matter:
  • Removable bases: orphaned (the workspace was deleted) and idle (unused for 30 days). The listing ends with their count and size.
  • Running servers: each holds its memory until it has been idle for Bazel’s --max_idle_secs (3 hours by default). The line under the census gives the total.

2. Preview

Lists each base gc would remove and why, the stale download-cache entries, and the total it would free. Nothing is deleted.

3. Reclaim

Lists the same plan and asks before deleting. A base Bazel uses after the scan is left alone. To remove a base the rules keep, such as an undetermined one, name it:

4. Tune the rules

The grace period keeps an orphaned base for an hour after its last use, so a worktree torn down and recreated at the same path gets its base back.

5. Run it on a schedule

gc asks before deleting, and refuses off a terminal unless --force says it may. A nightly cron entry on a developer machine:
Run it with the volumes your workspaces live on mounted: a workspace gc cannot find counts as gone.

Worktrees and agents

Each worktree is a new workspace path, so each gets its own output base, server and external/ tree. Deleting the worktree orphans them; gc removes them an hour after their last use. aspect worktree avoids that by reusing a pool of slots at fixed paths, each keeping one warm output base for its next lease. gc does not treat a pool slot’s base as orphaned, though it still removes one idle past --base-max-idle-days; aspect worktree prune deletes slots that have gone stale, base and all.

Scripting

Both tasks take --output=json. For example, the workspaces whose bases gc would remove: