[KongchangAI]
· 2 min read· 1,167 words

Claude Code + Git Worktree Eating Your Mac's Disk? Breaking Down 152GB and How to Clean It Safely

Claude Code + Git Worktree Eating Your Mac's Disk? Breaking Down 152GB and How to Clean It Safely

AI agents running parallel Worktrees pile up 67GB of Node Modules—a tested four-step safe cleanup method.

Based on a Bilibili creator's test, AI coding tools (Claude Code, Codex) running multiple Git Worktrees in parallel each install dependencies independently, causing Node Modules caches to balloon—307 Node Modules take 67.4GB on one Mac. The article breaks down where space goes (old Xcode Device Support etc. take 91GB) and offers a four-step cleanup: read-only DU investigation, proper Worktree removal (no rm -rf), red lines for AI models/Docker/PNPM Store/snapshots, and CleanBeat tiered cleanup.

AI coding tools boost productivity, but they're also quietly becoming disk hogs. A Bilibili creator's hands-on test found that a development Mac had a staggering 152.45GB flagged for cleanup—with 307 Node Modules alone accounting for 67.4GB. Behind this, parallel workflows involving AI agents like Claude Code and Codex alongside Git Worktree are the main culprits. Based on that test, this article breaks down where the space goes and provides a complete set of steps for safe cleanup.

Why does AI coding eat so much disk?

When running multiple AI coding agents (like Claude Code and Codex) in parallel, each Git Worktree is a complete working directory, and each one requires reinstalling dependencies—plus drawing history and various caches. A 256GB Mac will hit the red within weeks. The creator pointed out that the biggest chunk came from three items: old Xcode Device Support, simulator caches, and Derived Data, totaling 91GB found. Among package manager and AI tool caches, UV cache was 10.58GB, NPM 4.32GB, Claude Code only cleans old versions, and Hugging Face models and PNPM Store are shown but not deletable. DU stats show 307 Node Modules taking 67.4GB and .Codex taking 4.8GB—note that these are occupied sizes, not necessarily cleanable amounts.

Old Device Support

To check your own situation, you can run a single read-only DU command (no changes, no deletions), or use the official free generator to select and generate.

Git Worktree is a multi-working-tree mechanism provided by Git that allows the same repository to check out multiple branches into different directories simultaneously. Each Worktree has its own working area and staging area but shares the same Git object database and references. For AI coding agents, this means multiple tasks can run in parallel without interfering with each other; the cost is that each Worktree must re-run dependency installation like npm install, causing node_modules to multiply. When removing a Worktree, use git worktree remove rather than deleting the directory directly, otherwise stale pointers will remain in Git's metadata.

Step 2: Tear down WorkTrees—don't let rm -rf destroy your code

rm -rf is the easiest and also the most dangerous. Letting the AI agent free up disk space itself is the same, because WorkTrees may still contain uncommitted changes, and some repositories even track build artifacts in Git—blind deletion will lose code. Deleting directories directly also leaves stale pointers in Git's WorkTrees.

Also leaves stale pointers in Git's WorkTrees

The safe approach has three steps: first use git worktree list to list all WorkTrees; then go in and run git status to confirm there are no uncommitted or unpushed changes; finally use git worktree remove to tear them down, then git worktree prune to clean up remnants. Claude Code defaults to .claude in the user directory, and Codex and Cursor each have their own directories that need to be checked separately.

git worktree prune is used to clean up Worktree metadata records. When a Worktree directory is manually deleted or moved, its management files remain under .git/worktrees/, and git worktree list may show stale entries. Running prune removes these records that no longer correspond to actual directories but does not touch any working files. Typically, you first use git worktree remove for normal teardown, then prune as a fallback to clean up abnormal remnants—together they prevent pointer corruption.

Step 3: Honest boundaries—these four types of space should not be auto-deleted by tools

Some space looks cleanable but shouldn't be touched carelessly. The creator drew four red lines:

  • Local AI models and Docker: re-downloading takes tens of minutes to hours; only use their built-in commands to delete based on size.
  • PNPM Store: relies on hard links to share dependencies; don't force-delete the directory—use pnpm store prune.
  • System data: APFS local snapshots and iCloud Drive are outside the sandbox; legitimate sandbox tools shouldn't pretend they can clean them.
  • Running app caches and Git-tracked files: always skip.

And iCloud Drive

APFS local snapshots are point-in-time snapshots of the macOS file system used for Time Machine local backups and system rollback, stored at the volume layer that sandbox tools cannot reach. The "purgeable" space they show is not truly idle; the system reclaims it automatically when needed. Manually deleting snapshots may affect the backup chain and recovery capability. PNPM Store uses a content-addressed hard link mechanism where multiple projects share the same dependency files; directly deleting the Store directory breaks links for all projects. The correct approach is pnpm store prune to remove only unreferenced packages.

Step 4: Use CleanBeat to see clearly before deleting

In the demo, the app CleanBeat scanned that machine in 7.9 seconds, with results in three tiers: suggested cleanup (checked by default), needs confirmation (unchecked by default), and display only (not deletable). Each item states the impact of deletion, running apps are automatically locked, project artifacts are sorted by size from largest to smallest, each row shows the last modified time, Git-tracked files are always skipped, and parse failures are blocked by default.

The creator also acknowledged coverage limits: by default it covers visible projects and .claude and .codex WorkTrees, but Cursor and hidden directories inside repositories are not yet covered and require manual checks. AI drawing history is cleaned by time, handling only top-level drawing files without touching Memory. Deletions go two ways: items go to Trash (recoverable) or rebuildable caches are deleted directly—nothing is deleted before the user confirms. CleanBeat is available on the Mac App Store, runs in a sandbox, requires no Root, has no long-running background process, and file names and contents never leave the machine.

And hidden directories inside repositories

Four-step checklist summary

First do a read-only investigation, then tear down WorkTrees properly, hold the boundary around models, Docker, and snapshots, and confirm impact before deleting. To save effort, you can use GetCleanBeat.app or search CleanBeat on the Mac App Store—scanning is free, and the first two cleanups are free.

The convenience of AI coding shouldn't come at the cost of a crashed disk. Understand where the space goes and respect tool boundaries—only then can your development environment be both efficient and safe.

One-line Summary

AI agents running parallel Worktrees pile up 67GB of Node Modules—a tested four-step safe cleanup method.

Paragraph Summary

Based on a Bilibili creator's hands-on test, the article reveals that when AI coding tools (Claude Code, Codex, etc.) run multiple Git Worktrees in parallel, each worktree installs dependencies independently, causing Node Modules and other caches to pile up massively—307 Node Modules on one Mac took 67.4GB. The author breaks down where the space goes, notes that three items including old Xcode Device Support take 91GB, and provides a four-step cleanup checklist: first investigate with read-only DU commands, then properly tear down Worktrees with git worktree remove (no rm -rf), hold the four red lines around local AI models, Docker, PNPM Store, and system snapshots, and finally use CleanBeat for tiered cleanup. Emphasizes understanding where space goes and respecting tool boundaries to balance efficiency and safety.

#Claude Code disk space#Git Worktree cleanup#Node Modules 67GB#Mac disk cleanup#AI coding tools cache#CleanBeat#safe disk cleanup Mac
Share:

Related articles