Split PR Command
Analyzes PRs for splitting opportunities using commit domains, file dependencies, and risk assessment.
/plugin marketplace add jleechanorg/claude-commands/plugin install jleechanorg-claude-commands@jleechanorg/claude-commandsWhen this command is invoked, YOU (Claude) must execute these steps immediately: This is NOT documentation - these are COMMANDS to execute right now. Use TodoWrite to track progress through multi-phase workflows.
Action Steps: Analyze each commit for logical domains:
Action Steps: Analyze file dependencies to determine coupling:
Action Steps: DON'T SPLIT if:
CONSIDER SPLITTING if: 6. Multiple distinct domains represented 7. Security fixes mixed with other changes 8. Foundation changes that others depend on 9. Independent features that can be reviewed separately 10. Large PR (>15 files) with logical boundaries
ALWAYS SPLIT if: 11. Security vulnerabilities mixed with non-critical changes 12. Breaking changes mixed with safe improvements 13. Emergency fixes bundled with feature work
Action Steps:
Action Steps:
Action Steps:
roadmap/scratchpad_[branch].mdAction Steps:
git cherry-pick -x to preserve provenance)Purpose: Intelligently analyze a PR for potential splitting opportunities using file dependency analysis, commit grouping, and risk assessment.
Usage: /split [branch] or /split (uses current branch)
git show --name-only --format="" HEAD~N..HEAD | sort -u
git show --name-only --format="=== %h %s ===" HEAD~5..HEAD
git log --name-only --format="" HEAD~N..HEAD | sort | uniq -d
**Critical Check**: Files appearing in multiple commits create dependencies that affect splitting strategy.
### Splitting Strategies
#### Strategy A: Foundation-First (for dependent files)
```markdown
When files overlap between commits:
1. **Foundation PR**: Base changes that others depend on
2. **Dependent PRs**: Built on foundation, cherry-picked incrementally
When commits have distinct file sets:
1. **Critical Domain**: Security, breaking changes (highest priority)
2. **Feature Domain**: New functionality, improvements
3. **Infrastructure Domain**: Tooling, deployment, non-user-facing
When mixing high and low risk changes:
1. **High Risk**: Security, breaking changes, database migrations
2. **Medium Risk**: API changes, significant refactoring
3. **Low Risk**: Documentation, tests, minor improvements
MANDATORY: All split PRs must account for every file in original PR
# Original PR files
# Replace N with the number of commits in your PR (e.g., for 8 commits, use HEAD~8..HEAD)
ORIGINAL_COUNT=$(git show --name-only --format="" HEAD~N..HEAD | sort -u | wc -l)
# Sum of split PR files (accounting for overlaps)
# Example: count unique files across all split branches relative to the base branch
# Set your base branch (defaults to origin/main)
: "${PR_BASE:=origin/main}"
# List your split branches
SPLIT_BRANCHES=(split-foundation split-security split-infra)
SPLIT_COUNT=$(
(for b in "${SPLIT_BRANCHES[@]}"; do
git diff --name-only "${PR_BASE}...${b}"
done) | sort -u | wc -l
)
# Must equal: ORIGINAL_COUNT == SPLIT_COUNT
## Split Analysis: feature-complex-pr
### File Analysis
- **Total Files**: 12
- **Commits**: 8 commits across 3 domains
### Overlapping Files Detected
- `api.service.ts` (commits: security, foundation)
- `main.py` (commits: foundation, infrastructure)
### Recommended Strategy: Foundation-First
1. **Foundation PR**: 6 files (types, core utilities)
2. **Security PR**: 4 files (1 shared with foundation)
3. **Infrastructure PR**: 5 files (1 shared with foundation)
**File Count**: 6 + 3 + 3 = 12 unique files ✅
### Implementation Plan
[Detailed commands for creating each PR with proper dependencies]
Implementation: Analyze current PR state, generate intelligent recommendations, create scratchpad with verified file counts and dependency-aware splitting strategy.