Skip to content
Back to skills

Prepare

ASecurity

Gets a PR, and every PR stacked above it, green without new work: resolves merge conflicts, fixes failing CI, and applies unresolved review comments, in that order, then confirms CI; --merge squash-merges bottom to top once every gate passes. Triggers on "get this PR green", "prepare this PR", "make the stack mergeable", "fix and merge", "/prepare".

  • 23 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 26, 2026
ai-agentsgobashnodegitsecurity

Security analysis

A100/100

Pro scans all 4 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add mthines/agent-skills --skill prepare --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prepare?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prepare
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/mthines-prepare/badge)](https://www.skillsdirectory.com/skills/mthines-prepare)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prepare
description: >
  Gets a PR, and every PR stacked above it, green without new work: resolves
  merge conflicts, fixes failing CI, and applies unresolved review comments, in
  that order, then confirms CI; --merge squash-merges bottom to top once every
  gate passes. Triggers on "get this PR green", "prepare this PR",
  "make the stack mergeable", "fix and merge", "/prepare".
disable-model-invocation: false
argument-hint: '[<pr-url>|#<n>] [--merge] [--single]'
license: MIT
metadata:
  author: mthines
  version: '1.1.0'
  workflow_type: orchestrator
  tags: [pr, stack, ci, conflicts, review-threads, merge, orchestrator, delivery]
---

# Prepare

Gets one PR, and every open PR stacked above it, to green: no conflicts, passing CI, no unresolved review threads.
It delegates each fix to an existing skill and starts no new work.

## Arguments

Parse `$ARGUMENTS`: the first non-flag token is the PR, everything else is a flag.

| Argument | Default | Effect |
| --- | --- | --- |
| `<pr-url\|#n>` | the current branch's PR (`gh pr view --json url -q .url`) | The bottom PR of the job. |
| `--merge` | off | After the fixes, squash-merge bottom to top behind explicit gates. Read and follow [`rules/merge.md`](./rules/merge.md). |
| `--single` | off | Only this PR; skip the stack walk. |

## Step 0: Resolve scope

1. Set `PRS` to the given PR.
2. Unless `--single`, walk up: for each PR in `PRS`, run `gh pr list --base <its head branch> --state open --json number,url,headRefName`, and append the results.
   When a PR has more than one child, order by depth, then PR number.
3. `PRS` is now ordered bottom to top, which is also merge order.

## Step 1: Check state

For each PR in `PRS`:

```bash
gh pr view <n> --json mergeable,mergeStateStatus,statusCheckRollup,reviewDecision,headRefName,baseRefName
node "${CLAUDE_SKILL_DIR:-$HOME/.claude/skills/prepare}/scripts/threads.mjs" --pr <pr-url>
```

`threads.mjs` prints `THREADS: clear|open|pending — <reason>` last, naming each unresolved thread (outdated ones count); exit 0 only for `clear`.

A PR needs work when `mergeable` is `CONFLICTING`, any check is failing, or any review thread is unresolved.

A check still running is not green: `gh pr checks <n> --watch` first, then decide.
Then classify the head's CI with the bundled helper; its last line is the answer, its exit code 0 only for `green`:

```bash
node "${CLAUDE_SKILL_DIR:-$HOME/.claude/skills/prepare}/scripts/ci-ran.mjs" --pr <pr-url>   # CI: green|pending|red|not-run — <reason>
```

CI ran when at least one required check completed without being skipped, or, when the head reports no required check, at least one GitHub Actions check run did.
External commit statuses and other apps' checks (Vercel, security scanners) never prove CI ran on their own, unless the repo marks one required.
`CI: not-run` (a repo that skips CI on drafts) → report `CI not run (<its reason>)`, never green, and do not merge it.

```text
✗ draft PR, 16 checks SKIPPED, 2 Vercel statuses SUCCESS, none failing → Already green
✓ #41 CI not run (CI not run at b56dfb5: every required check skipped (4))
```

If no PR needs work and every PR ran CI, print `Already green` (without `--merge`) and stop.
Under `--merge`, skip Step 2 and go to the merge step.

## Step 2: Fix, bottom to top

Work one PR at a time, bottom first, and finish it before moving up.
`gh pr checkout <n>` before touching any PR other than the one already checked out.
Skip every step that does not apply:

| Order | Condition | Run |
| --- | --- | --- |
| 1 | Merge conflicts | Start the update, then `Skill("resolve-conflicts")` (below) |
| 2 | Failing CI | `Skill("ci-auto-fix", "<pr-url>")` |
| 3 | Unresolved review threads | `Skill("implement-suggestion", "<pr-url> --resolve-all")` |

`resolve-conflicts` only resolves a merge or rebase that is already in progress, and previews against `origin/main` otherwise.
So for row 1, start the update against the PR's own base first, so a stacked PR is compared with its real base:

```bash
git fetch origin <baseRefName>
git rebase origin/<baseRefName>   # stops on conflicts; resolve-conflicts takes it from there
```

Once the rebase finishes, `git push --force-with-lease`.

If a `Skill()` call is refused, apply that skill's contract inline rather than skipping the step.
A push to a lower PR can create conflicts or red CI above it, so after every push re-run Step 1 for the PRs above.
Do not stop after the first PR, even when it was already green.

Rebases use `--force-with-lease`, never `--force`.
If a rebase conflict is not one you can resolve with confidence, stop and ask; do not resolve unfamiliar conflicts to make the stack green.

## Step 3: Confirm

Watch CI on each PR's new head: `gh pr checks <n> --watch`.
A PR that is not passing after the fixes is reported as blocked, with the reason.

## Step 4: Report

One line per PR:

```text
#1 already green · #2 fixed CI · #3 resolved conflicts · #4 CI not run (every required check skipped)
```

Say `Already green` only when every PR in scope is, and never for a PR whose CI did not run.

## Hard rules

- **Never** start new work, refactor, or re-review.
- **Never** weaken a check to get CI green.
- **Never** merge without `--merge`.
- **Never** merge a PR that sits above one that is still open.

Files in this skill

  • SKILL.md5.2 KB
  • rules/merge.md1.6 KB
  • scripts/ci-ran.mjs11.9 KB
  • scripts/fixtures/skipped-plus-vercel.json5.9 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.