Merges reviewed GitHub PRs using rebase or squash, rebases onto base if behind, resolves conflicts, runs tests, and cleans up branches/worktrees.
npx claudepluginhub nikhilsitaram/claude-caliper --plugin claude-caliper-workflowThis skill uses the workspace's default tool permissions.
Merge (squash or rebase) and clean up branches and worktrees.
Safely merges PRs: verifies CI checks, clean working tree, public repo safety scan, local tests, then executes merge with post-merge monitoring.
Merges GitHub Pull Requests after validating comments replies, tests, linting, CI checks, and milestones. Confirms with user, executes merge commit, deletes branch, and handles post-merge cleanup.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Merge (squash or rebase) and clean up branches and worktrees.
Prerequisite: A PR that has been reviewed (via /pr-review or manually).
Detect if CWD is inside a worktree:
[ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]
If inside a worktree, note IN_WORKTREE=true and capture paths for cleanup:
MAIN_REPO="$(git worktree list --porcelain | head -1 | sed 's/^worktree //')"
WORKTREE_PATH="$(pwd)"
CWD_BRANCH=$(git rev-parse --abbrev-ref HEAD)
Stay in the worktree — gh pr merge is a GitHub API call that works from any directory.
Identify the PR from argument, current branch (gh pr view), or gh pr list --author @me --state open. If multiple candidates and you're not on a branch with an associated PR, ask the user to pick. Store PR number, branch name, and URL.
Detect environment:
DEFAULT_BRANCH from refs/remotes/origin/HEAD (fallback: main/master)IS_INTEGRATION — true when $BRANCH_NAME matches integrate/*; extract FEATURE=${BRANCH_NAME#integrate/}IS_INTEGRATION_CWD — true when $CWD_BRANCH matches integrate/* (CWD is an integration worktree, regardless of which PR is being merged)If branch protection requires human approval and the PR lacks it, tell the user and stop with the PR URL.
Pre-merge rebase check: Verify the PR branch is up-to-date with the base branch:
git fetch origin
git merge-base --is-ancestor origin/$DEFAULT_BRANCH HEAD
Use bare git fetch origin (no branch arg) so refs/remotes/origin/$DEFAULT_BRANCH actually advances. git fetch origin $DEFAULT_BRANCH only updates FETCH_HEAD — the is-ancestor check then compares against a stale ref and reports up-to-date when the branch is actually behind.
If behind (non-zero exit): rebase onto default branch, resolve conflicts, run tests, push with git push -u origin HEAD --force-with-lease. Comment on PR with conflict resolution details. Complex conflicts → stop and ask user.
Merge strategy:
IS_INTEGRATION=true): gh pr merge $PR_NUMBER --rebase — auto-detected, no flag neededintegrate/*): gh pr merge $PR_NUMBER --squash — auto-detected, no flag needed--rebase flag overrides for any non-auto-detected branchcaliper-settings get merge_strategy — use the returned value (squash or rebase) as the merge methodMulti-phase plans produce one squash commit per phase on the integration branch. Rebase preserves this per-phase history on main. Single-phase plans use squash (one phase = one commit). Phase PRs (base is integrate/*) always use --squash.
Never use --delete-branch — branch cleanup is handled in Step 3.
Integration branch (IS_INTEGRATION=true):
IN_WORKTREE: call ExitWorktree with action: "remove" and discard_changes: true — the PR is already merged so local commits are safe to discard
cd "$MAIN_REPO" && git worktree remove "$WORKTREE_PATH" --force, then prefix all subsequent commands with cd "$MAIN_REPO" &&git worktree remove .claude/worktrees/$FEATURE-phase-* for eachgit branch -D phase-a phase-b ... (list from plan.json)git branch -D $BRANCH_NAMEgit worktree prune && git pull --rebase && git remote prune originStandard worktree (IN_WORKTREE=true):
IS_INTEGRATION_CWD=true: the orchestrator is invoking pr-merge from the integration worktree for a phase PR — do NOT remove the integration worktree. Just delete the phase branch (git branch -D $BRANCH_NAME) and prune remotes (git remote prune origin). The orchestrator handles the integration worktree in Phase Wrap-Up step 7d/7e.IS_INTEGRATION_CWD=false (normal case, CWD branch matches PR branch):
ExitWorktree with action: "remove" and discard_changes: true — the PR is already merged so local commits are safe to discard
cd "$MAIN_REPO" && git worktree remove "$WORKTREE_PATH" --force, then prefix all subsequent commands with cd "$MAIN_REPO" &&git branch -D $BRANCH_NAMEgit worktree prune && git pull --rebase && git remote prune originNo worktree: git checkout $DEFAULT_BRANCH && git branch -D $BRANCH_NAME && git pull --rebase && git remote prune origin
Report: PR number/URL, merge status, cleanup status.
| Arg | Effect |
|---|---|
<PR number> | Target specific PR (/pr-merge 42) |
| (none) | Detect from current branch |
--rebase | Use rebase merge instead of squash (for multi-phase final PRs) |
| Mistake | Why |
|---|---|
Skipping ExitWorktree when it's available | cd doesn't persist across Bash tool calls — only ExitWorktree resets CWD at the session level. Always try ExitWorktree first; the cd "$MAIN_REPO" && fallback is for cross-session worktrees where ExitWorktree returns a no-op. |
| Deleting branch before removing worktree | Git refuses. Remove worktree first. |
Using --delete-branch on gh pr merge | Fails in worktree flows. Delete branch manually after. |
Preceded by: pr-review (or manual review)
Auto-invoked by: orchestrate — in pr-merge workflow mode