Skip to content

Investigation worktrees are removed however their session ends #346

Open

Description

@ooloth

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

Open

  • 022: The TUI reads the cache and never fetches (accepted, not yet implemented) removes workflows::fetch::run, and with it clean_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: launch and resolve_worktree create the worktree and its cleanup command
  • ui/tui/src/investigations/command.rs: compose appends the cleanup after claude
  • workflows/src/fetch.rs: create_investigation_worktree and clean_merged_worktrees

Activity

  1. ooloth commented on Nov 19, 2026

    @ooloth
    OwnerAuthor

    Since #435, the cleanup follows "$HUB_LAUNCHER" … and runs when the launcher exits. That's the same moment for a launcher that execs claude, as cc.bash does. A launcher that can't run is now refused in launch() before any worktree is created. A session held at cc.bash's browser login keeps its worktree all that time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions