/cleanup-worktree

Merge a verified branch into main, remove the worktree and branch, update Linear

04 Deploy Input: run from worktree; optional Linear issue ID Output: branch in main, worktree removed, Linear Done
Step
Human
Claude Code Agent
External Systems
Check
Validates: not on main, no uncommitted changes
Records branch name and worktree path
git status, git branch --show-current
Branch and status checked
Git
Verify
Shows commits to merge and checks if main is ahead
If main ahead: stops and requires /verify-worktree first
git log main..HEAD, git log HEAD..main
Commit comparison
Git
Reviews commit list, confirms merge
Required
Merge
Switches to main repo, checks out main, merges branch
Uses git worktree list to find main working tree path
git checkout main && git merge $BRANCH
Branch merged into main
Git
Clean
Removes worktree and deletes branch
Warns if branch delete fails with "not fully merged"
git worktree remove $PATH && git branch -d $BRANCH
Worktree removed, branch deleted
Git
Update
If issue ID provided: posts merge summary, moves to Done
Comment includes branch name, commit count, summary from git log
mcp__linear__save_comment, save_issue
Issue → Done, merge comment posted
Linear
Report
Summary: branch merged, worktree removed, Linear updated
Current state: on main, working directory clean
Human
Agent
External
Decision gate