split-pr
Analyzes git diffs and code complexity to break large changes into smaller, manageable units for review.
Install
mkdir -p .claude/skills/split-pr && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/6869" && unzip -o skill.zip -d .claude/skills/split-pr && rm skill.zipInstalls to .claude/skills/split-pr
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Analyzes current changes and suggests how to split them into smaller, reviewable PRsKey capabilities
- →Analyze diffs for component and package boundaries
- →Identify logical units of work from large change sets
- →Calculate complexity metrics by file type
- →Filter out generated/vendor code from metrics
- →Group changes by git layer and concern
How it works
Parses git statistics and file trees to cluster changes into logically independent units based on directory structure and code layers.
Inputs & outputs
When to use split-pr
- →Splitting large PRs into smaller ones
- →Refactoring monolithic code changes
- →Organizing feature work for code review
About this skill
Split Large PR into Smaller Changes
Purpose
Help developers break down large changesets into logical, reviewable pull requests. This skill analyzes the current diff and proposes a splitting strategy that keeps changes atomic and reviewable.
Instructions
1. Analyze Current Changes
Run these commands to understand the scope:
# Get detailed file statistics
git diff main...HEAD --stat
# List all changed files
git diff main...HEAD --name-only
# Show commit history for context
git log main...HEAD --oneline
# Count non-generated files changed
git diff main...HEAD --name-only | grep -v 'vendor/' | grep -v '\.pb\.go$' | grep -v 'zz_generated' | grep -v '^docs/' | wc -l
# Count lines changed (excluding generated code)
git diff main...HEAD --stat -- . ':(exclude)vendor/*' ':(exclude)*.pb.go' ':(exclude)zz_generated*' ':(exclude)docs/*' | tail -1
2. Evaluate Size and Complexity
Assess whether the changes exceed recommended limits:
- Target limits per PR:
- < 10 files changed (excluding tests, generated code, docs)
- < 400 lines of code changed (excluding tests, generated code, docs)
- Changes represent one logical unit of work
If changes exceed these limits or mix multiple concerns, proceed to split analysis.
3. Identify Logical Groupings
Examine the changed files and identify natural boundaries:
- By component/package: Group changes by the package or component they affect
- By layer: Separate model changes, business logic, API changes, CLI changes
- By concern: Separate refactoring from new features, bug fixes from enhancements
- By dependency: Identify which changes depend on others
Use these commands to help:
# Group changed files by directory
git diff main...HEAD --name-only | grep -v 'vendor/' | grep -v '\.pb\.go$' | cut -d'/' -f1-2 | sort | uniq -c
# Show changes by package
git diff main...HEAD --name-only | grep '\.go$' | grep -v '_test\.go$' | cut -d'/' -f1-3 | sort | uniq -c
4. Propose Split Strategy
Create a structured plan with multiple PRs:
For each proposed PR, specify:
- PR Name: Brief description (e.g., "Add base container interface")
- Purpose: What this PR accomplishes and why it's needed
- Files included: List of files that would be in this PR
- Estimated size: Approximate lines changed
- Dependencies: Which other proposed PRs this depends on (if any)
- Test coverage: What tests are included
- Order: Suggest the sequence for creating PRs (e.g., "Create this first")
5. Recommend Creation Order
Determine the optimal order for creating PRs:
- Foundation PRs first: New interfaces, base types, shared utilities
- Refactoring PRs second: Changes that use the new foundation
- Feature PRs last: New functionality that builds on the foundation
- Independent PRs anytime: Changes that don't depend on others
6. Present Action Plan
Provide a clear, actionable plan:
## Proposed PR Split
### Summary
Currently [X] files changed with [Y] lines modified. Recommend splitting into [N] PRs:
### PR 1: [Name] (Create First)
**Purpose**: [What and why]
**Files**:
- path/to/file1.go
- path/to/file2.go
**Size**: ~100 LOC
**Dependencies**: None
**Tests**: Includes unit tests for new functionality
### PR 2: [Name] (After PR 1)
**Purpose**: [What and why]
**Files**:
- path/to/file3.go
**Size**: ~150 LOC
**Dependencies**: Requires PR 1 (uses new interface)
**Tests**: Integration tests
[... continue for each PR ...]
## Next Steps
1. Would you like me to help create PR 1 first?
2. Should I create a tracking issue for the overall work?
3. Any changes to this split strategy?
Best Practices
Splitting Principles
- Each PR should pass tests independently: Don't create PRs that break builds
- Prefer multiple small PRs over one large PR: Easier to review and revert
- Keep related changes together: Don't artificially split code that changes together
- Foundation before features: Establish abstractions before using them
- Use feature flags for incomplete work: If a feature spans multiple PRs
Common Split Patterns
-
Refactoring + Feature:
- PR 1: Extract interface and refactor existing code
- PR 2: Add new feature using the interface
-
Multi-layer Feature:
- PR 1: Add data models and database changes
- PR 2: Add business logic layer
- PR 3: Add API endpoints
- PR 4: Add CLI commands
-
Package Restructuring:
- PR 1: Create new package structure (empty or minimal)
- PR 2: Move code to new structure
- PR 3: Update imports and references
- PR 4: Clean up old structure
-
Kubernetes Operator Changes:
- PR 1: Update CRD definitions and generate code
- PR 2: Update controller logic
- PR 3: Add validation and defaulting
- PR 4: Update documentation and examples
What NOT to Split
- Atomic refactorings: Renaming that touches many files but is one logical change
- Generated code updates: Proto, CRD, mock updates should stay together
- Dependency updates: Keep go.mod and vendor changes in one PR
- Tightly coupled changes: Changes that don't make sense independently
Examples
Example 1: Adding New CLI Command
Current state: 8 files changed, 450 lines
Split strategy:
- PR 1: Add business logic to
pkg/package (3 files, 200 lines) - PR 2: Add CLI command and E2E tests (5 files, 250 lines)
Rationale: Business logic is independently testable and reusable
Example 2: Refactoring + Feature
Current state: 15 files changed, 800 lines
Split strategy:
- PR 1: Extract common interface (2 files, 100 lines)
- PR 2: Refactor existing implementations to use interface (6 files, 300 lines)
- PR 3: Add new implementation with feature (7 files, 400 lines)
Rationale: Each PR is independently valuable and testable
Example 3: Operator Enhancement
Current state: 12 files changed, 600 lines
Split strategy:
- PR 1: Update CRD with new fields and generate code (4 files, 150 lines, mostly generated)
- PR 2: Update controller to handle new fields (5 files, 300 lines)
- PR 3: Add validation webhook (3 files, 150 lines)
Rationale: Each PR represents a complete vertical slice of functionality
User Interaction
After presenting the split strategy:
- Ask for feedback: "Does this split make sense for your workflow?"
- Offer to adjust: Be flexible based on user's preferences
- Help with first PR: "Would you like me to help create PR 1?"
- Create tracking: "Should I create a GitHub issue to track all PRs?"
Notes
- Be pragmatic: The goal is reviewable PRs, not arbitrary rules
- Consider the team: Some teams prefer different split strategies
- Document dependencies: Make it clear which PRs block others
- Test independently: Each PR should pass CI/CD checks
When not to use it
- →For extremely small PRs that do not require splitting
- →When dealing with monolithic, tightly-coupled legacy refactors
Prerequisites
Limitations
- →Hard to apply if changes are not logically separable
- →Performance depends on clear repository architectural patterns
- →Does not automatically perform the refactoring itself
How it compares
Uses algorithmic analysis of git diffs to suggest PR boundaries instead of relying on the user's subjective intuition.
Compared to similar skills
split-pr side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| split-pr (this skill) | 1 | 6mo | Review | Intermediate |
| resolve-conflicts | 81 | 8mo | Review | Intermediate |
| dependency-upgrade | 26 | 5mo | Review | Intermediate |
| git-commits | 21 | 4mo | No flags | Beginner |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by stacklok
View all by stacklok →You might also like
resolve-conflicts
antinomyhq
Use this skill immediately when the user mentions merge conflicts that need to be resolved. Do not attempt to resolve conflicts directly - invoke this skill first. This skill specializes in providing a structured framework for merging imports, tests, lock files (regeneration), configuration files, and handling deleted-but-modified files with backup and analysis.
dependency-upgrade
wshobson
Manage major dependency version upgrades with compatibility analysis, staged rollout, and comprehensive testing. Use when upgrading framework versions, updating major dependencies, or managing breaking changes in libraries.
git-commits
bonny
Create well-structured git commits in logical chunks following best practices
git-advanced-workflows
wshobson
Master advanced Git workflows including rebasing, cherry-picking, bisect, worktrees, and reflog to maintain clean history and recover from any situation. Use when managing complex Git histories, collaborating on feature branches, or troubleshooting repository issues.
github-multi-repo
ruvnet
Multi-repository coordination, synchronization, and architecture management with AI swarm orchestration
git-workflow-enforcer
CrazyDubya
Ensures commits follow conventional commits, branch naming conventions, and PR templates. Use when creating commits, branches, or PRs, or when user mentions git workflow.