Urgent.News

What's breaking now, across hundreds of outlets.

AI

Claude Code Worktrees Filling Your Disk? How to Find and Remove Leftover Git Worktrees

Note: Originally published at getcleanbit.app . Written by the CleanBit developer with AI assistance. All measurements were taken on a real developer Mac. Claude Code and Codex worktrees fill up your Mac because Git shares commit history across worktrees, but never shares untracked build directories like node_modules , Rust target/ , Swift .build/ , or Python .venv/ . Every parallel agent task…

Claude Code and Codex worktrees can consume large amounts of disk space on your Mac. This occurs because each worktree maintains its own copy of dependencies and build directories, leading to multiple gigabytes of data being stored even after merging a pull request. The report measured significant disk usage from worktrees, including 66.3 GB across multiple node_modules, .venv, and .build folders.

To locate and remove these leftover worktrees safely, start by conducting a read-only audit of your system. Use the following commands to identify the location and size of worktrees:

1. Run a read-only audit of worktree directories:

```bash

du -sh ~/.claude/worktrees ~/.codex/worktrees ~/.cursor/worktrees

```

2. Identify the largest individual worktree folders:

```bash

du -sh ~/.claude/worktrees/* ~/.codex/worktrees/* | sort -h | tail -20

```

3. List all registered Git worktrees:

```bash

git worktree list

```

4. Find prunable worktrees (locked, detached, or already missing):

```bash

git worktree list --porcelain

```

5. Determine the largest node_modules, target, and .build folders within worktrees:

```bash

find ~/.claude/worktrees ~/.codex/worktrees ~/.cursor/worktrees \

\( -name node_modules -o -name target -o -name .build -o -name .venv \) \

-type d -prune -exec du -sh {} + | sort -h | tail -25

```

Note that `du` provides the total directory size, not the amount of data safe to delete. Always verify the Git status before removing a worktree to ensure no uncommitted changes exist.

Different AI coding tools store worktrees in various locations, each requiring specific cleanup methods. Claude Code typically uses `~/.claude/worktrees`, while Codex employs `~/.codex/worktrees`. Cursor and other tools may create worktrees in hidden or sibling directories of the repository. Manual removal is recommended using `git worktree remove` to prevent data loss due to untracked or modified files. Always commit changes or create patches before deleting worktrees to preserve valuable work.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

What your AI agent loads, costs and exposes: a free offline check

Personal AI agents like OpenClaw, Hermes Agent or nanobot keep their memory, skills and config as plain files on your disk.

  • Scanner checks plain text keys, planted instructions, hidden charges in AI agents
  • Free tool requires Node.js 20+, no extra software needed
  • Shows exact file locations of issues, suggests fixes and false positive warnings

Nigerian startups make Google’s Africa AI Lab

Intron, Termii and Vendy secure three of 10 places in Google’s Africa Applied AI Lab, gaining access to Gemini and Gemma models and expert mentorship. Read More: https://punchng.com/nigerian-startups-make-googles-africa-ai-lab/

More from Wednesday 25 November →