Skip to content

feat: allow session-only delete on the main worktree - #23

Merged
xico42 merged 1 commit into
mainfrom
feat/delete-main-session
Jul 18, 2026
Merged

feat: allow session-only delete on the main worktree#23
xico42 merged 1 commit into
mainfrom
feat/delete-main-session

Conversation

@xico42

@xico42 xico42 commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

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 through to git, which failed removing the clone directory and surfaced a raw porcelain error.

This lets the TUI's d key kill the main worktree's sessions (leaving the worktree in place) and gives ch delete worktree main a clean refusal.

What changed

  • Domain guard. 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 herd.ErrMainWorktree sentinel, checked the moment the clone dir is known — before any session is stopped or any git command runs.
  • One error vocabulary. Both front ends translate the sentinel: the CLI names the worktree and points at ch delete session; the TUI shows a concise line.
  • TUI. d no 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 new deleteAllSessions action stops every session via StopOpts{All: true} and leaves the worktree in place.

Verification

make check green — 628 unit tests, integration tests, lint (0 issues), build; coverage 85.4% (≥ 80%). Includes a new integration test asserting Teardown refuses the main worktree for both --force values and leaves the clone dir on disk.

🤖 Generated with Claude Code

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>
@xico42
xico42 merged commit 9ee9111 into main Jul 18, 2026
7 checks passed
@xico42
xico42 deleted the feat/delete-main-session branch July 18, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant