Skip to content

feat(source-control): remove worktrees across repositories when cleanup runs outside a repository #11120

Description

@kyle-sexton

Refs: #7453

Agent Brief

Type: Feature
Summary: /source-control:worktree cleanup run outside a repository acts across repositories: it finds the same repositories as audit, shows the safe candidates grouped by repository behind one confirm, and removes each confirmed worktree from inside its owning repository with the single-repository guards unchanged.

Current behavior:

  • plugins/source-control/skills/worktree/context/cleanup.md (around :18): "Outside a repository, cleanup reports and removes nothing." It lists candidates per owning repository and tells the person to run cleanup from each one.
  • scripts/worktree-discover.sh already maps every worktree to its owning repository, and audit outside a repository already uses it (context/audit.md around :9).
  • fix(source-control): run the worktree reap without moving the caller's working directory #8021 made the removal sequence keep the caller's working directory out of the candidate.

Desired behavior (from #7453's proposed fix):

  1. Cleanup's out-of-repository path uses the worktree-discover.sh rows, runs the existing per-repository candidate logic (Step 2) for each owning repository, and shows one grouped confirm (Step 3's batching across repositories).
  2. For each confirmed row, every Step 4 guard and the removal run against the owning repository with git -C <owning-repo> (or a subshell cd), so the per-repository safety logic is unchanged and no directory change persists in the caller's shell.
  3. The per-row stranded, superseded and unknown stops behave exactly as in a single-repository run. --dry-run outside a repository lists what would be removed and removes nothing.

Done when

  • cleanup.md no longer says that cleanup outside a repository removes nothing; it describes the cross-repository path above.
  • An eval case: two repositories under one worktree root, each with one removable and one stranded worktree, cleanup run outside any repository. The expected output shows one grouped confirm, removes only the two removable worktrees, each through its owning repository, stops on both stranded rows, and leaves the caller's directory unchanged.
  • bash plugins/skill-quality/scripts/check-skill.sh plugins/source-control/skills/worktree exits 0.
  • scripts/check-changelog-fragments.sh passes with a source-control fragment.

Out of scope:

  • Changing the guards themselves, or what counts as a safe candidate.
  • audit and status behavior.

Activity

  1. github-actions commented on Oct 30, 2026

    @github-actions
    Contributor

    Proposed work class: work-class: scoped
    Basis: automated intake triage; the lanes App applied this class.

    Size: Medium
    Complexity: Medium
    Uncertainty: Known
    Flags: none
    Blocked by: none

    Understood: you want /source-control:worktree cleanup, when run outside a repository, to reuse the worktree-discover.sh rows. It would show one grouped confirm and remove each confirmed worktree through its owning repository. The single-repository guards stay unchanged, and --dry-run removes nothing. The brief gives the current behavior, the desired behavior, the done-when items and the out-of-scope items, so I found nothing missing. I found no likely duplicates among the open issues. This is a follow-on to #7453.

    Automated triage, applied by the lanes App.

  2. added
    status: ready
    admission-deferred
    agent-ready
    and removed
    admission-deferred
    on Oct 30, 2026
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

    agent-readystatus: ready

    Fields

    No fields configured for Feature.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions