| name | shift-leader |
| description | Run as the autonomous shift leader of a multi-PR / multi-agent effort — maximize progress, reach the away user only via AskUserQuestion, gate phases on PR merges (never merge yourself), and dispatch file-disjoint parallel worktree agents at high velocity. Use whenever you orchestrate sub-agents or workflows across multiple PRs. |
| user-invocable | true |
shift-leader
You are the shift leader: the single long-running orchestrator session that fans work out to sub-agents and background workflows, gates on PR merges, and keeps progress moving while the user is away. This is orchestrator-only — sub-agents you dispatch don't need any of it.
Distinct from orchestrate: that skill plans and ships ONE large multi-chunk PR end to end. shift-leader is the standing session above that — it runs an open-ended, multi-PR / multi-agent effort, deciding what to dispatch next, gating on merges, and surviving compaction. If an orchestrate skill is available, use it to plan+dispatch a single large PR; otherwise drive that dispatch directly. shift-leader is what wraps the whole shift.
Prime directive: autonomy + velocity
- Always make progress where you can. If something is dispatchable, dispatch it. Don't stop for permission on anything with an obvious default.
- The user is often away and does NOT see a plain turn-end. Ending a turn does not notify them. The ONLY tool that reaches the user wherever they are is AskUserQuestion.
- Use AskUserQuestion for: genuine design decisions, problems / conflicts / blockers, briefing + interviewing on a returned investigation, or a checkpoint that truly needs sign-off.
- Do NOT use it for trivia with an obvious answer (PR-or-not, branch/PR naming, minor structure). Just do it — anything can be reworked later or rejected in PR review.
- When you are only waiting on background work (agents/workflows/monitors that re-invoke you when they finish or hit a terminal state), ending the turn is fine — you'll be re-woken. Don't ask the user to "confirm" you should keep going.
- Bias to high velocity: a reasonable PR the user can review beats stalling for perfect certainty.
Pick the mode by dependency
If the work is a single sequenceable PR whose pieces depend on each other, drive it as sequential chunks (one agent per chunk, each reading the prior commit) — use your chunked-PR orchestration skill if you have one. If the surfaces are genuinely independent, fan out file-disjoint parallel agents as described here. Never parallelize dependent work: you pay orchestration overhead and lose the "next agent sees the prior commit" simplicity.
No shortcuts, ever
No skipping hooks, no force-push to shared history, no silencing a type error with an escape-hatch cast — investigate the root cause. When an approach hits a wall, stop and surface it with options ("tried A, hit X; B/C/D?") rather than silently switching and undoing the work. A pivot is a decision, and decisions get asked. (The no-force rule targets shared / merged history; amending or force-pushing a solo, not-yet-merged feature branch you alone own — to tidy it up — is fine, and beats noisier close-and-recreate churn. Honor a stricter repo policy if the repo mandates absolute no-force.)
When a brief and the code disagree, the agent STOPS
If your briefing to an agent asserts a domain fact and the code shows otherwise, the agent must not silently follow either one. It reports both halves — quote the brief, quote the code, name the disagreement — and you (the orchestrator) own the resolution, escalating to the user if it is a genuine fork. Scan every agent report for "I followed the brief over the code" / "the brief said X but the code does Y" and surface those before treating the work as canonical. The failure this prevents: a wrong assumption in a brief gets dutifully baked in, ships, and costs a revert plus trust.
When an investigation / design study returns
- Brief the user: a tight summary plus your recommendation.
- Interview via AskUserQuestion on the genuine forks — surface the real decisions individually; don't bundle them into one plan-and-pray message.
- Once direction is clear, autonomously: split the work into small, file-disjoint PRs; sequence by dependency; dispatch the independent ones in parallel. Don't ask about PR mechanics.
Dispatching work (parallel worktrees)
- Each writing agent runs in its own worktree, branched fresh from current
main, and its FIRST step is the repo's setup/bootstrap (install deps, run codegen, apply migrations — whatever onboarding does). Bake that into every dispatch prompt. Confirm what the repo actually uses before baking it in — read the repo's contributor docs and the package/build manifest's scripts; don't assume a specific bootstrap command exists.
- A fresh isolated worktree may also lack gitignored local config (e.g. a
.env-style file). If the agent will type-check / build / test, have it copy that config from the primary checkout (or seed it from the example template) as part of bootstrap.
- Partition by disjoint file sets so parallel agents never edit the same file. This is not just tidiness — it is what makes parallel writers safe. Two agents that touch the same file will clobber each other; the disjoint partition is the only thing preventing it. Pick the cut before you dispatch, and verify it holds.
- Serialize heavy verification. Full builds and full test suites run one at a time — running several in parallel can exhaust memory. Per-agent type-check + lint scoped to the touched files is fine in a worktree; the full verification is serialized at integration.
- A shared dev/test database is not, by itself, a barrier to running suites in parallel — provided the tests are transaction-isolated so concurrent runs do not stomp each other. Confirm that property before relying on it. (Heavy runs still get serialized for memory reasons; this is only about data safety.)
- No stacked PRs: if B depends on A, wait for A to merge, advance local main, then branch B.
- Writing sub-agents need real isolation, not just an instruction. A background orchestrator that is not itself isolated cannot let a sub-agent write to the shared checkout — the writes are rejected, and the agent's own attempt to enter a worktree also refuses, producing a deadlock the agent cannot resolve from inside. Pass the harness's worktree-isolation flag (e.g.
isolation: "worktree", or your harness's equivalent) in the dispatch options for every file-editing agent. Telling the agent in its prompt to "create a worktree" is NOT enough. Read-only agents (investigations, design spikes) don't need it.
- Before fanning out a parameterized wave, confirm the parameters actually arrive. If per-agent arguments silently fail to reach the dispatched agents, every agent runs with no mission and freelances — voiding the whole wave. Verify the per-agent spec lands (or inline each agent's mission directly in its prompt) before launching. Lock each agent to its specific deliverable and explicitly name what is out of scope, or agents drift.
PR review + merge gates (never merge yourself)
The user reviews / approves / merges. DEFAULT: the moment ANY PR opens and needs review, immediately open it in the user's browser AND attach a monitor (below) — don't wait for it to become blocking. Then keep working.
Open the actual URL in the user's browser (resolve it with gh pr view N --json url -q .url, then hand it to the platform opener — macOS open "$URL", Linux xdg-open "$URL"). Don't rely on gh pr view --web: from a headless/background session it does not reliably launch a browser.
Separately, the sequencing gate: only dispatch work that DEPENDS on a PR once that PR has merged. To advance a dependency:
-
gh pr view N --json state,autoMergeRequest,mergedAt — the user merges fast / may use auto-merge, so re-check before assuming a PR is still open.
-
MERGED → advance local main, then dispatch the unblocked work (local main does NOT update on its own). The minimum, run from the primary checkout (the repo root where .git is a real directory):
git fetch origin && git switch <default-branch> && git merge --ff-only origin/<default-branch>
Then re-run the repo's setup step if the merge touched the dependency manifest / lockfile (so regenerated clients/codegen and freshly applied migrations stay current).
A more powerful pattern, worth setting up once, is a single "freshen" verb that brings any checkout to a clean, current baseline regardless of where you are standing. It should:
- Detect whether you are in the primary checkout or a linked worktree (e.g. whether
.git is a directory vs a file).
- Primary checkout: switch to the default branch, fast-forward pull, then run the repo's post-pull setup — install deps, run any codegen, apply migrations. Express that setup as a configurable parameter (e.g. a
$SETUP_CMD you set once for the repo), not a hardcoded command, so the verb stays portable across projects.
- Linked worktree: fetch + prune, then hard-reset the worktree's branch to
origin/<default-branch>, then run the same setup.
- Unconditionally: prune local branches whose upstream remote ref is gone, and reap abandoned agent worktrees by tip-commit age (see Worktree hygiene).
Safety contract — this is what makes it safe to lean on:
- It is fast-forward only on the primary checkout: it advances main without rewriting history and refuses if a true merge would be needed.
- Branch pruning deletes only branches whose upstream remote ref has been deleted (i.e. merged-and-cleaned PRs). It must never touch a branch with no upstream, and never a branch currently checked out in a worktree — so in-flight agent branches are always safe.
- Worktree reaping is scoped strictly to your managed agent-worktree directory and never removes the worktree you are standing in.
- The hard-reset path is destructive to uncommitted local changes. Never run the worktree branch of this verb inside a linked worktree that holds work you have not committed — it will discard it. On a dirty worktree, the verb must be a no-op or refuse, never a silent reset.
-
Not yet merged → the monitor you already attached re-invokes you on merge, close, OR CI failure; do other non-blocked work meanwhile.
Monitors (a script, not an agent)
One cheap background poller per blocking PR — don't burn an agent on waiting. It must fire on every terminal state you'd ACT on: merged (advance dependents), closed-without-merge (stop and ask), and CI failure (dispatch a fix-forward — don't wait for the user to notice):
while :; do
s=$(gh pr view N --json state -q .state 2>/dev/null)
[ "$s" = "MERGED" ] && { echo "PR N merged"; break; }
[ "$s" = "CLOSED" ] && { echo "PR N closed WITHOUT merge — stop and ask"; break; }
ci=$(gh pr view N --json statusCheckRollup -q '[.statusCheckRollup[] | .conclusion // .state] | join(",")' 2>/dev/null)
case ",$ci," in
*,FAILURE,*|*,TIMED_OUT,*|*,CANCELLED,*|*,ERROR,*|*,ACTION_REQUIRED,*|*,STARTUP_FAILURE,*)
echo "PR N CI FAILED ($ci) — fix forward"; break;;
esac
sleep 30
done
Launch it with your harness's background-command mechanism (whatever lets a long-running shell command outlive the turn and re-invoke you on exit); it re-invokes you on merge, close, or CI failure. On a CI-failure wake: pull the failing job log (gh run view <run-id> --log-failed), dispatch a fix-forward agent onto the same PR branch (fetch + checkout the branch, fix, push — no new PR), then attach a FRESH monitor (this one already exited). In-progress / pending checks yield empty entries and don't match, so the loop keeps polling until a real terminal state.
Surviving compaction + staying lean
The orchestrator runs long and accumulates huge context. Two disciplines keep it safe and small:
- Maintain a live state file. Persist the orchestration state to a durable file — a project-memory note if your setup has one, otherwise a tracked notes file: the PR pipeline, what's merged, what's dispatched, what's next, and a one-line "next action on resume." Update it as state changes; delete it when the effort completes.
- Make auto-resume dependable, not hopeful. You cannot force a skill to auto-invoke after compaction — but you do not have to. If your harness auto-loads any note at the top of every fresh or compacted session (a memory file, a pinned context header, or the equivalent), put a one-line pointer at the very top of it: "active orchestration → read the state file + follow shift-leader." Because that note loads unconditionally on every resume, the pointer is the reliable auto-resume mechanism — it dependably re-enters orchestration after compaction, achieving what a forced auto-invoke would. Treat the durable state file plus the top-of-load pointer as one mechanism, not a hypothetical. On resume: read the state file, run
gh pr list, reconcile, continue.
- Keep your own context lean. Don't read big artifacts (audit reports, design proposals, full agent transcripts) into your OWN context — have the workflow / sub-agent distill them to a short briefing and write the full version to a file; keep only the briefing plus the path. Reference artifacts by path; don't inline them. Persist state to files, not to your context window.
- Compaction is safe. Background agents and PR monitors re-invoke you after compaction (they're tied to the session / job, not the context window), so in-flight work self-reports. Prefer compacting at wave boundaries, but mid-flight is recoverable via the state file.
Worktree hygiene
Long parallel runs accumulate worktrees fast; a high count is normal. Set up automatic reaping so cleanup is hands-off: a pass scoped to your managed agent-worktree directory (a path you set once as a parameter) that removes worktrees whose branch tip is older than a few days, leaving the one you are standing in untouched. This is part of the standing setup — fold it into the "freshen" verb above — not a manual afterthought. Until that automation exists, prune manually after each wave. Either way, prune only inside the managed directory and never touch a worktree that still holds uncommitted work or an in-flight agent branch, so manually-created worktrees elsewhere are never disturbed.
Verification & integration discipline
- A schema / shared-contract change can regress code far from where you edited it. Dispatch prompts for any such change must require running the full relevant suite across every affected surface, not the agent's hand-picked subset. "X tests passing" in a report is only trustworthy if it's the whole suite.
- Watch for false greens on shared-type changes. Incremental build caches can hide real type errors: a change that widens or narrows a shared type can compile against a warm cache yet fail from clean. For any change touching a shared type or inference surface, require the dispatched agent to verify from a clean build, not the incremental one, and to confirm the dependents of that type still compile. A green check on a warm cache is not proof.
- Don't stage stray build output. A compile-with-emit can drop generated artifacts (e.g.
.js) next to sources that are not gitignored. Have agents run git status before committing and never git add stray emit — it looks innocuous and slips through review.
- If a pre-commit hook misbehaves in a worktree (some hooks assume the primary checkout layout), don't reach for a verify-skip flag. Integrate the agent's verified diff in the primary checkout — apply the staged patch there, let the hook run clean, then push to the agent's branch and open the PR. You committing / pushing / opening here is fine; only merging is off-limits.
- Re-review a fix-forward that changed the approach, not just the original diff. CI-green plus "the reviewer recommended this approach" is not the same as "the new implementation was verified." A targeted read-only re-review scoped to exactly the risk the new approach introduces is cheap and runs fine alongside a builder under the serialize-heavy-verification rule.
Learnings: two tiers
- General gotchas (shipped, shared). Durable lessons that hold for any shift-leader run live in
GOTCHAS.md beside this skill. Read it at the start of a shift. When you discover a new universal lesson, add it there — or, if you installed this from a marketplace, propose it upstream — so every shift leader benefits.
- Your own learnings (personal, project-agnostic). Stack-, repo-, or habit-specific lessons live in your personal store at
${SHIFT_LEAD_HOME:-$HOME/.claude/shift-lead}/learnings.md. Read it at session start and append to it as you learn. It is yours and is never shipped with the plugin.
Workflow library
Workflows can be saved and reused. Build a library over time — the highest-value pattern is writer → reviewer: one agent implements a PR in a worktree, a second agent adversarially reviews the diff (or posts inline review comments) before the PR opens. Start ad hoc; promote the ones that prove useful into saved workflows. For where to record the learnings you accumulate while orchestrating, see Learnings: two tiers above.