feat: allow session-only delete on the main worktree - #23
Merged
Conversation
The dashboard hard-blocked `d` on the main worktree with a flat "cannot
delete the main worktree", so the only way to kill that worktree's agent
or shell sessions was to leave the TUI and run `ch delete session` by
hand. On the CLI, `ch delete worktree <project> main` fell straight
through to git, which failed trying to remove the clone directory and
surfaced a raw porcelain error instead of an explanation.
The main worktree is the clone directory itself, not a checkout under
__worktrees/, so tearing it down never makes sense. Teardown now refuses
it with a new ErrMainWorktree sentinel, checked the moment the clone dir
is known — before any session is stopped or any git command runs — so a
refusal can never leave sessions half-killed or the tree half-removed.
Both front ends translate the sentinel through the one error vocabulary:
the CLI names the worktree and points the user at `ch delete session`,
and the TUI shows a concise line.
In the dashboard, `d` no longer refuses the main worktree outright — it
only declines when there are no sessions to act on. With a session
present it opens the confirm menu in a main-worktree mode that offers
session kills only and never lists worktree removal, so the destructive
option is unreachable by construction rather than guarded after the
fact. A new deleteAllSessions action stops every session for the ref via
StopOpts{All: true} and leaves the worktree in place.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The dashboard hard-blocked
don the main worktree with a flat "cannot delete the main worktree", so the only way to kill that worktree's agent or shell sessions was to leave the TUI and runch delete sessionby hand. On the CLI,ch delete worktree <project> mainfell through to git, which failed removing the clone directory and surfaced a raw porcelain error.This lets the TUI's
dkey kill the main worktree's sessions (leaving the worktree in place) and givesch delete worktree maina clean refusal.What changed
__worktrees/, so tearing it down never makes sense.Teardownnow refuses it with a newherd.ErrMainWorktreesentinel, checked the moment the clone dir is known — before any session is stopped or any git command runs.ch delete session; the TUI shows a concise line.dno longer refuses the main worktree outright — it only declines when there are no sessions. With a session present it opens the confirm menu in a main-worktree mode that offers session kills only and never lists worktree removal, so the destructive option is unreachable by construction. A newdeleteAllSessionsaction stops every session viaStopOpts{All: true}and leaves the worktree in place.Verification
make checkgreen — 628 unit tests, integration tests, lint (0 issues), build; coverage 85.4% (≥ 80%). Includes a new integration test assertingTeardownrefuses the main worktree for both--forcevalues and leaves the clone dir on disk.🤖 Generated with Claude Code