← Back to News

Turn one giant AI-generated pull request to a reviewable stack

AI coding agents are becoming incredibly useful for tackling large refactoring tasks, migrating dependencies, or implementing complex features across your codebase. But they have a frustrating habit: they generate one massive pull request that changes hundreds of files, making it nearly impossible for your team to review effectively. A 5,000-line PR with changes scattered across 50 files doesn’t just slow down your code review process—it increases the risk of bugs slipping through because reviewers can’t realistically absorb everything at once. GitHub’s solution is stacked pull requests, which breaks that monolithic change into a logical, sequential chain of smaller, reviewable PRs.

Here’s how it works technically: instead of instructing your AI agent to make all changes at once, you teach it to decompose work into discrete, ordered steps. Each PR in the stack builds on the previous one, with earlier PRs merged into later ones rather than directly into main. This creates a dependency chain—PR 1 might handle data model changes, PR 2 refactors the API layer to use that new model, and PR 3 updates the frontend accordingly. Tools like GitHub’s Stacked PRs feature (integrated into their platform) track these relationships, making it clear which PRs depend on which. Your agent needs to understand this structure and generate PRs accordingly, but the payoff is enormous: each individual PR is small enough for a human to actually understand and approve in a single review session.

Why does this matter in practice? Consider a real scenario: migrating from an old authentication library to a new one across a Django application. An uncontrolled AI agent might touch 200 files in one go. A decomposed approach breaks it into: (1) add the new library alongside the old one, (2) update the core auth module, (3) migrate individual service consumers one at a time, (4) remove the deprecated library. Now each PR is 20–30 files and reviewers can reason about it. You also get better git history for understanding why changes were made, easier rollback if something goes wrong, and faster feedback loops since reviewers can approve step one while the agent works on step two.

The practical challenge is training your agents to think this way. If you’re working with tools like Claude’s computer use, GitHub Copilot X, or custom automation frameworks, you’ll need to add prompts or constraints that force decomposition—think of it like code review policies, but for AI. Set clear rules: “Break refactorings into layers,” “One concern per PR,” or “Each PR should be reviewable in under 15 minutes.” This requires a bit more setup upfront, but it pays dividends in team velocity and code quality. If you’re already using AI agents in your workflow, this is a straightforward enhancement that will make you a better engineering team overnight.

Source
↗ The GitHub Blog