Skip to content

Storage cleanup never removes a worktree that a subagent thread used #19144

Closed

Description

@jlcara

What happens

Delete merged worktrees, Delete unchanged worktrees and Delete worktrees with deleted threads are all on, yet a cleanup run reports 0 removed, 111 kept. Most entries say "Shared by N threads".

Why

Each subagent that a thread starts is stored as its own thread (createdBy: "agent") with the parent's worktreePath. storageCleanup.ts groups every thread by worktreePath (L426) and keeps any worktree with more than one thread (L457: if (shared > 1) return keep(...)). Subagent threads are never archived or deleted with their parent. So a worktree whose thread ever started a subagent is kept forever, even after the user deletes the parent thread.

In my project this blocked 45 of 81 worktrees. Subagent threads caused 44 of them.

Repro

  1. Turn on "Delete unchanged worktrees".
  2. In a worktree thread, have the agent start one subagent.
  3. Settle or delete the thread, then run Settings → Storage → Delete now.
  4. The worktree is kept: "Shared by 2 threads".

Expected

Subagent threads should not count as users of a worktree. Their state should follow the parent thread's state (open, archived or deleted).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions