/agent-traffic-control:session-handoff-detect-prior-orphan-prfrom agent-traffic-control
Pre-flight detection of a prior incomplete /session-handoff run that already created a branch, PR, handoff doc, and/or worktree — so the current invocation doesn't open a duplicate PR. Use when (1) you're about to write `docs/handoffs/session_N_handoff.md` as part of /session-handoff, (2) you just created or considered creating a `docs/sN-handoff` branch and `git` reports "branch already exists" or `+` (checked out elsewhere), (3) you find a worktree under `.claude/worktrees/` whose name vaguely matches the current session number, (4) `git status` in a worktree you don't recognize shows "nothing to commit" but the working tree contains a session handoff doc you haven't seen written this turn. Root cause: a prior orchestrator (parallel session, aborted earlier run, or a /session-handoff that ran partway and lost its context) created the branch + handoff doc + push + PR before the current orchestrator picked up. Without this check, you'll write a fresh handoff doc in the main checkout, commit to a different branch, and open a duplicate PR — leaving two competing handoff docs for session N.
Trending skills
7-day visitors to each skill page
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You're running /session-handoff at the end of a long, multi-step session. You start drafting docs/handoffs/session_N_handoff.md in the main checkout. Everything looks fine — git status in the main checkout shows the file as untracked, you write 200 lines, you're ready to commit.
Then you go to create the PR branch and git worktree add fails with "branch already exists." Or worse, you don't check and silently create a duplicate PR.
Root cause: a prior orchestrator already did most of /session-handoff for this session. That orchestrator:
docs/sN-handoff off main.claude/worktrees/sN+1-handoff instead of .claude/worktrees/sN-handoff)docs/handoffs/session_N_handoff.md in that worktreeorigin/docs/sN-handoffThe current orchestrator has no memory of that work — it's a different session instance — and sees only the fresh state. The detection signals are subtle:
git branch --list 'docs/sN-handoff' shows + docs/sN-handoff (the + means checked out in another worktree).git worktree list | grep -i sN reveals a worktree at an unfamiliar path.docs/handoffs/session_N_handoff.md but git status there reports "nothing to commit, working tree clean" — meaning the file is already tracked and committed.gh pr list --head docs/sN-handoff --state open returns an OPEN PR.Without this check, you'll:
docs/sN-handoff-2 or similar) for the same session.Run this pre-flight check at the start of /session-handoff Phase 1 (before drafting the handoff doc):
git worktree list returns more entries than you remember creating this session.git branch --list 'docs/sN-handoff' 'docs/sN-*' shows a hit you didn't create.gh pr list --state open --head 'docs/sN-handoff' --json number,title returns ≥1 result..claude/worktrees/ has a name involving the current or adjacent session number.If any of these are true, the prior orphan exists. Stop and inspect before drafting.
N=15 # current session number
PROJECT_ROOT=/path/to/repo
# 1. Branch check
git branch --list "docs/s${N}-handoff" "docs/s${N}-*"
# A `+` prefix means checked out in another worktree.
# 2. Worktree check
git worktree list | grep -iE "s${N}|handoff"
# 3. Open-PR check
gh pr list --state open --head "docs/s${N}-handoff" --json number,title,body
# Also try variants: docs/s${N}_handoff, docs/sN-handoff-bundle, etc.
# 4. If a worktree exists, inspect its working tree
cd /path/to/that/worktree
git status # "nothing to commit" means the docs are committed
ls docs/handoffs/session_${N}_handoff.md
wc -l docs/handoffs/session_${N}_handoff.md # is there real content?
# 5. If a PR exists, check what's in it
gh pr view <N> --json files,body -q '{files:[.files[].path], body:(.body|.[0:300])}'
| Found | Action |
|---|---|
| Nothing (no branch, no worktree, no PR) | Proceed normally — create branch off origin/main + worktree + doc + PR. |
| Branch exists, worktree exists, docs already committed, PR open | DO NOT create a new PR. Use the existing worktree as your working dir. Add any missing bucket outputs (reviews/, analysis/, plan refresh, next-session prompt) as additional commits to the same branch. Update the PR description to reflect expanded scope. |
| Branch exists but no worktree (e.g., user pruned) | Create a fresh worktree for that branch: git worktree add /path/to/worktree docs/sN-handoff. Proceed as above. |
| Branch + worktree but no open PR (maybe abandoned without PR) | Decide: complete the existing branch and open the PR, OR start fresh. Default: complete the existing one — preserves the prior work. |
Multiple competing branches (e.g., docs/sN-handoff + docs/sN-handoff-bundle) | Close the smaller / less complete one. Pick the one with more content; consolidate. |
| Worktree with an in-progress handoff doc but not committed | The prior orchestrator died mid-write. Read what's there, decide whether to extend or restart, then proceed in that worktree. |
Often the orphan is better than what you'd write fresh — the prior orchestrator may have had more context, included diff stats, captured nuances. Read it before deciding to overwrite.
Specifically check whether the orphan has things the freshly-drafted version typically lacks:
label-audit-skipped: etc.)If yes, keep the orphan and patch in whatever's missing (often: bucket footprint, mid-session incidents, cross-doc links).
If the orphan is thin or wrong, overwrite it — but commit on the same branch so the PR's history shows the evolution.
After applying the runbook, verify:
gh pr list --state open --head "docs/s${N}-handoff" returns ≤1 result.docs/handoffs/session_N_handoff.md exists in the working tree of your active branch.docs/handoffs/session_N_handoff.md is left untracked in any other worktree or in the main checkout.Mid-/session-handoff Phase 1, I wrote session_15_handoff.md (~220 lines) in the main checkout. Then git worktree add origin/main -b docs/s15-handoff failed with "branch already exists." Investigation:
$ git worktree list | grep -i s15
/Users/.../.claude/worktrees/s16-handoff 95e70df [docs/s15-handoff]
^^^ mislabeled dir name — branch is correct
$ cd /Users/.../.claude/worktrees/s16-handoff
$ git status docs/handoffs/session_15_handoff.md
nothing to commit, working tree clean
$ wc -l docs/handoffs/session_15_handoff.md
193 lines
$ gh pr list --head docs/s15-handoff --state all --json number,title,state
{"number":67,"state":"OPEN","title":"docs(s15): session 15 handoff"}
The orphan handoff doc was actually richer than my fresh draft (formal frontmatter, PR-by-PR diff stats, test delta table). I deleted my draft, copied my bucket outputs (reviews/, analysis/, plan refresh, next-session prompt) into the existing worktree, committed onto docs/s15-handoff, and updated PR #67's description to reflect the expanded scope. No duplicate PR.
s16-handoff checking out docs/s15-handoff) is a common artifact of main-bash-cwd-persists-nested-worktree — the prior orchestrator was likely in a different cwd when creating the worktree. The branch name is the authoritative identifier; the directory name is just convenience./ultrareview, /agent-review-panel, /loop, and any custom workflow that creates branches + PRs. The detection runbook is the same; substitute the relevant branch / worktree naming convention.docs/s14-handoff when you're in S16), close that PR explicitly with a comment — don't leave dangling open PRs from a previous arc.main-bash-cwd-persists-nested-worktree — why orphan worktree dir names are often mislabeled.session-handoff-number-collision-with-unmerged-sibling — sibling scenario: two parallel orchestrators both claim session N+1.session-handoff (ships in the separate session-handoff plugin, not here) — the canonical workflow this skill protects.pr-hijack-via-stale-worktree-branch-ref — adjacent worktree-ref staleness pattern.What SKILL.md sets; muted values are Claude Code's defaults
118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control