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 Merge?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/eusilvio-merge)
---
name: merge
description: "Review and squash-merge a feature PR after CI, QA and diff gates, delete the branch and its worktree, and close the linked issues. Human-only."
argument-hint: "<pr-number> [extra-issue# ...]"
allowed-tools: Bash(gh:*), Bash(git:*), Bash(${CLAUDE_PLUGIN_ROOT}/scripts/wt.sh:*), Bash(${CLAUDE_PLUGIN_ROOT}/scripts/codemap.py:*), Bash(${CLAUDE_PLUGIN_ROOT}/scripts/brain.py:*), Bash(${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py:*), Skill, SendMessage
model: sonnet
disable-model-invocation: true
---
Merge feature PR #$ARGUMENTS and close its issues.
Use this for the daily flow: a feature/fix PR. Two supported shapes:
- **Integration flow**: PR targets an integration branch (e.g. `development`).
GitHub does not auto-close linked issues there, so this command closes them.
- **Direct-to-main flow**: feature PRs target the default branch. GitHub
auto-closes `Closes #N` issues on merge.
First token of `$ARGUMENTS` is the PR number. Remaining tokens are extra issue
numbers to close (for PRs that only reference `(#N)` without a `Closes`
keyword).
Speed rule: batch independent `gh`/`git` calls in one parallel message; chain
strictly sequential git steps with `&&` in a single Bash call.
## 1. Fetch everything up front (one parallel message)
Run these THREE calls in the same message - the closing-issues list is static
(comes from body keywords), so fetch it now, not after the merge:
```
gh pr view <PR> --json number,state,headRefName,baseRefName,isCrossRepository,author,body,url,statusCheckRollup
gh repo view --json defaultBranchRef,owner,name --jq '[.defaultBranchRef.name,.owner.login,.name] | @tsv'
gh api graphql -f query='query($o:String!,$r:String!,$n:Int!){repository(owner:$o,name:$r){pullRequest(number:$n){closingIssuesReferences(first:50){nodes{number}}}}}' -F o=<owner> -F r=<repo> -F n=<PR> --jq '.data.repository.pullRequest.closingIssuesReferences.nodes[].number'
```
(If owner/repo are not yet known for the GraphQL call, derive them first from
`git remote get-url origin` in the same message.)
**Local specs.** Every `Flow-Spec: <n>` line in the PR `body` is a local spec
(`.flow/specs/<n>.md`, no GitHub issue). They are linked items just like the
closing issues: QA gate in step 3, close in step 5.
Extract `headRefName` (feature branch to delete) and `baseRefName`. If
`state` is `MERGED` or `CLOSED`, skip to step 5 (still close issues).
## 2. Guards - run BOTH before anything else
**Branch guard.** If `baseRefName` EQUALS the default branch:
- `headRefName` is a long-lived integration branch (`development`, `develop`,
`staging`, `release/*`): STOP - this is a release merge, use `/flow:release`.
- Otherwise it is the DIRECT-TO-MAIN FLOW (feature PR straight to default).
Valid, but merging into the default branch must never happen silently: ask
the user to explicitly confirm before merging. On merge, GitHub auto-closes
`Closes #N` issues - step 5 adapts.
**CI guard.** Inspect `statusCheckRollup` from step 1:
- Empty (repo has no CI): continue.
- Any check FAILURE / TIMED_OUT / CANCELLED: report the failing checks and
STOP. Do not merge over red CI.
- Any check still PENDING: report it and STOP; the user reruns after checks
finish (or explicitly tells you to merge anyway).
## 3. QA gate - behavior first, diff second
**3a. Require a QA report.** For each linked issue or local spec, fetch the
most recent `## QA report` (`${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py spec qa <N>`,
batched; it reads the issue or the local spec).
- Most recent verdict is **FAIL**: do not merge. Report which criteria
failed, then step 3c. **BLOCKED**: do not merge; report the reason and
STOP (a human decision, not a fix).
- **No QA report at all**: do not merge on the strength of the diff alone -
an app that reads correctly and does not run is the exact failure this gate
exists for. Tell the user to run `/flow:verify <N>` and STOP. Override only
if the user explicitly says to merge unverified, or the diff touches
nothing executable (docs, comments, config with no behavior).
- Report is **PASS** but lists `UNVERIFIED` criteria: this is a waiver, and
only the user grants it. List every UNVERIFIED row with its reason and ask
once whether they accept merging without that evidence. Yes -> before
merging, post on the issue (`flowctl.py spec comment <N>`):
`QA waiver: <ids> accepted by @<gh api user -q .login> at <PR head sha>`,
one line per criterion with the reason QA gave. No -> stop; the way
forward is to verify them (`/flow:verify <N>`, a browser, the manual
steps). `/flow:run --merge` never waives: `flowctl merge` refuses any
report with an UNVERIFIED row.
**3b. Then read the diff** (`gh pr diff <PR>`) for what running the app
cannot reveal: secrets or credentials committed, destructive migrations,
dependencies added without need, auth or permission checks removed, changed
lines that trace to no criterion in the issue, schema changes without the
matching docs the repo's CLAUDE.md demands. Run
`${CLAUDE_PLUGIN_ROOT}/scripts/codemap.py check --changed <baseRefName>` inside the PR's worktree (or after
`gh pr checkout`): `MISSING`/`ORPHAN` lines are minor findings - list them,
they do not block. Same for `${CLAUDE_PLUGIN_ROOT}/scripts/brain.py check --changed <baseRefName>`
when the repo has `<brain>/`: `STALE?`/`ANCHOR`/`LINK` are minor findings.
(`<brain>` = the directory `${CLAUDE_PLUGIN_ROOT}/scripts/brain.py dir` prints (`docs/brain/` by default; `.flow/brain/` of the main checkout for a local, unversioned brain).)
Apply the calibration in the `qa-criteria` skill: you are reviewing code you
did not write and have no stake in landing. "The intent is clear" and "minor,
can be a follow-up" are not verdicts you get to reach.
- **Critical finding**: do not merge. Report each as
`path:line - problem - suggested fix`, then step 3c.
- **Minor findings**: proceed, but list them in the final confirmation.
- Trivial diff (docs, typo, small mechanical change): say so and proceed.
**3c. Send it back to the agents that built it.** When the item came through
`/flow:run` in this session, its implementer and QA are still alive, with
the code and the evidence in their heads (`agent-pipeline`, section Agent
lifetime). Use them instead of stopping cold:
1. `${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py agents <N>`. Exit 1 (no agents) ->
STOP as before; the user reruns `/flow:run #<N>` to fix.
2. Tell the user in one line what goes back and to whom, then
`flowctl.py init <N>` (the slot was released at `ready`; ports may change)
and `flowctl.py set <N> stage=fix round=<last QA round + 1> note=merge-gate`.
3. `SendMessage(to: <impl id>, "Merge gate on PR #<PR> found:\n<every FAIL row
or critical finding, verbatim>\nFix in the same worktree, branch and PR,
rerun your checks, reply with the pushed sha, the ## Reply to QA block
and the PR: line.")`. If it fails (the id is gone: another session) ->
STOP as before.
4. On its `PR:` reply: `flowctl.py talk <N> impl qa reply "<Reply to QA>"`,
`flowctl.py set <N> stage=qa`, `flowctl.py qa-env <N> up branch=<headRefName>`
when `flowctl.py qa-env recipe` exits 0 (its lines go into each QA
message), and `SendMessage` each QA (`qa`, or every
`qa:<part>` followed by `flowctl.py qapart <N> merge sha=<sha> --post`):
"Merge-gate round <r>. Fix pushed (<sha>); ports may have changed, run
flowctl.py env <N> again. Your implementer answered:\n<Reply to QA>\n
Re-verify what failed plus what touches the same code, post the report,
end with your verdict line."
5. `ASK:`/`ANSWER:` lines in between go through the bridge exactly as `run`
step 5 says.
6. `VERIFY:PASS` -> `flowctl.py done <N> ready` and restart this skill from
step 1 (new sha: CI runs again, and a pending CI stops you there - say the
user reruns `/flow:merge <PR>` when it is green). Anything else ->
`flowctl.py done <N> blocked` + note, report, STOP.
One merge-gate round per `/flow:merge` call; it does not count against the
3-round QA cap, and it never merges on its own result without passing steps
1-3 again. While waiting for an agent, end the turn; its reply arrives as a
notification.
## 4. Merge (squash)
```
gh pr merge <PR> --squash --delete-branch
```
`--delete-branch` removes the remote feature branch. If merge fails
(conflicts, checks failing), report the error and stop. Do not force-merge.
Then clean up local state. The pipeline left a worktree for this branch
(`wt.sh rm` is a no-op when there is none, and refuses a worktree with
uncommitted changes to tracked files: show them to the user and pass
`--force` only after they agree to lose them); remove it first, so the local
branch is no longer checked out anywhere:
```
${CLAUDE_PLUGIN_ROOT}/scripts/wt.sh rm <headRefName>; ${CLAUDE_PLUGIN_ROOT}/scripts/wt.sh rm <issue-number>
```
`${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py qa-env <N> down` takes the shared
QA environment down if it is still up (servers and its worktree). A split QA
without it left one worktree per part: for each id in
`${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py qapart <N> ls` other than `int`,
`${CLAUDE_PLUGIN_ROOT}/scripts/wt.sh rm <N>-qa-<id>`. The item's agents need
no cleanup: the merge is where their job ends, they are idle and go with the
session. Never `TaskStop` them.
Update the base **without moving the user's checkout off what they are doing**.
Check `git branch --show-current` and `git status --porcelain` in the main
checkout, then pick exactly one:
| Main checkout is on | Do |
|---|---|
| `<baseRefName>` | `git pull --ff-only origin <baseRefName>` (uncommitted changes that would be overwritten make it fail: report, do not stash) |
| `<headRefName>`, clean | `git checkout <baseRefName> && git pull --ff-only origin <baseRefName>` |
| `<headRefName>`, dirty | stop and tell the user; do not switch |
| any other branch | `git fetch origin <baseRefName>:<baseRefName>` (fast-forwards the local base without a checkout); never switch the user's branch |
Then `git branch -d <headRefName>` (skip when `isCrossRepository` is true).
`-d` may fail because the squash commit is not an ancestor; use `-D` only
because the PR was confirmed merged above.
## 5. Close the linked issues
You already have the accurate keyword list from the step 1 GraphQL call.
Union it with any extra issue numbers passed in `$ARGUMENTS`.
- **Direct-to-main flow**: keyword issues were auto-closed by GitHub. Verify
in one parallel batch (`gh issue view <N> --json state,number`); close only
the extras and any that did not auto-close.
- **Integration flow**: nothing auto-closed. Close all resolved issues in one
Bash call:
```
gh issue close <N1> -c "Entregue em <baseRefName> via #<PR>. Fecha manualmente porque a base nao e a branch default (GitHub nao auto-fecha)." && gh issue close <N2> -c "..." && ...
```
- If the union is empty, scan the PR `body` for bare `#N` references and ASK
the user which of those to close (never close bare references silently).
- **Local specs**: nothing auto-closes them. Close each one:
`${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py spec close <n> "Entregue em <baseRefName> via #<PR>."`
Close the item in the orchestrator state, for every closed issue or spec:
`${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py done <N>` (ignore "sem estado":
the issue never went through `/flow:run`).
## 6. Learn - run it, do not suggest it
The user should not have to judge whether an issue taught something. Decide
here and run the `flow:learn` skill yourself (Skill tool). Skip silently
when the repo has no `<brain>/`.
- **Playbook.** `ls "$(${CLAUDE_PLUGIN_ROOT}/scripts/flowctl.py playbook-dir)"`
lists a `<N>.md` for an issue just closed -> run `flow:learn` with
`--playbook --auto`. Promoting is mechanical and dedupes, so it always runs
when there is something pending.
- **Distill.** Run `flow:learn` with `--from <N> --auto` for a closed issue
only when it carries a signal that something durable happened:
- a `## QA report` with `VERIFY:FAIL` (it cost a round);
- `## Open decisions` resolved in the body or in comments;
- the `bug` label, a revert, or an implementer dispute / `spec-mismatch`.
No signal -> do not run it. A clean first-round PASS rarely holds a lesson
the code and its tests do not already carry.
The learn skill applies its own bar and often writes nothing; that is the
expected result, not a failure. Notes land in the main checkout's working
tree, uncommitted (learn never commits).
## 7. Confirm
Report: PR URL + merge status, CI status, QA verdict + round number + every
UNVERIFIED criterion the user waived (with the waiver comment link), review verdict (minor findings if
any), remote+local feature branch and worktree deleted, issues closed
(numbers), which branch the main checkout is on and whether the local base
is at the merged commit.
Then what step 6 did, in one or two lines: notes written or updated (paths,
uncommitted - the user commits them), traps promoted, or "nada durável para
o brain" with the one-line reason. Never end with a `/flow:learn` suggestion:
step 6 already decided.