41 leftover git worktrees eat 45GB: fix it with a cleanup rule in AGENTS.md

dotey · x · 2026-10-28

It started with @marcoscamara01 complaining that every agent chat in Claude Code, Codex, or t3 code gets its own git worktree with its own nodemodules and .next — 1-2GB each — and none got cleaned up, leaving 41 worktrees and 45GB on disk.

dotey's suggested fix isn't manual cleanup but encoding the rule in AGENTS.md so the agent cleans up after itself. He cites the "no leftover worktrees" clause from JimLiu's baocut repo: on task completion the agent must delete the worktree (including subagent .claude/worktrees/agent-), its branch, and its dedicated cargo target dir; before deletion, either merge to main, or commit uncommitted changes to the branch, tag it as archive/<worktree-name>, then run git worktree remove + git branch -D; the orchestrating session is responsible for subagent-derived worktrees; anything that must be kept (pending user decision, unresolved conflicts) must be called out with path and reason in the final reply.

Original post →

More from coding & agent

coding & agent channel →