/agents-skills:orchestrating-slotsfrom agents-skills
Runs an N-slot, event-driven multi-agent orchestration loop over a repo: surveys PRs/issues, dispatches sub-agents by priority, reacts to merge/CI/review events, applies backpressure, and persists state via labels, assignees, and a sentinel pause issue for cold resume.
Ships in agents-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are the orchestrator: a long-running coordinator session that dispatches sub-agents into a fixed number of concurrency slots, watches the tracker and CI for events, and keeps the merge pipeline moving. You do not write feature code yourself in this role — you select, lock, dispatch, verify, rescue, and close. This skill covers the loop itself; the protocols it composes live in sibling skills: the issue-locking skill (gh-issue-locking / jira-issue-locking) (claim/release), dispatching-subagents (briefs, model tiers), driving-prs-to-merge (per-PR CI triage and rescue), the issue control-field skill (gh-issue-labels for GitHub labels, jira-issue-fields for Jira fields) (the control taxonomy), and the issue-filing skill (gh-issue-filing for GitHub, jira-issue-filing for Jira) (turning discovered breakage into dispatchable issues).
Define these in the adopting project's CLAUDE.md before running the loop. Refer to them by placeholder everywhere below.
| Binding | Meaning | Example |
|---|---|---|
<integration-branch> | Branch all PRs target | dev |
<default-branch> | Repo default branch | main |
<repo-slug> | Repo slug for gh --repo | org/repo |
<worktree-dir> | Where agent worktrees live, branched off fresh origin/<integration-branch> | .worktrees/<branch> — see the dispatching-subagents skill for the full definition |
<lockfile-install-cmd> | Lockfile-frozen install | <package-manager> install --frozen-lockfile — see the dispatching-subagents skill |
<pr-ci-workflow> | PR CI workflow filename (for stale-run checks) | pr-checks.yml |
<required-checks> | Which check names gate merge (needed to read UNSTABLE) | CI Summary required — see the driving-prs-to-merge skill for the canonical definition |
<bot-reviewer> | Review bot whose threads may gate merge via required_review_thread_resolution | a code-review bot |
<claim-label> | Active-work lock label/field — see the issue-locking skill for semantics | agent-claimed |
<hold-label> | Operator-hold label/field — see the control-field skill for semantics | do-not-dispatch |
<not-dispatchable-labels> | Additional labels/fields that exclude an issue from dispatch (project extras beyond blocked and needs-spec-input); case must exactly match what the bootstrap script created | needs-triage, wontfix (examples — adapt to your label/field set) |
<sentinel-label> | Label/field marking the pause-sentinel issue | orch:sentinel |
<paused-label> | Label/field whose presence on the sentinel pauses all dispatch | orch:paused |
<slot-count> and lane caps | Total concurrency N; leaf/plumbing split | 8 total; 4 leaf + 1 plumbing under cron mode |
| Cadence tunables | Stall window, backup threshold, lock expiry — calibrate to actual CI runtime | 4h stall, >5 PRs + 15 min no-merge backup, 24h lock expiry (assumes 10–15 min CI) |
For <claim-label> and <hold-label> semantics (including why they must be machine-readable labels/fields, not comments): see the control-field skill and the issue-locking skill. Label/field-name matching in jq filters is case-sensitive; the exact casing bootstrapped by the control-field skill's script is the only casing your queries may assume.
Operator logins are never hardcoded: resolve yours at runtime with ME=$(gh api user --jq .login); peers are whoever else appears as issue/PR assignees. Treat slot counts and throttle policy as operator-set runtime state, not constants — in real use the cap changed many times across sessions.
<slot-count>; default 2–3 when unstated.dispatch #N. This serializes the changes most likely to conflict while parallelizing safe work. If the operator closes a plumbing PR, detect the close next round, free the slot, and return the issue to the queue.This order matters: reconcile reality before adding work, so you never dispatch on stale slot math.
ME=$(gh api user --jq .login). Every count below scopes to $ME.<claim-label> or any assignee), operator-held (<hold-label>), or in any other non-dispatchable state (blocked, needs-spec-input, and any <not-dispatchable-labels>). The triage-state taxonomy is canonical in the issue-filing skill; the exclusion list here must stay in sync with the terminal states defined there:gh issue list --repo <repo-slug> --state open --sort created --limit 50 \
--json number,title,body,labels,assignees \
--jq '[.[] | select(
(.labels | map(.name) | contains(["<claim-label>"]) | not)
and (.labels | map(.name) | any(. == "<hold-label>" or . == "blocked" or . == "needs-spec-input"
or . == "<not-dispatchable-labels>") | not)
and (.assignees | length == 0)
)]'
# per candidate, confirm no in-flight fix the labels do not reflect:
gh pr list --search "Closes #<N>" --state open
The (.assignees | length == 0) filter is the multi-operator race guard — triage labels lie (in real use, ready-to-dispatch persisted after a peer claimed, double-locking 4 issues). Re-verify assignees are empty immediately before each lock; if the race re-check finds an active lock, drop the candidate and take the next rather than contest it. The open-PR probe catches "zombie" issues whose fix is already in flight or merged-but-unclosed.
4. Fill slots P0 → P1 → P2, ascending createdAt within tier. Bundle same-surface issues (same page, same module) into a single dispatch — one agent, one worktree, one PR — instead of three agents racing on one file. Lock each issue per the issue-locking skill before dispatching; brief per the dispatching-subagents skill.
5. Reserve headroom: keep ~25% of slots (2 of 8) free for inbound events. A fully-saturated orchestrator cannot rescue, sweep, or react, and events always come.
React to each event class with its specific response. Handle events before refilling slots — state first, new work second.
| Event | Response |
|---|---|
| PR merged | Close every linked issue per the issue-locking skill's release block; free the slot. For multi-issue PRs, close all of them. See "Close-on-merge" below for the sweep mechanics. |
| Bot review threads land on N PRs | Dispatch one rescue agent per PR, all in the same message (parallel), each scoped to that PR's existing worktree and branch: apply-or-counter each comment, then resolve every thread. Before dispatching, check gh pr view <N> --json state — bot reviews are async, and a fast PR can merge before threads post; a fix pushed to a merged branch is orphaned and never reaches <integration-branch>. Re-land via fresh branch + cherry-pick instead. Details in driving-prs-to-merge. |
| CI failure on a PR you own | Triage per the driving-prs-to-merge ladder (read the failing job's raw log, check the flake ledger, retry transients) before spending a slot on a rescue. |
CI failure pre-existing on <integration-branch> | Different ownership flow: finder owns the fix in a separate dedicated PR, after running the coordination probes (open PRs/issues/branches mentioning the failure) so two agents don't duplicate it. See driving-prs-to-merge. |
| Deploy / smoke-test failure | File a groomed issue per the issue-filing skill, then lock and dispatch. Don't fix inline — the issue is the audit trail and the dispatch unit. But don't chase a deploy failure that predates your changes if the operator handles those separately. |
| Platform-wide gate failure (e.g. a new dependency advisory failing a required check on every open PR) | Preempt everything. This outranks all product work — every slot's output is blocked behind it. Dispatch the fix immediately, hold other dispatches until it lands. |
| Agent completion | Verify-then-trust (below), then refill the slot. |
| Operator command | See the command vocabulary below. |
Poll with gh pr view <N> --json mergeStateStatus,autoMergeRequest. Each state has one correct response; misreading them causes pointless rescue dispatches. The canonical mergeStateStatus table with full semantics lives in the driving-prs-to-merge skill. Orchestration-specific notes:
| State | Orchestrator action |
|---|---|
BLOCKED | Normal — wait. If green-but-BLOCKED 30+ min, check threads first (raw GraphQL; --json reviewThreads can return empty). |
CLEAN | Often autoMerge=false because the queue took over. Re-run gh pr merge <N> --auto — "already queued" is confirmation. |
UNKNOWN | Queue processing in flight — normal. |
DIRTY | Try gh pr update-branch <N> yourself; dispatch rescue only if it returns "Cannot update PR branch due to conflicts". |
BEHIND | None — auto-rebase handles it. |
UNSTABLE | A non-required check failed; doesn't block merge by itself. Check whether it's a known advisory (no action) or a real regression (fix it — prioritize if it gates other work). |
False signals to rule out before any intervention:
gh run list --branch <branch> --workflow=<pr-ci-workflow> --limit 5 — a SUCCESS for the same SHA means the red is cosmetic.gh pr merge <N> --auto) — the queue rejects the flag and the enrollment silently drops. Diagnose queue boots from the gh-readonly-queue/<integration-branch>/pr-N merge-group runs.autoMerge=false and re-arm each pass — idempotent and free.gh pr edit silent no-op. It can exit 0, print a deprecation warning, and persist nothing. Verify mutations with gh pr view --json <field> or use the REST API.<bot-reviewer> threads — check threads first (raw GraphQL; --json reviewThreads can return empty), not the queue. See driving-prs-to-merge.Sub-agents truncate at the final push/PR-open step, drop mandated flags, and occasionally misreport success. The orchestrator owns final verification — on every agent completion, before counting the slot's work as done:
gh pr view <N> --json state,assignees,labels,autoMergeRequest.$ME — in real use ~25% of agents dropped --assignee even when the brief bolded it; re-add via API (works even post-merge). Assignee-scoped slot math and rescue scoping silently break without it.git -C <worktree> status and git -C <worktree> log origin/<branch>..HEAD must be empty. The dangerous case: an agent resolves its review threads (PR goes green and enqueues) while its actual fix sits committed-but-unpushed — the queue then merges pre-fix code under falsely-resolved threads. Also note git push exit 0 is unreliable under heavy pre-push hooks; trust git ls-remote origin <branch> matching local HEAD, not the exit code.Salvage before re-dispatch. A stalled or truncated agent's worktree usually contains finished, committed work. Audit it (git log origin/<branch>..HEAD; git status) and push / open the PR yourself rather than re-running the task — re-dispatching hits the same wall and restarts from scratch. This is also why every brief mandates "commit per logical step" (see dispatching-subagents §(f)): with per-step commits, recovery resumes from the last commit in minutes instead of replaying an hour of work.
Declare a queue backup only when all three hold:
gh run list, don't infer.Response to a true backup: stop dispatching (every added PR makes a jammed queue strictly worse), investigate the head of the queue (is the lead PR stuck? is <integration-branch> itself red?), and audit for the undeclared-dependency class (below).
Explicitly not a backup: 2–4 PRs in flight while CI works through them (normal when CI takes 10–15 minutes each), and cancelled-run shadows with a parallel green run for the same SHA. The negative criteria matter as much as the positive — without them orchestrators halt on normal churn or keep dispatching into real jams. Recalibrate the thresholds to your project's actual CI runtime.
Gated-queue hold: when every open PR is waiting on one fix landing (a lint-rule change, a dep promotion, a broken required check), hold your free slots even though they're free — new PRs just accumulate rebase thrash behind the gate. Resume filling once it clears.
<integration-branch> ≠ <default-branch>)GitHub's Closes #N auto-close only fires for merges to the default branch. If PRs land on a separate integration branch, every issue stays open and every lock stays held unless you close explicitly — and slot accounting (which counts claimed issues) silently saturates until you believe all slots are full forever.
On every pass, for every PR merged since the last pass, run the full release block from the issue-locking skill:
gh issue edit <N> --remove-label "<claim-label>"
gh issue close <N> --reason completed --comment "Resolved by PR #<PR-number> (merged into `<integration-branch>`)."
gh issue comment <N> --body "Session lock released — PR #<PR-number> merged."
Handle multi-issue PRs (multiple Closes #N lines) by running the block for all of them. Leave the assignee in place — it remains a useful ownership-history signal. Also run this defensively during reconciliation: any claimed issue whose linked PR is already closed gets its lock released, and any candidate issue gets the pre-dispatch open-PR probe — zombie dispatches against already-merged work are a real, observed waste mode.
Multiple orchestrator sessions may run against one repo. The assignee field is the cheap, atomic, queryable ownership primitive everything builds on:
--assignee "$ME" only. Counting the union across operators double-throttles everyone.Keep a task list with one entry per slot: what's dispatched, status (in_progress / completed), and the outcome recorded in the description. Keep no round counters or in-memory tallies — compute "merged since round start" from timestamps:
gh pr list --state merged --search "merged:>=<round-start-iso>" --json number,title,mergedAt
Counters die with the session; timestamps and labels don't. The payoff: any context reset, restart, or peer operator can reconstruct the loop state cold from the tracker plus the task list.
When the ready-to-dispatch queue drops below ~10 and no recon sweep is already running, dispatch up to 5 parallel recon agents per the issue-filing skill's protocol (one issue per dispatch, <cheap-model>, ≤5 in parallel, sandbox enforced). Do not dispatch a single mid-tier batch sweep — the per-issue sandbox (label/field/comment mutations scoped to one issue) is what makes cheap-model recon safe; a batch covering the whole backlog escapes that sandbox and must escalate to <workhorse-model>. The "no sweep already running" condition prevents duplicate concurrent sweeps. See the issue-filing skill for the recon brief template and the output contract.
Chat memory doesn't survive restarts and is invisible to peers, so persistent loop state lives in one long-lived issue carrying the sentinel label/field. The presence of the <paused-label> on it means dispatch is paused for everyone; rounds still reconcile and report, but skip recon top-up and dispatch ("PAUSED — N in flight"). Operator pause / resume commands add/remove the label/field. Bootstrap once if no open issue carries the <sentinel-label>:
gh issue create --repo <repo-slug> \
--title "[orch] Sentinel — DO NOT close" \
--body "Orchestration sentinel. The presence of the <paused-label> on this issue pauses all dispatch." \
--label "<sentinel-label>"
Report the creation to the operator in the end-of-round status block the first time it fires so they know the sentinel exists.
A tiny fixed verb set keeps operator control deterministic — two-word replies instead of paragraphs, and you never infer intent:
| Command | Effect |
|---|---|
dispatch #N | Releases the plumbing slot and dispatches the surfaced candidate. |
defer #N | Skip this candidate; pick another next round. |
unblock #N | Re-triage #N ignoring the named blocker; clear its blocked label/field. |
force-leaf #N | Override a plumbing lane classification after the operator's manual review. |
pause / resume | Toggle the <paused-label> on the sentinel issue. |
Triage misclassification is corrected by these human overrides — never by the orchestrator second-guessing labels/fields.
The bare fix trigger. When the operator opens chat with fix and no specific issue: pull the next N (default 5) open issues using the opening-sequence selection query (any label is fair game; the exclusions and the assignees-empty filter still apply), confirm no open PR references each, lock each candidate per the issue-locking skill before dispatching, then dispatch one sub-agent per locked issue in parallel. You never write the fixes yourself in this mode and never approve your own agents' PRs — staying free to monitor is the point. If the operator names a specific issue or keyword, scope to that, but still lock first and dispatch rather than fixing inline.
Slot economics: a slot spent on mechanical work is a slot a real fix can't use.
Never dispatch:
Self-handle (cheap, mechanical): gh pr update-branch for DIRTY PRs; the three-command close-on-merge sequence; trivial additive-append conflicts in shared changelog/learnings files (keep both entries); filing issues from operator reports; push + PR-open for an agent that truncated with committed work in its worktree. CI flake reruns on a dispatched PR belong to the implementing agent, not you.
When running on a recurring trigger instead of events, use two cadences:
Queue watch (~every 5 min) — exactly two queries per tick, then act per the state table:
# 1. your open PRs
gh pr list --state open --limit 15 \
--json number,title,mergeStateStatus,autoMergeRequest \
--jq '.[] | " #\(.number) [\(.mergeStateStatus)] auto=\((.autoMergeRequest != null)) — \(.title[0:55])"'
# 2. merged since last tick (drives close-on-merge)
gh pr list --state merged --limit 10 --json number,title,mergedAt \
--jq '.[] | select(.mergedAt > "<last-tick-iso>") | " #\(.number) — \(.title[0:55])"'
The merged-since-last-tick diff is what makes close-on-merge reliable — multi-PR landings in one window are never missed.
Orchestration round (~every 30 min), in fixed order so state is reconciled before work is added:
$ME; release locks on issues whose PR closed; check the sentinel for pause; detect stalls. A PR is stalled only when both hold: updatedAt older than the stall window (default 4h) and no statusCheckRollup entry is IN_PROGRESS — the second condition avoids "rescuing" PRs that are just sitting in long CI. Rescue the oldest stuck PR first (oldest carry the most rebase debt and block the pipeline), skipping ahead only when a newer PR's merge would unblock the older one, or the older one has a STOP-and-report awaiting the operator. Layered recovery: rescue agent, then the lock auto-expiry as fallback.A stable format makes round-over-round diffs legible and embeds the exact reply commands:
<X> PRs merged since last round · <Y> dispatched · <Z> in flight
Awaiting your input (<count>):
- #<n> <one-line question> — see comment
Plumbing candidate — your OK needed:
- #<n> <title> (lane: plumbing — <files>; P<x>)
Reply `dispatch #<n>` or `defer #<n>`.
In flight: #<pr1> #<pr2> ... (slot map: <agent → PR>)
Queue: <ready> ready · <blocked> blocked · <needs-input> needs-input
<lockfile-install-cmd> in that worktree before pre-push hooks can pass — bake this into briefs and run it during rescues. Recurred three times in one observed session.This skill runs in high-volume, repetitive orchestration loops where tokens compound across many rounds and many agents. Operate in caveman mode (load the caveman skill) to cut token use on all working output — status, reasoning, slot tables, completion reports, dispatch and coordination chatter.
Caveman compresses prose only. It must NEVER alter machine-precise content, which stays byte-exact: lock-comment markers, the RECON OK / RECON-ERROR contract lines, JQL, gh / Atlassian-MCP commands, label and field names/values, file:line references, code blocks, and acceptance-criteria checklists. Compress the narration, never the protocol.
Durable prose a human reads later — issue/ticket bodies and PR descriptions — is the exception: write those through the humanizer skill (see the issue-filing skill), not in caveman.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
multi-agent, orchestration, concurrency-slots, merge-queue, event-driven
npx claudepluginhub skyfox675/agents-skills --plugin agents-skills32 skills in this plugin
/browser-diagnosisReproduce and root-cause a front-end bug in a real browser using whichever browser MCP is connected — Chrome (claude-in-chrome), Playwright, Cypress, or Chrome DevTools — not just one. Drive the page as the signed-in user, watch the network and console, capture the failing request/response, shim/mock to isolate the fault, and record a repro, then hand the evidence to the issue being filed. Use whenever a symptom needs live-browser evidence (the toast says failed but it saved, a column shows zero, a click 404s) and from the /…-use-browser command family (and the engine-pinned /…-use-chrome, /…-use-playwright, /…-use-cypress variants), the /…-use-aws-browser commands, and the diagnostician agent. Picks the available MCP automatically and degrades gracefully when none is connected./cavemanUltra-compressed communication mode. Cuts token usage ~75% by speaking like caveman while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra, wenyan-lite, wenyan-full, wenyan-ultra. Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens", "be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested./ci-flake-huntingThe authoritative method for hunting, root-causing, and fixing CI flakes so the merge queue stops ejecting correct PRs and churn drops. A flake is a test that fails then passes on retry with NO code change explaining it — every red speculative merge-queue build ejects a correct PR and disarms its auto-merge, so a live flake taxes every PR behind it. Encodes the loop — MINE CI history for real flakes → REPRODUCE harsher-than-CI → ROOT-CAUSE the real mechanism (hydration/render race, settle race, mock-order, loading-state race, click-through fragility) → FIX FORWARD (test or component, never mask) → VERIFY by re-running many times → UNSTICK the PRs the flake stranded → REPEAT. And how to tell a true code flake from transient INFRA (CDN/mirror outage, expired token mid-suite, rate-limit/WAF, external-service cap, cloud state-lock, CI-provider billing/outage, upstream bump) which must NOT be code-fixed. Use whenever chasing CI instability, "deflake this spec", "CI keeps ejecting my PR", "is this a flake or real", a shard that intermittently reds the queue, or running the ci-flake-hunter lane. Distinct from ci-speed-hunting (which owns slow-but-green jobs — flake never touches timing/sharding).Other plugins' skills for the same job