Repository navigation
Description
Problem
afx cleanup -p <id> only kills the Tower terminal and unregisters the builder from the agent farm. The worktree and branch are deliberately preserved, with the cleanup output printing the manual follow-up commands:
[info] Worktree preserved at: /Users/.../.builders/pir-XXXX
[info] To remove: git worktree remove "/Users/.../.builders/pir-XXXX"
[info] Branch preserved: builder/pir-XXXX
[info] To delete: git branch -d "builder/pir-XXXX"
The full teardown sequence is always three steps:
afx cleanup -p <id>
git worktree remove --force .builders/<branch>
git branch -d builder/<branch>The help text — "Clean up a builder worktree and branch" — describes the aspiration of the command, not its actual behavior. There's a small footgun here: a reader who's only seen the help text will assume the command does what it says, then discover halfway through cleanup that they need two more commands.
Why preservation is the right default
This isn't an argument to change the default. Today's behavior protects two real cases that hit us twice in one Shannon session (2026-05-25):
- PIR Fix #1584: never re-write a mailbox row whose write completed #1585 / PR afx send: a builder running from the main workspace root resolves as a non-builder, so plain 'architect' routes to main instead of its owner (CLAUDE.md rule sends it there) #1783: worktree had 1 uncommitted file — the iter-1 rebuttals
.mddoc the builder wrote and referenced in its consult-result notification ("Full rebuttal: codev/projects/.../1585-review-iter1-rebuttals.md"). The substantive content shipped via the review file that was on the PR, but the rebuttals file itself was untracked scratch worth inspecting before discarding. - PIR porch: force-advance at the review ceiling should request a gate instead of continuing as approved #1793 / PR Diff navigation: skip collapsed sidebar folders and auto-reveal deleted/binary files #1794: same pattern, two iterations of consult so two untracked rebuttal files in the worktree.
Both times the architect agent paused to inspect the scratch before removing. That's exactly the discipline preservation enforces — if cleanup removed everything in one step, mid-iteration scratch would be silently lost.
Proposed change
Add an opt-in flag that does the full teardown in one command, after explicit acknowledgment:
afx cleanup -p <id> --full
# or: --remove-worktree --delete-branch (composable)Suggested behavior:
--full(or both--remove-worktree+--delete-branch): perform the existing cleanup, then rungit worktree removeandgit branch -din sequence.- If the worktree has uncommitted/untracked changes when
--fullis invoked:- Refuse by default with the existing "To remove" hint AND a one-line listing of which file(s) are uncommitted, so the user can decide whether to inspect.
--full --force(or--full -f) overrides — runsgit worktree remove --force.
- If the branch hasn't been merged into the current HEAD when
--fullis invoked:- Refuse by default, point the user at the unmerged commit list.
- Re-use the existing
-f, --forceflag for branch deletion (currently scoped to "branch not merged").
- Keep the existing default (no flag) preserving both, exactly as today.
The composable form (--remove-worktree / --delete-branch) is nice because some workflows want to keep the branch around for a while after the worktree is gone (e.g., GitHub PR archived for reference, local worktree clutter removed).
Out of scope
- Changing the existing default (still preserve unless asked).
- Auto-discarding uncommitted scratch (the value of preservation IS the human-in-the-loop decision on what's scratch vs work).
- Touching the
-f, --forcesemantics for the "branch not merged" case — leave that as-is to avoid regressing today's safety guard.
Help text fix (separate, can ride along)
Independently of whether --full lands, the current help text overpromises:
Clean up a builder worktree and branch
A more accurate one-liner would be:
Stop the builder; print teardown commands for worktree + branch (use --full to also run them)
…or whatever phrasing fits once the flag lands.
References
- Today's friction: PIR Fix #1584: never re-write a mailbox row whose write completed #1585 / PR afx send: a builder running from the main workspace root resolves as a non-builder, so plain 'architect' routes to main instead of its owner (CLAUDE.md rule sends it there) #1783, PIR porch: force-advance at the review ceiling should request a gate instead of continuing as approved #1793 / PR Diff navigation: skip collapsed sidebar folders and auto-reveal deleted/binary files #1794 in cluesmith/shannon — both had untracked rebuttal
.mdscratch in their worktrees post-merge, both required separategit worktree remove --forcecalls afterafx cleanup.
Unassigned — for the team to discuss the right flag shape and default behavior.
Activity
waleedkadous commentedon May 25, 2026
amrmelsayed commentedon May 27, 2026
Agree with @waleedkadous 's read — drop
--full--fulladds nothing the composable form doesn't already provide, and it has one structural downside worth flagging: it doesn't compose with future additions. If a third teardown step is ever added (cleanup orphanterminal_sessionsrows in~/.agent-farm/global.db, prune builder thread logs incodev/state/, etc.),--fullbecomes semantically ambiguous — does it include the new thing or not? Either choice is a footgun. Pure composable flags don't have this problem; they just gain a third sibling.Two slightly different shapes worth picking between:
Form 1 — pure composable, two flags:
Form 2 — one flag (questions whether "delete branch, keep worktree" is real):
The issue body argues against Form 2 by citing "some workflows want to keep the branch around for a while after the worktree is gone" — but that's exactly what Form 2 does by default. The reverse case (delete branch but keep worktree) is the weird one that needs justifying. If nobody actually wants that, Form 2 has the smallest possible surface.
Independent: ship the help-text fix now
The help-text fix (
"Clean up a builder worktree and branch"→ something that matches actual behaviour) is independent of the flag design and could land as a trivial PR today. That's the most direct footgun for new users — they read the help, type the command, then discover halfway through cleanup that they need two more commands. Fixing the docs doesn't wait on the design discussion.Issue-body cleanup observation
Per house convention, codev issues should be framed in codev's own terms — the current body references specific external-repo PR numbers (in the "References" section and the inline examples) which aren't meaningful to a future reader of this codev issue. A rewrite that keeps the motivation ("two consecutive cases where worktrees held uncommitted scratch worth inspecting before deletion") without naming the external repo or its PR numbers would generalize cleanly.