← sources

Coding agents create branches and worktrees. Who cleans them up?

source: reddit (reddit:AI_Agents)published 2026-10-11 02:37ingested 2026-10-12 02:36

retained text

As agentic development becomes more common, familiar tools like Git face a new workload: several agents creating branches, making checkpoint commits and opening worktrees throughout the day.

The PR gets merged. But its local branch, review checkout and recovery records can stick around.

We ran into this while building Assay. Leftover worktrees consume disk, and tools that scan references or walk retained history have more to process. The slowdown depends on what those tools do; an old branch doesn’t make every Git command slow.

What helped was separating three jobs:

* **Merge the change:** get the accepted work onto main.
* **Retire the workspace:** check for active owners, unpublished work and evidence before removing worktrees and branches.
* **Maintain the repository:** let Git pack objects and maintain indexes, while preserving a sensible recovery window.

Squash merging keeps accepted history concise. It doesn’t remove the original task commits while branches, worktree HEADs or reflogs still retain them.

A useful starting inventory:

    git worktree list --porcelain
    git branch -vv
    git count-objects -vH

In Assay, we’re building ownership checks, workspace retirement and maintenance into the desk tools that manage agent work. These are useful practices even if your entire setup is shell scripts.

For people running multiple coding agents: what tells your tooling that a workspace is safe to retire? A merged PR, completed review, a retention period, or explicit owner sign-off?

document fetched 2026-10-12 00:18 · canonical https://reddit.com/r/AI_Agents/comments/1x2wt98/coding_agents_create_branches_and_worktrees_who