Cleanup never takes your work: a rule we wrote after losing a file

By The Ember team4 min read

In shortEmber's own cleanup removes a worktree only when everything in it is on its branch, and deletes a branch only when git shows its work landed. We wrote that rule after an automatic cleanup force-removed a closed worktree that still held a saved edit and an untracked file.

What happened

Agents that work in background worktrees leave worktrees behind, so an editor that runs many agents has to clean up after them. Ours did, automatically, once a branch merged or a limit was reached.

In a real run, that automatic cleanup force-removed a closed worktree that was holding a saved edit to a tracked file and an untracked file. Nothing warned about it, because a forced removal doesn't ask. We changed the rule that day.

The rule now

Cleanup that Ember starts by itself never takes work the branch doesn't hold. A worktree with uncommitted or untracked files, ignored files that may be yours, a detached HEAD, or files Ember couldn't check is kept, and Ember says why.

A branch is deleted only when git shows its work landed: through git cherry, or for a squash merge, by confirming with git merge-tree that merging the branch would change nothing. Removing a worktree that still holds work is something only you do, after Ember names exactly what goes.

Why the words changed too

We used to call all of this Retire. One word covered two different actions with different consequences, so nobody could tell what a button would do. Every surface now names the action it runs: Remove worktree, where the branch stays, or Delete branch, for a merged branch checked out nowhere.

The same check runs wherever the action starts: the board, a finished chat, a plan build's cleanup or your phone. On the phone, Ember reads the branch again and asks on the phone before anything is removed.

What we took from it

Convenience features that delete things need the strictest defaults in the product. If Ember is not certain that a folder holds nothing of yours, it keeps the folder and tells you. A leftover worktree costs some disk space. A lost file costs trust.

Download Ember