Claude Code, Cursor and Codex run in git worktrees so several agents can work at once. Each worktree is a full checkout with its own node_modules and build output, and they pile up quietly. One Claude Code user found 27 forgotten worktrees using 80 GB (issue 63087). 61 Codex worktrees of a Rails app took about 100 GB (issue 35383).
Where they live
-
Claude Code:
.claude/worktrees/inside each repository (older versions used~/.claude-worktrees) -
Cursor:
~/.cursor/worktrees/ -
Codex:
~/.codex/worktrees/, on a detached HEAD rather than a branch
See what they take
git worktree list # inside a repository
du -sh .claude/worktrees/* 2>/dev/null | sort -h # inside each repository
du -sh ~/.cursor/worktrees/*/* ~/.codex/worktrees/* 2>/dev/null | sort -h
Check before you remove one
git -C <path> status --short # prints nothing if nothing is uncommitted
git -C <path> status --short --ignored # .env and other ignored files you'd lose
git log --oneline main..<branch> # prints nothing if the branch is merged
Squash merges leave the commits out of main, so ask GitHub instead: gh pr list --head <branch> --state merged --json headRefOid, and check it matches git rev-parse <branch>.
Remove it
git worktree remove <path>
Skip --force: without it, git refuses when there's uncommitted work, which is the point. The branch stays, so nothing committed is lost.
Stop the pile-up
-
Claude Code: lower
cleanupPeriodDays(default 30) -
Cursor: lower
cursor.worktreeMaxCount(default 25) - Codex: lower the limit of 15 kept worktrees in its settings
The full guide covers the rest, including Codex's detached worktrees and a Codex bug that saved 54,504 crash reports in a day.
I make Mopup, a Mac app that runs these checks for you and removes only finished worktrees, never with --force. It's free to scan.
Top comments (0)