finish-branch
Finish a branch: verify, self-review, check base and size, then offer commit, push, draft PR or keep.
- License 许可
- MIT
- 最近更新
- 2026-11-09
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- finish-branch
- description
- Finish a branch: verify, self-review, check base and size, then offer commit, push, draft PR or keep.
- allowed-tools
- Bash(git rev-parse *), Bash(git symbolic-ref -q --short HEAD), Bash(gh pr list *), Bash(bash ${CLAUDE_PLUGIN_ROOT}/scripts/kern-get *), Bash(bash ${CLAUDE_PLUGIN_ROOT}/scripts/kern-detect *), Bash(gh pr checks *)
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/branch-ops.md2.4 KB
- 参考文档references/discard.md994 B
- 参考文档references/pr-body.md1.4 KB
- 参考文档references/push-and-pr.md2.5 KB
- 参考文档references/release.md2.8 KB
03 SKILL.md 正文
finish-branch
A failure no step handles stops the run: report its output.
Steps
- Defer: if the kern settings block names an override for this job, follow that skill instead, say so in one line, and stop.
- Consent: the user typed
/kern:finish-branchor asked for a push, PR, release, tag or version bump in this session, or autopilot is on. Otherwise stop. Asked to tag a merged release:references/release.md, section After the merge, instead of steps 2 to 11. - Find the work: a worktree the user or caller named, else the newest ledger whose
Worktree:path is ingit worktree list(ls -t <dir>/*/ledger.md,<dir>being whatbash ${CLAUDE_PLUGIN_ROOT}/scripts/kern-dir ledgersprints), elsegit rev-parse --show-toplevel; say which. Runcd <wt>as its own call: G1 and G2 judge by the session's directory.git rev-parse --path-format=absolute --git-dir --git-common-dirprinting one path twice is the main checkout.git symbolic-ref -q --short HEADprints the branch; exit 1 means detached: in a linked worktree, offer "create branch <name from branch.pattern> here" (git switch -c <name>) and go on only after it; in the main checkout, stop: kern never switches its branch. A protected branch: stop; ask which worktree; for a release, offer a release branch perreferences/branch-ops.md. - Base:
<base>isbase_branch; when the plan'sbase:line, a ledgerDecision:line or an upstream other thanorigin/<branch>(git rev-parse --symbolic-full-name @{u}; failing: none) names another, never the ledger'sMain:orWorktree:branch, ask once which base; a missing plan or ledger names none.git remote get-url originfailing means no remote:<baseref>is local<base>. Else<baseref>isorigin/<base>aftergit fetch origin <base>; if that fails, report "base not refreshed" and ask to use the last fetched one.git rev-list --left-right --count <baseref>...HEADprints behind, then ahead; behind above 0 is stale: offer a rebase perreferences/branch-ops.md. - Record the proven tree with
bash ${CLAUDE_PLUGIN_ROOT}/scripts/wt-snap <wt>, then provetest.fullhere by following${CLAUDE_PLUGIN_ROOT}/skills/prove-it/SKILL.md; files the proof wrote are not proven. Atest.fullthat passed on tree<id>in this run stands for that tree; a step that would rerun it on that tree cites the run. Runs on other trees stay. Red, orwt-snapfailing: stop (a red under autopilot: below). - Read
${CLAUDE_PLUGIN_ROOT}/skills/self-review/SKILL.mdand run it on<wt>. Comment hygiene:skip: no-comments ships in M3.fix first,splitor no verdict: stop with its report (autopilot: below).rebase first: handle it as step 3's stale base.ready: go on. - Size gate:
git merge-base HEAD <baseref>, thengit diff --shortstat <merge-base> <tree>(step 4's tree, so untracked files count). Always run it, even after self-review listed the files:pr.max_linesreads its line count. The count is insertions plus deletions in every changed file, tests included; withpr.size_commandset, run it in<wt>with{base}as<merge-base>and{tree}as<tree>, and the last number it prints is the count instead (it fails or prints none: say so, keep the shortstat count). Name the count you compare, aslines: <n> (<measure>). Files changed abovescope_threshold, or a count abovepr.max_lines: rungrep -H '^Decision: [Ss]ize' <dir>/*/ledger.md(<dir>: step 2's; no ledger is no line). ADecision:line in the work's ledger whose what opens with size and that quotes the user's one-PR answer settles it: name that answer, the ledger's count and this step's count, and go on. Else propose a split alone, no menu before it is answered; stop on yes, go on on no. Nevergit addto count, not even-N. - Show the menu, then wait: 1
commit; 2commit and push; 3commit, push and open a draft PR; 4keep. Ask for the reply in those words: G5, G1 and G2 read them as this prompt's consent, while a digit gives none, so each commit, push and PR would ask. Leave out 2 and 3 with no remote orpush.policy: deny, and 3 withpr.policy: deny. Option 4: report the branch and<wt>; stop. Discard only on the typed worddiscard, perreferences/discard.md. - Commit, for options 1 to 3: nothing to commit when
git status --porcelainprints nothing; else run steps 2 to 6 of${CLAUDE_PLUGIN_ROOT}/skills/commit/SKILL.mdon<wt>; its stops stop this skill, and its proof is its own, apart from step 4's. Then offer a rebase step 3 put off. A release, if asked:references/release.md. Option 1 ends with the short SHA. It comparesgit rev-parse HEAD^{tree}with step 4's tree and reports any difference, a rebase included, as unproven. - Dedup, before any push or PR:
references/push-and-pr.md, section Dedup. - Push, for options 2 and 3:
references/branch-ops.md, section Proven tree, thenreferences/push-and-pr.md, section Push. - Draft PR, for option 3:
references/push-and-pr.md, section PR. Report the URL; the worktree stays. Then report each review that ran and its result (self-review's verdict and lanes; from the work's ledger, the task and whole-branch reviews), and, except under a go, rungh pr checks <n>(<n>: the PR number from its URL) once, with no wait: report its output, or why it could not run.
Inputs
Each key: bash ${CLAUDE_PLUGIN_ROOT}/scripts/kern-get <key> (exit 3: the default), a detected one then kern-detect <key> (both exit 3: ask).
| Key | Default |
|---|---|
base_branch, branch.pattern, test.full, pr.template, commit.convention, tracker |
detected |
branch.protected, deploy.envs |
base plus deploy branches; none |
scope_threshold, pr.max_lines, pr.size_command |
4 files; 300 lines; none |
push.policy, pr.policy, pr.dedup |
ask; draft-after-approval, read as ask; on |
Outputs
A commit, push or draft PR, per the choice, or a release; a chat report: SHA, branch, PR URL, the reviews that ran, the PR checks, <wt>, the tag or its wait.
Stops and autopilot
Ask at each stop as a typed reply in chat, never through AskUserQuestion. A G1 or G2 prompt is the confirmation; a declined prompt or a denial stops, reported.
Autopilot is on per the latest kern signal (an autopilot ON: reminder or a kern mode: line with autopilot=on), else the kernel's "Autopilot:" line; a turn with no mode line changes nothing. Under autopilot every kern ask is a denial, nothing is rebased or discarded, no teardown runs but the stale-check removal in references/branch-ops.md, and the menu resolves to option 3, or the highest option step 7 left: commit, then the dedup check, then the push and PR. A judgment call parks as parked: <question>; default: <choice>; why: <one line>. Defaults: a stale base or rebase first: no rebase; go on, the PR body's Merge danger saying so (why: a draft cannot merge; a rebase changes what was proven). A failed fetch: the last fetched ref. Another base named: base_branch. The size gate or a split on size alone: go on, Scope giving the size (why: a split is the user's scope call; a draft can be closed). Dedup: per its section. Stray untracked files can park the finish at commit's "no files, no commit" default. Any other stop waits for a typed reply. Off the end path below, a failed proven-tree check means no push.
Under autopilot a red step 4, first pass or in a round, counts as fix first. fix first, or a size split that also reports it, starts a fix round, up to 3: fix the findings, then rerun step 4 and self-review in full. A split from a finding on a line the last round changed stops, and so does no verdict. The end path is a third round still fix first, a task still open at execute-plan's step 13, a required check that cannot run, or run.md's stop on a defect the ticket demands or on a change it does not name: the run commits its work, pushes its branch, reports each red or unrun check as fail, opens no PR and stops. A red or unrunnable proof stops neither commit's step 4 nor the Proven tree check there: the path claims nothing. A typed reply that says to open the PR opens it.
Under autopilot, stops, unblocking and the run report follow ${CLAUDE_PLUGIN_ROOT}/skills/autopilot/references/run.md.
Under a go, after step 11, follow ${CLAUDE_PLUGIN_ROOT}/skills/autopilot/references/ci.md to gh pr ready or a stop. Its class 4 rebase is the only one autopilot makes.
Red flags
| Thought | Reality |
|---|---|
| "Tests passed earlier this session" | A run proves only the tree it ran on. Push the proven tree. |
| "A PR exists, so there is nothing to push" | A PR at an older head gets the new commits. Only a PR at this head stops. |
| "'Yeah, get rid of it' counts as confirmation" | Only the typed word discard deletes work. |
| "The PR is up, so the worktree is clutter" | Review fixes happen there. |
| "The push was rejected; force will fix it" | The remote moved, unless this run rebased. Investigate; never a plain force. |
04 同仓库更多 Skills
unslop
Rules for prose others read: artifact shapes, document rules and the catalog of AI-writing tells.
technical-writing
Write docs, PR bodies, issues and commit messages a tired engineer understands on the first read.
self-review
Check your own diff before a PR: deterministic checks, blast radius, probes, a fresh doubt pass, then a verdict.
recall
Use when starting or resuming work and state must be rebuilt first: "where did I leave off", "catch me up on X", "what remains", "I got lost in these PRs", a session after days away, or "recall chat" for this thread since my last message. Not for one named session.
prove-it
Use before saying work is done, fixed, passing or verified; before a commit, push or PR; and when a subagent reports success. Runs the proving command fresh, reads all output, checks each acceptance line, and labels other claims measured, inferred or guess.
plan
Turn an approved spec into ordered tasks with exact files, test-first steps, verify commands and blocking edges.