Menu

The git worktrees your coding agents leave behind, and how to clean them up
📰

The git worktrees your coding agents leave behind, and how to clean them up

DEV Community: swift·Suman Maharjan·about 24 hours ago
#qN5aYnQw
#devtoswift#devto#dev#worktrees#codex
Reading 0:00
15s threshold

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

Enter fullscreen mode

Exit fullscreen mode

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..…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.