worktree-merge
Cleans up a worktree after its branch has been merged: removes the worktree directory and deletes the local branch. Use when the user says '/worktree-merge' or asks to clean up a merged worktree.
Install
npx skills add https://github.com/domengabrovsek/agent-config/tree/main/skills/worktree-merge
claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install domengabrovsek-claude@llmmart
git clone https://github.com/domengabrovsek/agent-config.git
The skills CLI installs just this skill, for any of its supported agents. Claude Code installs the whole domengabrovsek/claude collection as a plugin from our marketplace. Git is the plain clone.
Skill manifest
Clean up the current worktree: $ARGUMENTS
Preconditions
- Current
$PWDmust be inside a worktree (not the main checkout). Verify withgit rev-parse --git-dir != --git-common-dir. - The worktree's branch must be safely removable: either merged into the default branch upstream, or its upstream is
gone(PR was merged and remote branch deleted), or the user explicitly passes--force.
If the branch is not safe to remove, stop and explain what's still pending (unpushed commits, open PR, etc.). Never auto-delete unmerged work.
Steps
Capture worktree path and branch name:
WORKTREE=$(git rev-parse --show-toplevel) BRANCH=$(git rev-parse --abbrev-ref HEAD)Move out of the worktree to the main checkout (
cd "$(git rev-parse --git-common-dir)/..").Remove the worktree:
git worktree remove "$WORKTREE". If it has uncommitted changes and--forcewas passed, usegit worktree remove --force "$WORKTREE".Delete the local branch:
git branch -d "$BRANCH"(or-Dwith--force).Report what was cleaned up.
After cleanup
If the user has more work, suggest /worktree <new-slug> for the next task rather than mutating the main checkout.
Merging parallel lanes
When several lane-mode teammates finish, merge their branches into the integration branch one at a time:
- Review each teammate's diff for correctness.
- Merge one branch. Resolve any conflict with
/resolve-conflictsbefore merging the next. - After the last merge, run the full test suite, typecheck, and lint.
- Prune the worktrees:
~/.agents/scripts/worktree-prune.sh --apply. It removes only worktrees whose branch is upstream-gone or merged into the default, which is the post-merge state. Anything still active survives.
Files (claude)
-
SKILL.md 2 KB
--- name: worktree-merge description: "Cleans up a worktree after its branch has been merged: removes the worktree directory and deletes the local branch. Use when the user says '/worktree-merge' or asks to clean up a merged worktree." --- Clean up the current worktree: $ARGUMENTS ## Preconditions - Current `$PWD` must be inside a worktree (not the main checkout). Verify with `git rev-parse --git-dir != --git-common-dir`. - The worktree's branch must be safely removable: either merged into the default branch upstream, or its upstream is `gone` (PR was merged and remote branch deleted), or the user explicitly passes `--force`. If the branch is not safe to remove, stop and explain what's still pending (unpushed commits, open PR, etc.). Never auto-delete unmerged work. ## Steps 1. Capture worktree path and branch name: ```bash WORKTREE=$(git rev-parse --show-toplevel) BRANCH=$(git rev-parse --abbrev-ref HEAD) ``` 2. Move out of the worktree to the main checkout (`cd "$(git rev-parse --git-common-dir)/.."`). 3. Remove the worktree: `git worktree remove "$WORKTREE"`. If it has uncommitted changes and `--force` was passed, use `git worktree remove --force "$WORKTREE"`. 4. Delete the local branch: `git branch -d "$BRANCH"` (or `-D` with `--force`). 5. Report what was cleaned up. ## After cleanup If the user has more work, suggest `/worktree <new-slug>` for the next task rather than mutating the main checkout. ## Merging parallel lanes When several lane-mode teammates finish, merge their branches into the integration branch one at a time: 1. Review each teammate's diff for correctness. 2. Merge one branch. Resolve any conflict with `/resolve-conflicts` before merging the next. 3. After the last merge, run the full test suite, typecheck, and lint. 4. Prune the worktrees: `~/.agents/scripts/worktree-prune.sh --apply`. It removes only worktrees whose branch is upstream-gone or merged into the default, which is the post-merge state. Anything still active survives.
Comments (0)
Sign in to join the conversation.
Reviews (0)
No reviews yet.
No comments yet.