Skip to content

feat(pr-cycle): 0.5.0 — post-merge worktree sweep (close the agent-worktree leak)#424

Merged
dancinlife merged 1 commit into
mainfrom
feat/pr-cycle-worktree-sweep
Jun 6, 2026
Merged

feat(pr-cycle): 0.5.0 — post-merge worktree sweep (close the agent-worktree leak)#424
dancinlife merged 1 commit into
mainfrom
feat/pr-cycle-worktree-sweep

Conversation

@dancinlife

Copy link
Copy Markdown
Contributor

/cycle-bg runs piled up .claude/worktrees/agent-* dirs: gh pr merge --delete-branch drops the remote branch but leaves the worktree directory, and
pr-cycle had no clean step. The pr-cycle-hook's cleanup only ran on Bash-tool
gh pr merge (not the slash-command !-exec) and only removed the cwd worktree,
never accumulated siblings.

  • after a successful merge, cd to the MAIN worktree, then remove every
    .claude/worktrees/agent-* worktree whose upstream is [gone] (+ branch -D
    • worktree prune)
  • squash-safe: a squashed branch isn't an ancestor of main, so key off the
    deleted upstream (git push -u then --delete-branch leaves it gone), not
    --is-ancestor
  • cd-to-main first => even the just-merged CURRENT worktree is swept
  • SAFETY: never touch a worktree with a live or absent (track=none) upstream
    (may hold un-pushed work) nor a locked worktree (another checkout); only
    /.claude/worktrees/ paths are eligible
  • validated against 9 real leaked worktrees: 2 [gone] + 5 stale-locked swept,
    2 track=none (unmerged LAB-10 commits) correctly preserved
  • g22 lockstep: plugin 0.5.0 <-> marketplace 0.5.0 + CHANGELOG, same commit

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

…rktree leak)

`/cycle-bg` runs piled up `.claude/worktrees/agent-*` dirs: `gh pr merge
--delete-branch` drops the remote branch but leaves the worktree directory, and
pr-cycle had no clean step. The pr-cycle-hook's cleanup only ran on Bash-tool
`gh pr merge` (not the slash-command !-exec) and only removed the cwd worktree,
never accumulated siblings.

- after a successful merge, cd to the MAIN worktree, then remove every
  `.claude/worktrees/agent-*` worktree whose upstream is `[gone]` (+ branch -D
  + worktree prune)
- squash-safe: a squashed branch isn't an ancestor of main, so key off the
  deleted upstream (`git push -u` then `--delete-branch` leaves it gone), not
  --is-ancestor
- cd-to-main first => even the just-merged CURRENT worktree is swept
- SAFETY: never touch a worktree with a live or absent (track=none) upstream
  (may hold un-pushed work) nor a locked worktree (another checkout); only
  /.claude/worktrees/ paths are eligible
- validated against 9 real leaked worktrees: 2 [gone] + 5 stale-locked swept,
  2 track=none (unmerged LAB-10 commits) correctly preserved
- g22 lockstep: plugin 0.5.0 <-> marketplace 0.5.0 + CHANGELOG, same commit

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dancinlife dancinlife merged commit dc42d17 into main Jun 6, 2026
@dancinlife dancinlife deleted the feat/pr-cycle-worktree-sweep branch June 6, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant