/engineering-skills:stacked-prsfrom engineering-skills
Breaks large changes into chains of small, dependent GitHub pull requests using the gh stack CLI extension. Guides layering, restructuring, and review workflow for stacked PRs.
Ships in engineering-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Break a large code change into a chain of small, dependent pull requests that can be reviewed and merged independently, using the gh stack extension for GitHub CLI. Each pull request (PR) contains one focused change, reviewers see only that layer's diff, and GitHub links the PRs together as a stack with a stack map and per-layer navigation.
Source docs: About stacked pull requests · Quickstart · Managing stacks
This feature is in public preview and may need to be enabled for the repository. If commands fail with exit code 9 ("stacked pull requests are not enabled"), report that to the user rather than working around it.
A stack is two or more PRs in the same repository where the bottom PR targets the trunk (usually the default branch) and every PR above it targets the branch of the PR below:
┌── feat/frontend → PR #3 (base: feat/api-endpoints) ← top
┌── feat/api-endpoints → PR #2 (base: feat/auth-layer)
┌── feat/auth-layer → PR #1 (base: main) ← bottom
main (trunk)
The key principle: if code in one layer depends on code in another, the dependency must live in the same branch or a lower one. This drives every layering decision:
Layer well up front. Restructuring a stack later is possible but costs a restructure cycle (see "Restructuring a stack" below), while adding the next layer on top is always cheap.
Constraints to know before starting:
Requires GitHub CLI (gh) 2.90.0 or later, Git 2.20 or later, and authentication via gh auth login.
Install the extension once per machine:
gh extension install github/gh-stack
The extension reuses gh authentication — no separate login. gh stack init also enables git rerere automatically, so conflict resolutions are remembered across rebases.
Initialize the stack from the repository root. This creates a tracking entry and the first branch.
gh stack init # interactive: prompts for a branch name
gh stack init feature-auth # non-interactive: name the first branch
gh stack init --base develop feature-auth # target a non-default trunk
Existing branches are adopted automatically; missing ones are created. gh stack init b1 b2 b3 builds the whole stack at once.
Work and commit on the current branch with normal Git commands.
Add a layer when the next logical unit of work starts. Run this from the topmost branch:
gh stack add api-routes
gh stack add -Am "Add login endpoint" # stage all + commit + branch in one step
The -Am shorthand has a useful quirk: if the current branch has no commits yet, the commit lands on the current branch; if it already has commits, a new branch is created on top. Omitting the branch name with -m auto-generates one like 03-24-add_login — prefer explicit names.
Push all branches:
gh stack push
Create and link the PRs:
gh stack submit
This pushes branches, creates a PR per branch with the correct base, and links them as a stack on GitHub. Re-running it updates existing PRs and adds new branches to the existing stack; if every PR has merged, it starts a fresh stack rooted at the trunk.
Inspect the stack at any time:
gh stack view --short # one line per branch
gh stack view --json # machine-readable
Several commands open full-screen interactive editors. In a non-interactive terminal (or as an agent driving a shell), behavior changes in ways that matter:
gh stack view --short or --json. Bare gh stack view opens a full-screen UI in an interactive terminal. Exit code 2 means the current branch is not in a stack — useful for detecting stack state.gh stack submit in a non-interactive terminal behaves like --auto: it skips the editor and uses auto-generated titles. New PRs are created as drafts unless you pass --open. Drafts are usually the right default for agent-authored work; pass --open when the user wants PRs ready for review immediately.gh stack modify and gh stack switch are interactive-only TUIs. Do not attempt to drive them. Use the non-interactive restructure pattern below instead.gh stack sync aborts (exiting successfully, pushing nothing) when local and remote stacks have diverged and the terminal is non-interactive. Resolve divergence by unstacking and recreating (see below).gh stack merge prompts in an interactive terminal. Use --yes plus a merge-method flag (--merge, --squash, --rebase) to merge without prompts.GH_STACK_HYPERLINKS=0 disables OSC 8 hyperlinks and GH_STACK_THEME=light|dark forces a palette.Exit codes are how commands tell you what went wrong — script against them:
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Generic error |
| 2 | Not in a stack, or stack not found |
| 3 | Rebase conflict |
| 4 | GitHub API failure |
| 5 | Invalid arguments or flags |
| 6 | Branch belongs to multiple stacks; disambiguation required |
| 7 | Rebase already in progress |
| 8 | Stack locked by another process |
| 9 | Stacked pull requests not enabled for this repository |
| 10 | Modify session interrupted; recovery required |
gh stack up # one layer away from the trunk
gh stack down # one layer toward the trunk
gh stack top # jump to the top branch
gh stack bottom # jump to the bottom branch
gh stack trunk # jump to the trunk (e.g. main)
gh stack checkout BRANCH
All navigation clamps to the bounds of the stack. gh stack checkout also accepts a stack number, PR number, or PR URL, and can pull down a remote-only stack locally.
Commit on the current branch, then push:
git add ... && git commit -m "..."
gh stack push
When a fix belongs in a layer below where you are working, put it where it belongs and cascade the change upward — don't work around it at the current layer:
gh stack down # or: gh stack checkout BRANCH
# ... edit ...
git add ... && git commit -m "..."
gh stack rebase --upstack # replay layers above onto the fix
gh stack push
gh stack top # return to where you were
A stack must be linear before it can merge. gh stack rebase fetches from the remote and cascades a rebase from the trunk upward so every branch picks up all lower layers. Scope it with --downstack (trunk → current) or --upstack (current → top); --no-trunk skips the fetch and trunk rebase.
On conflict the command stops, prints conflicted files with line numbers, and exits with code 3:
# resolve markers in the listed files, then:
git add <resolved-files>
gh stack rebase --continue
# or start over:
gh stack rebase --abort
Then gh stack push — it uses per-branch --force-with-lease, which is the safe way to update rebased branches. Never bypass it with a manual git push --force.
If the repository requires signed commits, always rebase locally with gh stack rebase rather than the website's "Rebase stack" button — server-side rebase commits are unsigned.
When the bottom PR merges, bring local state up to date in one command:
gh stack sync --prune
This fetches, fast-forwards the trunk, rebases remaining branches if the trunk moved, pushes, syncs PR status, and (with --prune) deletes local branches for merged PRs. Remaining PRs automatically re-target the trunk. Clean remote-ahead updates (PRs someone added on GitHub) are pulled automatically; sync is safe in automation and only stops for true divergence.
Human-interactive path: gh stack modify opens a TUI (drop x, fold down d, fold up u, insert i/I, rename r, reorder Shift+↑/Shift+↓, undo z, apply Ctrl+S). It requires an active stack, a clean working tree, no rebase in progress, no PR queued for merge, and linear history. After conflicts, gh stack modify --continue or --abort; then gh stack submit to rebuild the stack on GitHub.
Non-interactive path (agents, CI, or when the TUI is impractical):
gh stack unstack # dissolve the stack on GitHub; PRs keep their bases
gh stack init b1 b2 b3 # recreate with the desired order; existing branches adopted
gh stack submit --auto # push, recreate PRs and the stack
gh stack link is a third option that links branches or PR numbers into a stack on GitHub with no local tracking — designed for people managing branches with Jujutsu, Sapling, or git-town.
PRs must merge from the bottom up, but you can drive that with one command. gh stack merge merges every PR in the stack up to and including the one you choose, as a single all-or-nothing operation:
gh stack merge 42 # everything up to and including PR 42
gh stack merge --yes --squash # whole current stack, no prompts
gh stack merge 7 # by stack number, without checking it out
Merging the top PR merges the whole stack; merging a mid-stack PR merges everything below it while PRs above stay open and re-target the trunk. Merge commit, squash, and rebase methods are supported and merge-queue aware. Merge requirements cannot be bypassed — GitHub evaluates branch protection and rules when the merge runs.
| Command | Purpose |
|---|---|
gh stack init | Initialize a stack; create/adopt the first branches |
gh stack add | Add a branch on top (run from the topmost branch) |
gh stack submit | Push branches, create/update PRs, link the stack |
gh stack push | Push active branches (--force-with-lease) |
gh stack view | Show branches, PR links, statuses |
gh stack checkout | Check out by stack number, PR number/URL, or branch |
gh stack up / down / top / bottom / trunk | Navigate the stack |
gh stack switch | Interactive branch picker (TTY only) |
gh stack rebase | Cascading rebase across the stack |
gh stack sync | Fetch, rebase, push, sync PR state, optionally prune |
gh stack modify | Interactive restructure TUI (TTY only) |
gh stack unstack | Dissolve stack on GitHub and remove local tracking |
gh stack link | Link branches/PRs into a stack without local tracking |
gh stack merge | Merge up to and including a chosen PR |
For every command's full flags, arguments, examples, environment variables, and exit codes, read references/cli-reference.md — the complete gh stack command reference distilled from GitHub's docs.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub dgalarza/agent-skills --plugin engineering-skills7 skills in this plugin
/conventional-commentsUse this skill when writing, rewriting, or reviewing feedback comments so they follow the Conventional Comments format./conventional-commitsThis skill should be used when creating Git commits to ensure they follow the Conventional Commits specification. It provides guidance on commit message structure, types, scopes, and best practices for writing clear, consistent, and automated-friendly commit messages. Use when committing code changes or reviewing commit history./legacy-code-protocolProtocol for working in legacy code, meaning existing code with few or no tests, or code nobody understands. Modes - survey maps an unfamiliar area (structure, coupling, coverage, hotspots, seams); plan sequences the work into stacked PRs and tickets; pin locks current behavior with characterization tests; change makes one change safely through seams and test-first edits; replace swaps in a new implementation using characterization tests as the parity oracle; review audits a pull request that touches legacy code. Based on Michael Feathers' Working Effectively with Legacy Code. For new code, or code already covered by tests, use tdd./tddUse this skill when implementing or changing behavior with test-driven development. Follow red-green-refactor one behavior at a time, confirm a real failure before writing production code, and keep the test command the project's own./team-code-reviewReview an agent's own code changes or another contributor's pull request by dispatching specialist agents, verifying every finding, and reporting only evidence-backed issues. Use when the user asks for a code review, PR review, review of a diff, or a multi-agent quality audit./webhook-receiverDesign, implement, or review inbound webhook handling that is verified, idempotent, and asynchronous. Use when adding a webhook endpoint or callback receiver for any provider (payments, messaging, analytics, CMS, CRM), when a provider is retrying or timing out, when webhook processing is slow or loses events, or when auditing an existing webhook handler. Language and framework agnostic, with a Rails reference.Other plugins' skills for the same job