Let your coding agent auto-clean git worktrees and branches after deploy

NielsRogge · x · 2026-10-13

Niels Rogge shares a practical tip: add a rule to AGENTS.md so that once a task's merged commit is deployed to production and passes smoke checks, the agent removes the task's worktree and deletes its local and remote branches. Before deleting, it confirms the worktree is clean and main contains the branch's changes (comparing branch diff vs merge commit diff for squash merges). The rule only touches the task's own worktree. He implemented it with Claude Code and wishes he'd done it earlier.

Related event: Engineers share trick: let coding agents auto-clean git worktrees(2 posts)→

Original post →

More from coding & agent

coding & agent channel →