Repository navigation
Description
Current state
An investigation whose tmux window is closed before Claude exits leaves its worktree on disk under ~/.hub/repos/<project>/ permanently, and nothing in hub ever removes it.
For WorktreeSpec::EphemeralFresh and WorktreeSpec::Ephemeral, resolve_worktree in ui/tui/src/investigations/launch.rs creates a detached-HEAD worktree named investigation-<ts> and returns a git worktree remove --force command as its only cleanup.
compose in ui/tui/src/investigations/command.rs appends that command to the shell string after claude ... with ;, so it runs only when the Claude process exits and the shell carries on.
Killing the window terminates the shell before that point: running sleep 600; touch <file> in a tmux window and then tmux kill-window (or tmux kill-session) leaves no file, while letting the same command finish creates it.
The periodic sweep does not catch these worktrees either: clean_merged_worktrees in workflows/src/fetch.rs skips every worktree with no branch (let Some(branch) = branch else { continue };), and create_investigation_worktree creates them with git worktree add --detach, so they never have one.
Ideal state
- Every investigation worktree is removed once its session ends, however the session ends.
- A session whose tmux window is killed before Claude exits has its
investigation-<ts>worktree removed. - A session where Claude exits normally still has its worktree removed, as it does today.
- A worktree whose launch fails before its session starts is removed.
investigation-<ts>worktrees left behind by sessions that ended before this fix are removed.
Out of scope
pr-<N>worktrees, which persist on purpose until their PR branch is deleted.
Decisions
Constraints
- 019: Drop the task model; filesystem-based session tracking: treats ephemeral worktrees as transient and cleaned up when the session ends, and keeps session records outside worktrees so removing a worktree loses nothing that must persist.
- 015: Accept tmux and Claude Code as baked-in dispatch dependencies: detecting that a session ended may rely on tmux directly, with no abstraction over it.
Open
- 022: The TUI reads the cache and never fetches (accepted, not yet implemented) removes
workflows::fetch::run, and with itclean_merged_worktrees, from the TUI. Does any removal step for orphaned investigation worktrees belong to the TUI, to the daemon, or to something else? (new process or runtime)
Starting points
ui/tui/src/investigations/launch.rs:launchandresolve_worktreecreate the worktree and its cleanup commandui/tui/src/investigations/command.rs:composeappends the cleanup afterclaudeworkflows/src/fetch.rs:create_investigation_worktreeandclean_merged_worktrees
Activity
ooloth commentedon Nov 19, 2026
Since #435, the cleanup follows
"$HUB_LAUNCHER" …and runs when the launcher exits. That's the same moment for a launcher thatexecsclaude, ascc.bashdoes. A launcher that can't run is now refused inlaunch()before any worktree is created. A session held atcc.bash's browser login keeps its worktree all that time.