Merge a pull request
Merges a pull request with configurable strategy and branch cleanup options.
/plugin marketplace add fractary/claude-plugins/plugin install fractary-repo@fractary<pr_number> [--strategy <strategy>] [--delete-branch] [--worktree-cleanup]claude-haiku-4-5<CRITICAL_RULES> YOU MUST:
YOU MUST NOT:
COMMAND ISOLATION:
WHEN COMMANDS FAIL:
THIS COMMAND IS ONLY A ROUTER. </CRITICAL_RULES>
<WORKFLOW> 1. **Parse user input** - Extract pr_number (required) - Parse optional arguments: --strategy, --delete-branch - Validate required arguments are presentBuild structured request
Invoke agent
Return response
<ARGUMENT_SYNTAX>
This command follows the space-separated argument syntax (consistent with work/repo plugin family):
--flag value (NOT --flag=value)--delete-branch ✅ (NOT --delete-branch true)Merge strategies are exact keywords:
merge, squash, rebasemerge-commit, squash-merge, rebase-mergeExamples:
✅ /repo:pr-merge 456
✅ /repo:pr-merge 456 --strategy squash
✅ /repo:pr-merge 456 --strategy squash --delete-branch
❌ /repo:pr-merge 456 --strategy=squash
❌ /repo:pr-merge 456 --delete-branch true
</ARGUMENT_SYNTAX>
<ARGUMENT_PARSING>
Required Arguments:
pr_number (number): PR number (e.g., 456, not "#456")Optional Arguments:
--strategy (enum): Merge strategy. Must be one of: merge (creates merge commit), squash (squashes all commits), rebase (rebases and merges) (default: merge)--delete-branch (boolean flag): Delete the head branch after successful merge. No value needed, just include the flag--worktree-cleanup (boolean flag): Automatically clean up worktree for merged branch. No value needed, just include the flag. If not provided and worktree exists, user will be promptedMaps to: merge-pr
Example:
/repo:pr-merge 456 --strategy squash --delete-branch --worktree-cleanup
→ Invoke agent with {"operation": "merge-pr", "parameters": {"pr_number": "456", "strategy": "squash", "delete_branch": true, "worktree_cleanup": true}}
</ARGUMENT_PARSING>
<EXAMPLES> ## Usage Examples# Merge PR (default strategy)
/repo:pr-merge 456
# Squash and merge
/repo:pr-merge 456 --strategy squash --delete-branch
# Rebase and merge
/repo:pr-merge 456 --strategy rebase
# Merge and delete branch
/repo:pr-merge 456 --delete-branch
# Merge with worktree cleanup
/repo:pr-merge 456 --strategy squash --delete-branch --worktree-cleanup
# Without --worktree-cleanup flag (prompts if worktree exists)
/repo:pr-merge 456
# If worktree exists, displays:
# 🧹 Worktree Cleanup Reminder
# Would you like to clean up the worktree for feat/456-my-feature?
# 1. Yes, remove it now
# 2. No, keep it for now
# 3. Show me the cleanup command
</EXAMPLES>
<AGENT_INVOCATION>
CRITICAL: After parsing arguments, you MUST actually invoke the Task tool. Do NOT just describe what should be done.
How to invoke: Use the Task tool with these parameters:
Example Task tool invocation:
Task(
subagent_type="fractary-repo:repo-manager",
description="Merge PR #456",
prompt='{
"operation": "merge-pr",
"parameters": {
"pr_number": "456",
"strategy": "squash",
"delete_branch": true,
"worktree_cleanup": false
}
}'
)
What the agent does:
DO NOT:
<ERROR_HANDLING> Common errors to handle:
Missing PR number:
Error: pr_number is required
Usage: /repo:pr-merge <pr_number>
Invalid merge strategy:
Error: Invalid merge strategy: invalid
Valid strategies: merge, squash, rebase
PR not found:
Error: Pull request not found: #999
Verify the PR number and try again
PR not mergeable:
Error: Pull request #456 is not mergeable
Reasons: merge conflicts, required reviews missing, CI checks failing
</ERROR_HANDLING>
<NOTES> ## Merge Strategies--delete-branch to keep repository clean--worktree-cleanup to remove associated worktreesWhen a PR is merged, the associated worktree (if any) should be cleaned up to free disk space and prevent accumulation.
Automatic cleanup (with flag):
/repo:pr-merge 456 --worktree-cleanup
Proactive prompting (without flag):
If no --worktree-cleanup flag is provided and a worktree exists for the merged branch, the system will prompt:
🧹 Worktree Cleanup Reminder
A worktree exists for branch feat/456-my-feature:
Path: ../repo-wt-feat-456-my-feature
Status: Safe to remove (no uncommitted changes)
Would you like to clean up this worktree?
1. Yes, remove it now
2. No, keep it for now
3. Show me the cleanup command
This reinforces cleanup best practices while giving users control.
This command works with:
Platform is configured via /repo:init and stored in .fractary/plugins/repo/config.json.
Related commands:
/repo:pr-create - Create PRs/repo:pr-review - Review PRs/repo:pr-comment - Add comments/repo:branch-delete - Delete branches manually/repo:init - Configure repo plugin
</NOTES>