Skip to content

feat(repos): remove worktrees whose commits are merged without a manual prune #2338

Description

@dan-petty

Problem or Motivation

Worktrees of merged work stay on disk. devops repos worktrees prune exists and is safe, but nobody runs it: it is a dry run by default and no routine calls it.

Evidence from devops repos worktrees status --json on this host:

  • 125 worktrees besides the main one. 57 of them are contained in main (their commits are merged), and 3 are dirty.
  • The directories hold a full virtual environment each: the 107 worktrees under ~/.gemini/antigravity/worktrees/ use 123 GB, the 12 under .data/agent/worktrees/ use 13 GB, and the 3 under .claude/worktrees/ use 3.5 GB.
  • devops repos worktrees status takes 14 s because it inspects every entry, and git worktree list grows with every worktree. Every agent pays this cost.

Proposed Solution & Architectural Design

Remove a worktree that is clean, not locked, and contained in origin/main, without a manual run of prune.

  • The design of the pull request chooses where the removal runs. The candidates are the end of devops pr (when the pull request of the branch is merged), devops workspace clean, and the routine tasks in docs/ROUTINE_TASKS.md. The rule is the same in each: the worktree is clean, unlocked and contained, and the worktree of the current directory is never removed.
  • A worktree that is dirty, locked or not contained stays, and the command reports it.
  • --dry-run makes no change and lists the worktrees it would remove with their size.

Target Subsystem

SDLC, Git & PR Governance

Existing Tool Considered

git worktree prune removes only entries whose directory is gone. git worktree remove removes one worktree. Neither selects merged work. The existing devops repos worktrees prune already computes contained, so the change reuses it and adds no tool.

Activity

  1. added
    source/agent
    type/feature
    on Oct 27, 2026
  2. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Type: type/feature. The candidate proposes a new feature to automate worktree cleanup based on merge status.
    • Priority: P2-Medium. This change improves repository maintenance and performance but is not critical for immediate operations.
    • Value: High. The change provides significant disk space savings and performance improvements for agents.
    • Effort: Medium. Implementation requires integration with existing worktree management logic and proper handling of edge cases.
    • Related: feat(repos): add devops repos worktrees add that refuses an issue another agent already holds #2337, which asks for a different change. Both items are about worktrees, but the candidate focuses on automatic cleanup while item #2337 addresses worktree creation and conflict prevention.
  3. added 2 commits that reference this issue on Oct 27, 2026
    6d3a18a
    621282b
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

    source/agenttype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions