Use for any work with GitHub's native stacked pull requests - whenever the user says "stack", "stacked PR", "stacked pull requests", "layer", "upstack", "downstack", "restack", or pastes a command starting with `gh stack`. Also load this before running any gh stack or git command in a repository that has a stack, because it defines which commands are blocked at the tool layer and what to run instead.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Stack?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/xingliu0923-stack)
---
name: stack
description: Use for any work with GitHub's native stacked pull requests - whenever the user says "stack", "stacked PR", "stacked pull requests", "layer", "upstack", "downstack", "restack", or pastes a command starting with `gh stack`. Also load this before running any gh stack or git command in a repository that has a stack, because it defines which commands are blocked at the tool layer and what to run instead.
---
# Stacked pull requests with `gh stack`
A **stack** is an ordered chain of branches rooted on a trunk, where each branch
has one PR based on the branch below it, so a reviewer sees only that layer's
diff. GitHub prints a stack trunk-first, left to right:
```
(main) <- auth <- api <- frontend
```
Left is the **bottom** (merges first), right is the **top**. `up` moves away
from trunk, `down` moves toward it.
## What this skill is for
`gh stack` ships its **own** agent skill, and it is the authority on the command
surface — flags, JSON schema, exit codes, stack design, troubleshooting. Do not
restate it and do not guess at flags; run `gh stack <command> --help`, which is
authoritative, or read the reference files that ship with the extension.
This skill covers what that one does not:
1. **Preflight** — whether stacked PRs work here *before* you run anything.
2. **The blocked-command contract** — this plugin denies commands at the tool
layer, and you need to know which, and what to run instead.
3. **Splitting an existing oversized branch**, which GitHub explicitly declines
to cover. See `pr-stack:split-pr`.
## Preflight — required before any stack command
```bash
bash "${CLAUDE_PLUGIN_ROOT}/scripts/check-status.sh"
```
Six lines. Stop and act on these:
| Line | Action |
| --- | --- |
| `gh=NOT installed` / `ext=NOT installed` / `auth=NOT authenticated` | Stop. Load **pr-stack:stack-setup**. |
| `repo=NOT a git repository` | Stop. Read-only questions are fine; repo-modifying commands are not. |
| `stacks=NOT available` | Stop. Stacked PRs are **not enabled on this repository**; every `gh stack` command will fail with exit 9. Tell the user and offer the ordinary single-PR workflow. |
| `stacks=unknown` | Verify with `gh stack view --json` before relying on any stack command. |
Only when `gh`, `ext` and `auth` are all good, you are in a repository, and
`stacks=available`, may you run a repo-modifying stack command.
## Never run these — they block an agent session forever
`gh stack` branches on whether stdout is a TTY. Under a PTY these open a prompt
or a full-screen TUI and **never return**. This plugin denies them at the tool
layer; the correct form is always available.
| Never | Always |
| --- | --- |
| `gh stack view` | `gh stack view --json` (to parse) / `--short` (to show) |
| `gh stack submit` | `gh stack submit --auto` (`--auto --open` for ready-for-review) |
| `gh stack merge <t>` | `gh stack merge <target> --yes` |
| `gh stack init` | `gh stack init <branch> [<branch>...]` |
| `gh stack add` | `gh stack add <branch>` |
| `gh stack checkout` | `gh stack checkout <branch\|pr\|stack-number>` |
| `gh stack switch` | `gh stack up` / `down` / `top` / `bottom` |
| `gh stack modify` | **no non-interactive path exists** — `gh stack unstack --local`, then `gh stack init` |
`gh stack view --json` writes JSON to **stdout** and status messages to
**stderr**. Never parse stderr; branch on exit codes.
## Blocked git commands (only in a repository with a stack)
In an ordinary repository these are left alone. Inside a stack they are denied,
because they silently corrupt it.
| Blocked | Use instead |
| --- | --- |
| `git push --force` / `-f` | `git push --force-with-lease`, or `gh stack push` |
| `git rebase` | `gh stack rebase --upstack` (or `gh stack sync` first) |
| `git rebase --continue` | `git add <files>` then `gh stack rebase --continue` |
| `git rebase --abort` | `gh stack rebase --abort` |
| `git reset --hard` | Requires explicit human approval first |
| `git branch -d` / `-D` / `-m` | `gh stack sync --prune`; restructuring needs approval |
| `gh pr merge` | `gh stack merge <pr-number> --yes` — **`gh pr merge` cannot merge a stack** |
Everything else is allowed and normal: `git add`, `git commit`, `git status`,
`git diff`, `git log`, `git show`, `git checkout`, `git switch`, `git fetch`,
`git push` without `--force`, and every `gh stack` command in its
non-interactive form.
If the user has approved one of the approval-gated commands in plain words, that
single command may be re-run prefixed with `PR_STACK_ALLOW=1`. **Never** add
that marker on your own initiative.
## Which layer does a change belong to?
1. **Default**: the change stays on the layer whose concern it serves.
2. **A problem in code this stack introduced** belongs on the layer that first
introduced that code:
```bash
bash "${CLAUDE_PLUGIN_ROOT}/scripts/pickaxe.sh" "<search-term>"
```
It searches only trunk..top and returns the layer closest to trunk that
contains the introducing commit, or nothing. **Verify before acting on it**
with `gh stack view --json` and `git log --all -- <path>`.
3. **A problem that already exists in trunk** and is unrelated to this stack
belongs in a new branch at the **top** of the stack, or in a separate stack —
never retrofitted into a lower layer.
4. **When ownership is unclear**, do not guess. Show the user the stack and the
relevant diff, and ask.
### Editing a lower layer
```bash
gh stack down # or: gh stack checkout <layer>
git add <files> && git commit -m "<message>"
gh stack rebase --upstack # replay every layer above onto the change
gh stack top # return to where you were
gh stack push
```
Never commit a lower layer's concern on the top branch "for now".
## Constraints that shape every plan
* **Stacks are strictly linear** — one parent, at most one child. Parallel
independent work needs *separate stacks*, not a tree.
* **There is no non-interactive reorder.** Layer order must be decided before
you create the layers; fixing it later costs `unstack` then `init`.
* **PR titles and bodies are auto-generated.** Use `gh pr edit <n>` afterwards
to write a real description.
## Conflicts
```bash
# resolve the files in the working tree
git add <files>
gh stack rebase --continue
```
To back out: `gh stack rebase --abort`. After a failed `gh stack sync` the stack
has already been restored — run `gh stack rebase` to recreate the conflict, then
resolve as above.
## Merged layers
Ask the user before deleting anything. After approval, `gh stack sync --prune`
drops local branches for merged PRs. Pruning never happens without `--prune`.
Do not hand-merge with `gh pr merge`: it merges one PR without retargeting the
layers above it, which GitHub then auto-closes.
## Related skills
* **pr-stack:stack-setup** — install `gh`, the `gh-stack` extension, and authenticate.
* **pr-stack:split-pr** — split an existing oversized branch into a stack.