worktree-cleanup

Retire merged git worktrees and prune unreachable objects from the shared object store.

2|Updated Mar 3, 2026
One-click install
npx skills add https://github.com/DanielH2018/server --skill worktree-cleanup-danielh2018
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: worktree-cleanup
Source: https://github.com/DanielH2018/server/tree/main/.claude/skills/worktree-cleanup
Command: npx skills add https://github.com/DanielH2018/server --skill worktree-cleanup-danielh2018

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? After a squash or rebase merge, git tooling cannot tell whether a worktree's branch still holds unlanded work, so removal tools refuse and merged worktrees pile up alongside unreachable objects in the shared object store. ## Core Features & Use Cases - Content-based merge verification: Compare git merge-tree --write-tree output against master's tree SHA to prove a branch's work landed, instead of trusting commit counts. - Safe pruning workflow: Run prune_worktrees.py in report, --prune, or --gc modes to remove only merged, clean, unlocked worktrees and repair the object store. - Lock and stash safety rules: Respect session-held locks, ignore stale locks, and avoid the shared stash stack by using WIP commits or SHA-pinned stash entries. - Use Case: A session's PR just squash-merged and ExitWorktree refuses to remove the worktree; verify the merge by tree SHA, then let the pruner collect the worktree and delete the branch with git branch -d before the tracking ref is pruned. ## Quick Start Ask the assistant to verify whether the current worktree's branch has landed on master and, if so, prune the merged worktree and delete its branch.

Frequently Asked Questions about worktree-cleanup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I remove a git worktree after a squash merge?▼

Verify the merge by comparing `git merge-tree --write-tree origin/master <branch>` with `git rev-parse origin/master^{tree}`; equal SHAs mean the work landed. Then run prune_worktrees.py --prune to remove the merged, clean, unlocked worktree.

Why does ExitWorktree refuse to remove my merged worktree?▼

Squash and rebase merges land content under new SHAs, so the tool sees commits on the branch and cannot distinguish landed work from unlanded work. Verify by tree content instead of passing discard_changes, which risks deleting real unlanded work.

When does git branch -d work on a squash-merged branch?▼

git branch -d succeeds while the local tracking ref still carries the branch tip, because it checks merge status against HEAD or the upstream. The window closes at the next git fetch --prune, after which only -D works.

Can I use git stash while cleaning up worktrees?▼

Avoid bare git stash and git stash pop because the stash stack and index are shared across all worktrees and concurrent sessions. Prefer a temporary WIP commit, or stash with a unique message and restore via git stash apply <sha>.

Why does git fetch warn about unreachable objects after pruning worktrees?▼

Removing a worktree makes its branch's objects unreachable, but git gc --auto only runs above loose-object and pack thresholds, so churn accumulates. Running prune_worktrees.py --gc drops unreachable objects older than a day and clears stale gc.log files.