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.
More from coding & agent
- A Comprehensive Guide to Building Agentic AI Systems, from Architectures to Guardrails — goyalshaliniuk · 2026-10-28
- Delta, JPMorgan, Amazon are blocking AI agents — permission is AI's next big fight — Arindam_1729 · 2026-10-28
- Magpie adds animation to show data masking doesn't degrade agent behavior — dotey · 2026-10-28
- Google open-sources Elephant-Goldfish: design-review skills for AI coding agents — sven_ai · 2026-10-28
- Claude Music Video plugin generates agentic MVs with custom shaders, 95% on first pass — AIandDesign · 2026-10-28
- Opus 5 Agents Pay a Steep Rediscovery Cost: 475K Tokens Is the Record, Not the Bug — Sauers_ · 2026-10-28