You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create an intelligent /merge command for Agent OS that automates the complete PR merge workflow with safety checks, code review integration, and automatic worktree cleanup. The command should infer PR context from conversation, validate readiness for merge, address any review feedback, and clean up after successful integration.
Problem Statement
Current workflow pain points:
Manual PR merge requires multiple manual steps:
Checking PR status on GitHub
Reviewing CodeRabbit/Codex feedback
Addressing review comments
Verifying CI status
Manual merge execution
Worktree cleanup
Branch deletion
Context switching between tools:
AI conversation → GitHub web UI → Terminal → Back to AI
Lost context when reviewing feedback
Manual copy-paste of PR numbers
Risk of premature merges:
No systematic pre-merge validation
Easy to miss failing CI checks
Potential to merge with unresolved review comments
Worktree management overhead:
Orphaned worktrees after manual merges
Manual cleanup commands
Risk of deleting wrong worktree
User story:
"As a developer using Agent OS, when I've completed work on a feature branch in a worktree, I want to type /merge and have the system intelligently merge my PR after validating it's ready, addressing any review feedback, and cleaning up the worktree automatically."
Proposed Solution
Create a /merge command that provides intelligent, context-aware PR merge automation with comprehensive safety checks and optional review feedback resolution.
Command Syntax
/merge [pr_number] # Merge specific PR
/merge # Infer PR from current branch/context
/merge --dry-run # Show what would happen without executing
/merge --force # Skip some validation checks (with warnings)
/merge --auto # Enable GitHub auto-merge when checks pass
High-Level Flow
graph TD
A[User: /merge] --> B{PR Specified?}
B -->|No| C[Infer from branch/context]
B -->|Yes| D[Use specified PR]
C --> E[Confirm: Merge PR #XX?]
D --> E
E -->|User confirms| F[Validate Pre-Merge Checks]
F --> G{All checks pass?}
G -->|No| H[Review Feedback]
H --> I{Address issues?}
I -->|Yes| J[Fix issues]
J --> F
I -->|No| K[Abort merge]
G -->|Yes| L[Execute Merge]
L --> M{In worktree?}
M -->|Yes| N[Cleanup Worktree]
M -->|No| O[Update main]
N --> O
O --> P[Verify Success]
P --> Q[Report Completion]
Cleans up worktree metadata with git worktree prune
Updates main branch with latest changes
Reports final status and next steps
Safety Checks:
# Before worktree removal
✓ Merge verified on GitHub
✓ Main branch updated locally
✓ No uncommitted changes in worktree
✓ Branch fully merged (not just PR closed)
Phase 4: Advanced Features & Polish
Goal: Production-ready with full safety and UX
Tasks:
Add --dry-run mode
Add --auto flag for GitHub auto-merge
Add --strategy flag (merge/squash/rebase)
Implement comprehensive error handling
Add rollback on failure
Create comprehensive test suite
Add color-coded status output
Document all flags and options
Acceptance Criteria:
--dry-run shows actions without execution
--auto enables GitHub auto-merge feature
Clear error messages with recovery suggestions
Rollback on merge failures
Beautiful terminal output with colors/icons
Comprehensive documentation
Alternative Approaches Considered
1. Manual Merge with Checklist
Approach: Provide checklist without automation
Pros: Simple, no code changes Cons: Doesn't solve manual overhead, context switching still required
Decision: Rejected - doesn't address core user pain
2. GitHub Actions Automation
Approach: Auto-merge via CI/CD on approval
Pros: Fully automated, no CLI needed Cons: Loss of developer control, harder to customize, requires CI setup
Decision: Rejected - removes developer from loop, different from Agent OS philosophy
3. Git Alias Approach
Approach: Simple bash alias or git alias
Pros: Lightweight, portable Cons: No AI integration, can't parse review feedback, no context awareness
Overview
Create an intelligent
/mergecommand for Agent OS that automates the complete PR merge workflow with safety checks, code review integration, and automatic worktree cleanup. The command should infer PR context from conversation, validate readiness for merge, address any review feedback, and clean up after successful integration.Problem Statement
Current workflow pain points:
Manual PR merge requires multiple manual steps:
Context switching between tools:
Risk of premature merges:
Worktree management overhead:
User story:
Proposed Solution
Create a
/mergecommand that provides intelligent, context-aware PR merge automation with comprehensive safety checks and optional review feedback resolution.Command Syntax
High-Level Flow
graph TD A[User: /merge] --> B{PR Specified?} B -->|No| C[Infer from branch/context] B -->|Yes| D[Use specified PR] C --> E[Confirm: Merge PR #XX?] D --> E E -->|User confirms| F[Validate Pre-Merge Checks] F --> G{All checks pass?} G -->|No| H[Review Feedback] H --> I{Address issues?} I -->|Yes| J[Fix issues] J --> F I -->|No| K[Abort merge] G -->|Yes| L[Execute Merge] L --> M{In worktree?} M -->|Yes| N[Cleanup Worktree] M -->|No| O[Update main] N --> O O --> P[Verify Success] P --> Q[Report Completion]Technical Approach
Architecture
Command Structure:
commands/workflow-merge.md(markdown command file)scripts/workflow-merge.sh(main execution logic)workflow-status.sh,workflow-complete.shpatternsKey Components:
PR Inference Engine (
infer_pr_number())gh pr list --head)Pre-Merge Validator (
validate_merge_readiness())# Check via: gh pr view --json reviewDecision,mergeable,mergeStateStatus,statusCheckRollup ✓ Review status: APPROVED (or no reviews required) ✓ Merge conflicts: MERGEABLE (no conflicts) ✓ CI/CD checks: All passing (via gh pr checks) ✓ Branch protection: Not BLOCKED ✓ No unresolved review threadsReview Feedback Analyzer (
analyze_review_feedback())gh api repos/{owner}/{repo}/pulls/{pr}/commentsMerge Executor (
execute_merge())gh pr merge --merge --delete-branch--merge,--squash,--rebaseWorktree Cleanup (
cleanup_worktree())git worktree list | grep $(pwd)git worktree remove <path>git worktree prunegit checkout main && git pullImplementation Phases
Phase 1: Core Merge Automation (MVP)
Goal: Basic merge with safety checks
Tasks:
commands/workflow-merge.mdcommand filescripts/workflow-merge.shexecution scriptinfer_pr_number())validate_merge_readiness())execute_merge())setup-claude-code.sh)Acceptance Criteria:
/mergeinfers PR from current branchgh pr mergeFiles:
Phase 2: Review Feedback Integration
Goal: Address review comments before merge
Tasks:
fetch_review_comments())Acceptance Criteria:
Integration Points:
Phase 3: Worktree Management
Goal: Automatic cleanup after successful merge
Tasks:
detect_worktree())cleanup_worktree())Acceptance Criteria:
git worktree pruneSafety Checks:
Phase 4: Advanced Features & Polish
Goal: Production-ready with full safety and UX
Tasks:
--dry-runmode--autoflag for GitHub auto-merge--strategyflag (merge/squash/rebase)Acceptance Criteria:
--dry-runshows actions without execution--autoenables GitHub auto-merge featureAlternative Approaches Considered
1. Manual Merge with Checklist
Approach: Provide checklist without automation
Pros: Simple, no code changes
Cons: Doesn't solve manual overhead, context switching still required
Decision: Rejected - doesn't address core user pain
2. GitHub Actions Automation
Approach: Auto-merge via CI/CD on approval
Pros: Fully automated, no CLI needed
Cons: Loss of developer control, harder to customize, requires CI setup
Decision: Rejected - removes developer from loop, different from Agent OS philosophy
3. Git Alias Approach
Approach: Simple bash alias or git alias
Pros: Lightweight, portable
Cons: No AI integration, can't parse review feedback, no context awareness
Decision: Rejected - doesn't leverage Agent OS/AI capabilities
4. Integrated
/mergeCommand (Selected)Approach: Full Agent OS command with AI integration
Pros:
Cons:
Decision: SELECTED - Best aligns with Agent OS mission and user needs
Acceptance Criteria
Functional Requirements
Core Functionality
/mergecommand installed viasetup-claude-code.sh/merge 123)Review Integration
Merge Execution
gh pr mergeWorktree Management
git worktree removeNon-Functional Requirements
Performance
Reliability
Usability
Security
--adminflagQuality Gates
Testing
Documentation
/merge --help)CLAUDE.mdwith command usageCode Review
bash -nsyntax checkSuccess Metrics
Quantitative
/mergewithin 1 monthQualitative
Dependencies & Prerequisites
Technical Dependencies
gh) installed and authenticatedgit worktree remove)~/.agent-os/)Workflow Dependencies
/workflow-statuscommand (for context)External Dependencies
Risk Analysis & Mitigation
Risk: Accidental Merge to Main
Severity: HIGH
Probability: LOW (with validation)
Impact: Code deployed to production prematurely
Mitigation:
--dry-runalways availableRisk: Merge with Failing Tests
Severity: HIGH
Probability: MEDIUM
Impact: Broken code in main branch
Mitigation:
gh pr checks--forceflag requires explicit confirmationRisk: Loss of Worktree Data
Severity: MEDIUM
Probability: LOW
Impact: Uncommitted work lost
Mitigation:
Risk: GitHub API Rate Limits
Severity: LOW
Probability: LOW
Impact: Command fails or delays
Mitigation:
--cachedflags where availableRisk: Network Failure During Merge
Severity: MEDIUM
Probability: LOW
Impact: Unclear state (merged or not?)
Mitigation:
Risk: Branch Protection Conflicts
Severity: LOW
Probability: MEDIUM
Impact: Merge blocked, confusing error
Mitigation:
--adminflag for overridesResource Requirements
Development Effort
Testing & QA
Documentation
Grand Total: 32-46 hours (~1 week of focused development)
Future Considerations
Extensibility
Long-Term Vision
Documentation Plan
User Documentation
/mergecommand help textCLAUDE.mdDeveloper Documentation
References & Research
Internal References
commands/workflow-status.mdscripts/workflow-complete.sh:428workflow-modules/step-4-git-integration.md:134scripts/workflow-status.sh:282-365setup-claude-code.sh:65-77External References
Research Documents
docs/research/pr-merge-automation-best-practices.mddocs/research/gh-cli-worktree-claude-commands.mdRelated Work