Tear down an agent worktree when the task is done
ai agents & parallel sessions
// what it does
Once an agent's branch is merged (or rejected), remove its worktree and delete the branch so git worktree list keeps matching reality. remove deletes the directory and the repository-side metadata in one step; branch -d then clears the merged branch.
// shell
$ git worktree remove --force ../myapp-agents/auth$ git branch -d agent/auth// gotcha
remove refuses when the worktree has untracked or modified files — and node_modules alone makes a JS worktree "unclean", so in practice you'll often need --force. Glance at git -C <path> status first to be sure nothing valuable is about to go.