Publish a finished autopilot plan — check that every task is done and the final verification passed, bring the branch up to date with its target and re-verify, merge autopilot/<plan-id> into main (or open a pull request), record the published status in state.json, REPORT.md and PROGRESS.md, and clean up the worktree and branch. Use when the user runs /autopilot-publish or asks to merge, ship, land or publish a completed autopilot run.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Autopilot Publish?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/timothy1102-autopilot-publish)
---
name: autopilot-publish
description: Publish a finished autopilot plan — check that every task is done and the final verification passed, bring the branch up to date with its target and re-verify, merge autopilot/<plan-id> into main (or open a pull request), record the published status in state.json, REPORT.md and PROGRESS.md, and clean up the worktree and branch. Use when the user runs /autopilot-publish or asks to merge, ship, land or publish a completed autopilot run.
disable-model-invocation: true
---
# Autopilot publish
The run is over and the work sits on branch `autopilot/<plan-id>`, in the worktree `../<repo>.autopilot-<plan-id>`, one commit per task. Your job is to land it on its target branch (usually `main`) safely, or open a pull request for it, then record that in the plan and clean up. You are the last gate before the work reaches the branch everyone builds on, so check before you merge, and stop and ask whenever a check fails.
## Ground rules
- **Commands that change things only run in the step that calls for them**, after the user has chosen how to publish (Phase 2). Phase 1 only reads.
- **Never** push, force-push, delete a remote branch, or merge a pull request unless the user chose that in Phase 2 or says so now. Never rewrite the target branch's history (no reset, rebase or force-push of `main`).
- **Never** skip hooks (`--no-verify`) or checks. If a hook or check fails, stop and show it.
- **Never** stage or commit anything under `.autopilot/`. Plans are local-only (git-ignored through `.git/info/exclude`).
- **Never edit `run/state.json` or `run/REPORT.md` by hand.** REPORT.md is regenerated on every save, so hand edits are lost. The published status is recorded with `autopilot mark-published` (Phase 5), which updates state.json, REPORT.md and PROGRESS.md.
- `autopilot run` on a plan whose tasks are all done runs **only the final verification** (no worker sessions, no model cost) and records the result. That is how you re-verify the branch.
## Phase 1: Load the plan and check that it is ready (read-only)
1. **Find the plan.** If the user named one (plan id or path), use it. Otherwise list `.autopilot/*/tasks.json` and prefer plans whose tasks are all done and that have no `published` entry in `run/state.json`. If more than one fits, ask which.
2. **Check that no run is active:** `ps -axo pid=,command= | grep -E '[a]utopilot(\.py)? (run|herdr) ' | grep -F '<plan-id>'`. If one is running, stop: publishing needs the finished branch.
3. **Read where it stands:**
- `autopilot status .autopilot/<plan-id>/tasks.json`, and `run/state.json` for `final_verify` (`ok`, `commit`), `stop_reason`, `base_commit` and `published`.
- `autopilot validate .autopilot/<plan-id>/tasks.json` for `plan changed:` warnings.
- `run/REPORT.md`, `DECISIONS.md` (decisions workers made on their own) every review file (`REVIEW.md`, `REVIEW-R<n>.md`: reviewer findings) and `REVIEW-FIXES.md` if present (what `/autopilot-fix-review` did with each finding).
- `tasks.json` for `plan_id`, `base_branch` and the `defaults` verification commands. The SPEC.md Goal section for the merge message.
4. **Already published?** If `published` exists:
- `method: pr` (a PR was opened earlier): check it with `gh pr view <url> --json state,mergeCommit,mergedAt,baseRefName`. If it is merged, update the local target branch (Phase 3, step 2), then skip to Phase 5 and record the merge: `--pr <url> --commit <mergeCommit>`, with `--method merge` when `git merge-base --is-ancestor autopilot/<plan-id> <mergeCommit>` succeeds, and `--method squash` (or `rebase`) when the PR was squashed or rebased on the remote. If it is still open, say so and stop, unless the user wants to change how to publish.
- Otherwise, if the tasks it lists are all the done tasks, the plan is published. Say where and when, and offer only the cleanup that is left (Phase 5, step 3). If tasks were added and done since (a revised plan), publish the new work as usual: the earlier record is kept under `earlier_publications`.
5. **Gate.** The plan is ready only when all of these hold. For each that fails, say why and what fixes it, and stop:
| Check | How | If it fails |
|---|---|---|
| Every task is `done` | `autopilot status` | Failed, blocked or skipped tasks need `/autopilot-revise` and `--retry-failed`; pending ones need the resume command. Removed tasks (`removed_tasks`) do not count. |
| The final verification passed **at the branch's current commit** | `final_verify.ok` is true, and `git rev-parse <final_verify.commit>` equals `git rev-parse autopilot/<plan-id>` | Not run, failed, or the branch moved since: run `autopilot run .autopilot/<plan-id>/tasks.json` (final verification only). If it fails, the fix is a new task via `/autopilot-revise`. If no `final_verify`, `verify` or `full_verify` commands are configured, say so, and run the project's test command from SPEC.md's Verification section yourself instead. |
| No `plan changed:` warnings | `autopilot validate` | A done task edited after it ran, or a task with run state removed, means the plan and the branch disagree. Resolve it with `/autopilot-revise` first. |
| The worktree is clean | `git -C <worktree> status --porcelain` | Uncommitted changes are not on the branch. Ask the user what they are; never commit or discard them yourself. |
| Nothing from `.autopilot/` is tracked on the branch | `git ls-tree -r --name-only autopilot/<plan-id> -- .autopilot` is empty | A plan committed by an older version. Ask whether to remove it from the branch with a commit in the worktree (`git rm -r --cached .autopilot`) before merging. |
The user may tell you to publish anyway (for example with a task they descoped by hand). Then go on, say clearly what is not verified, and pass `--force` in Phase 5 so the record says so.
6. **Summarize for the user**, in a few lines:
- tasks done, total cost (`total_cost_usd`) and run time;
- `git log --oneline <target>..autopilot/<plan-id>` (the commits that will land) and `git diff --stat <target>...autopilot/<plan-id>`;
- the final verification result and commit;
- **what the user is about to accept without having decided it**: the decisions in DECISIONS.md, and reviewer findings that are still open: not addressed by a later task, and not marked `fixed`, `already-fixed` or `rejected` in REVIEW-FIXES.md (list `wontfix` ones as accepted by the user). List them briefly. Unresolved findings marked serious are a reason to stop and suggest `/autopilot-fix-review` (or `/autopilot-revise` for larger work).
## Phase 2: Choose how to publish
Work out the facts first, then ask everything in one AskUserQuestion call (recommended option first, with a one-line reason):
- **Target branch:** `base_branch` from tasks.json; if it is not set, the branch the work started from (`git branch --contains <base_commit>` usually shows it, typically `main`).
- **Does the repo use pull requests?** `git remote -v` has a remote, `gh auth status` works, and there are signs of a PR flow: `.github/pull_request_template.md`, branch protection, or merge commits titled `Merge pull request #…` in `git log --oneline -20 <target>`.
- **Is the target ahead of the branch?** `git rev-list --count autopilot/<plan-id>..<target>` (after `git fetch` if there is a remote).
Questions:
1. **How to publish.**
- *Merge commit* (`git merge --no-ff`): keeps the one-commit-per-task history and groups it under one merge commit, which is easy to revert as a whole. The default for a local workflow.
- *Pull request* (`gh pr create`): the default when the repo uses PRs. Optionally merged right away with `gh pr merge` if the user asks for that.
- *Squash*: one commit on the target; the per-task commits stay only on the branch, which is then not merged in git's eyes.
- *Fast-forward* (`git merge --ff-only`): no merge commit; only possible when the target has not moved.
2. **Push the target branch afterwards?** Only relevant for a local merge with a remote. Default no: say the push command instead.
3. **Clean up afterwards?** Remove the worktree and delete the local branch (recommended once the work is on the target), or keep them. For a PR, the branch must stay until the PR is merged; only the worktree can go.
The user's answers are the approval for the steps below. Anything beyond them (a force-push, deleting a remote branch, resolving a conflict in a way that changes behaviour) needs a new question.
## Phase 3: Prepare and re-verify
1. **The main checkout** is where a local merge happens. `git status --porcelain` must be clean (`.autopilot/` is ignored, so it does not show). If the checkout is on another branch, switching to the target is needed: ask first if that branch has work in progress. The target cannot be checked out there if another worktree already has it; say so and stop.
2. **Update the target from its remote** if there is one: `git fetch`, then `git -C <repo> merge --ff-only @{u}` on the target. If the target has diverged from its upstream, stop and ask; never reset it.
3. **If the target has commits the branch does not** (`git rev-list --count autopilot/<plan-id>..<target>` > 0), the branch was verified against an older target, so bring the target into the branch **in the worktree** and verify the combination:
- `git -C <worktree> merge --no-ff <target> -m "<plan-id>: merge <target> before publishing"`.
- On conflicts: resolve them when the intent of both sides is clear from SPEC.md, the task commits and the target's commits, keeping both sides' behaviour. Show the user each resolution. If the intent is unclear, `git -C <worktree> merge --abort` and ask. Commit the resolution in the worktree.
- For a pull request, this merge goes to the PR branch too, which is usually what reviewers want. If the user prefers the PR to show conflicts instead, skip it and say so.
4. **Re-run the final verification** whenever the branch moved since `final_verify.commit` (step 3, or a commit you made in Phase 1): `autopilot run .autopilot/<plan-id>/tasks.json`. With every task done it runs only the final gate. It can take as long as the project's full test suite, so run it in the background for long suites. If it fails, stop: show the output from REPORT.md; if the failure comes from the merge with the target, say so, and suggest a fix task via `/autopilot-revise` (the merge commit stays on the branch, so the fix builds on it).
5. **Last look at the diff** that will land: `git diff --stat <target>...autopilot/<plan-id>`. Flag anything that does not belong in a product commit: secrets or `.env` files, large binaries, debug output, scratch files, generated files the repo does not track elsewhere, and anything under `.autopilot/`. Stop and ask if you find any.
## Phase 4: Publish
Write the message from the plan, not from git output alone:
```
Merge autopilot/<plan-id>: <one-line goal from SPEC.md>
<two or three sentences: what the plan built>
Tasks:
- T01 <title>
- …
Final verification passed at <commit>. Plan: .autopilot/<plan-id>/ (local).
```
Then, depending on the method (all in the main checkout, on the target branch):
- **Merge commit:** `git merge --no-ff autopilot/<plan-id> -F <message file>`.
- **Fast-forward:** `git merge --ff-only autopilot/<plan-id>`. If it refuses, the target moved: go back to Phase 3, step 3.
- **Squash:** `git merge --squash autopilot/<plan-id>`, then `git commit -F <message file>`. Check `git status` first to be sure nothing from `.autopilot/` got staged.
- **Pull request:** `git push -u origin autopilot/<plan-id>`, then `gh pr create --base <target> --head autopilot/<plan-id> --title "<plan-id>: <goal>" --body-file <file>`. The body: the message above, the task table from REPORT.md (task, title, model, cost), the final verification result, the worker decisions and open reviewer findings from Phase 1, and the total cost. Merge it only if the user asked for that: `gh pr merge <url> --merge` (or the method the repo uses), then `git fetch` and fast-forward the local target.
A pre-commit or pre-merge hook that fails stops the publish: show the output, and fix it with the user (or via `/autopilot-revise`) rather than bypassing it. If a merge stops on conflicts here, the target moved after Phase 3: `git merge --abort`, then go back to Phase 3, step 3.
Push the target only if the user chose that in Phase 2: `git push origin <target>`. If the push is rejected, stop; never force it.
Check the result: `git log --oneline -5 <target>`, and for a merge commit or fast-forward, `git merge-base --is-ancestor autopilot/<plan-id> <target>` succeeds.
## Phase 5: Record and clean up
1. **Record it** (this does no git work; it checks the gate again, mirrors the worktree's PROGRESS.md, DECISIONS.md and REVIEW*.md back to the main checkout, appends a "Published" entry to PROGRESS.md, and rewrites REPORT.md with a `Published:` line and new next steps):
```bash
autopilot mark-published .autopilot/<plan-id>/tasks.json --into <target> --method <merge|ff|squash|rebase|pr> [--commit <sha>] [--pr <url>]
```
- `--commit` is the commit on the target that holds the work (the merge or squash commit); it defaults to the target's tip, which is correct right after a local merge. For a PR that was merged on the remote, pass its merge commit.
- `--method pr --pr <url>` for a PR that is open but not merged yet. Run `/autopilot-publish` again once it is merged to record the merge and clean up.
- `--force` only if the user chose to publish past a failed gate check in Phase 1. The record lists what was skipped.
- If it refuses, read why. "is not merged into" means the merge did not happen as expected: check the target, don't reach for `--force`.
2. **Show the result:** the `Published:` line and "Next steps" from `run/REPORT.md`.
3. **Clean up**, if the user chose it in Phase 2:
- Worktree: `git worktree remove <worktree>`. It deletes the worktree's copy of the plan (git-ignored files), which `mark-published` has just mirrored back; check with `diff -rq <worktree>/.autopilot/<plan-id> .autopilot/<plan-id> -x run` beforehand if you are unsure. If git refuses because of changes, stop and ask; never `--force` without the user's yes.
- Local branch, once the work is on the target: `git branch -d autopilot/<plan-id>`. After a squash, git does not see it as merged and needs `-D`: first confirm that `git diff autopilot/<plan-id> <squash commit>` is empty (Phase 3 merged the target into the branch, so the squash commit and the branch have the same tree). If it is not empty, ask before deleting.
- For a PR that is still open, keep the branch. Delete the remote branch only after the PR is merged and the user agreed.
- Keep `.autopilot/<plan-id>/`: it is the record of the plan, its run and its costs, and it is local-only. The user can delete it whenever they like.
4. **Report** in a few lines: what landed where (commit or PR link), the final verification it passed, the cost, what was pushed or not (with the push command if not), and what was cleaned up or kept.
If more work is wanted later on the same plan, `/autopilot-revise` adds tasks and the same run command continues: a deleted branch and worktree are recreated from `base_branch`, and REPORT.md shows that the new work is not published yet.