Skip to content

fix(repos): worktree prune removes a worktree with agent scratch #7357

Done

Description

@dan-petty

Problem Description

devops repos worktrees prune removes no worktree of a merged pull request when the worktree holds scratch files of its builder. AGENTS.md rule 12 tells an agent to put scratch files under .data/agent/scratch/, and in a worktree that path is inside the worktree. Prune counts these files as ignored data files and refuses the worktree.

Preview on 2026-11-26 in the devcontainer: Preview: 0 removable (0.0 B), 155 refused. The reasons: 103 outside the managed folder, 20 with no merged pull request for the tip, 17 that hold ignored data files, 8 dirty, 1 locked. .data/agent/worktrees holds 79 GB.

Five of the 17 were worktrees of pull requests that merged that day (#7297, #7306, #7320, #7332, #7336). Each held only .data/agent/scratch/ files (probe scripts, logs, pull request bodies), .data/rag/ index caches and .hypothesis/.

Expected vs Actual Behavior

  • Expected: prune removes the worktree of a merged pull request whose only ignored files are agent scratch files and caches that can be made again.
  • Actual: it refuses each such worktree, so a person or an agent removes them by hand with git worktree remove --force.

Proposed Fix

Count .data/agent/scratch/, .data/rag/ caches and .hypothesis/ of a worktree as data that can be made again, as .venv and .data/cache are, or print the ignored files and take them with an option.

Acceptance Criteria

  • A test: a clean worktree of a merged pull request that holds only .data/agent/scratch/ files and .hypothesis/ is removable.
  • A test: a worktree that holds another ignored data file is refused as before, and the refusal names the file.

Environment Diagnostics

devops-cli 0.223.3.

Alternatives check of 2026-11-26: none.
Tool: none found.
Reason: Searches surfaced only generic worktree managers and git itself; none detects merged pull requests for a worktree tip or separates regenerable scratch/cache paths from other ignored data, so the change belongs in the project's own pathspec list.

Lacks:

  • Merged-pull-request check for the worktree tip
  • Regenerable-path policy for scratch, RAG caches and .hypothesis
  • Refusal that names the offending ignored file

Proposed design

Problem statement

devops repos worktrees prune refuses the worktree of a merged pull request when the worktree holds only agent scratch files and regenerable caches. The preview reports 0 removable and 155 refused. Five refused worktrees of pull requests merged that day held only .data/agent/scratch/, .data/rag/ and .hypothesis/ files. A person or an agent must remove each worktree by hand with git worktree remove --force.

Acceptance criteria

Requirement: Regenerable ignored files are removable

devops repos worktrees prune SHALL remove the worktree of a merged pull request when its only ignored files are .data/agent/scratch/, .data/rag/ and .hypothesis/ files.

Scenario: Merged worktree with agent scratch and caches

  • WHEN A test creates a worktree of a merged pull request with only .data/agent/scratch/, .data/rag/ and .hypothesis/ files ignored.
  • THEN The prune command removes the worktree and reports it as removed.

Requirement: Other ignored data is refused and named

devops repos worktrees prune MUST refuse a worktree that holds an ignored file outside the regenerable paths and MUST name that file in the refusal.

Scenario: Merged worktree with other ignored data

  • WHEN A test creates a worktree of a merged pull request with one ignored file outside .data/agent/scratch/, .data/rag/ and .hypothesis/.
  • THEN The prune command refuses the worktree and its reason names the ignored file.

Requirement: Existing regenerable paths stay removable

devops repos worktrees prune SHALL keep .venv and .data/cache as regenerable paths.

Scenario: Existing cache paths stay removable

  • WHEN A test creates a worktree of a merged pull request with only .venv and .data/cache files ignored.
  • THEN The prune command removes the worktree.

Existing Tool Considered

The alternatives check in the issue body records verdict none and no tool. The project builds the change itself by extending its existing pathspec list. Estimated cost is about 10k tokens and 2 hours to build, keep and fix the path policy and its tests.

Key questions

  • How should prune treat agent scratch and cache paths?: Add .data/agent/scratch/, .data/rag/ and .hypothesis/ to the existing regenerable pathspec list. Keep other ignored data refused and name the offending file. (best practice) [sources: AGENTS.md]
    • Chosen: Extend the regenerable pathspec list. AGENTS.md rule 12 puts agent scratch under .data/agent/scratch/, and the issue shows these paths are regenerable.
    • Rejected: Print ignored files and require an option. This keeps the manual removal step that the issue reports.
    • Rejected: Force remove every worktree with ignored files. This would delete data that cannot be made again.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    status/new
    on Nov 26, 2026
  2. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor
  3. added
    value/medium
    effort/low
    scope/repos
    priority/p2-medium
    on Nov 26, 2026
  4. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (9)

    Tools considered:

    Searches run:

    • tool that removes git worktrees of merged pull requests automatically, results: 5
    • git worktree prune ignored untracked files refuse removal, results: 5
    • gwq git worktree manager, results: 5
    • github cli extension clean up stale worktrees merged branches, results: 5
    • "git worktree remove --force" python library, results: 5
    • worktree cleanup tool for agents scratch directories, results: 5
    • worktree, results: 5
    • git worktree prune manual documentation, results: 5
    • git-town worktree support github, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 28, 2026
  6. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 03:13 UTC

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

    effort/lowpriority/p2-mediumscope/repossource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions