parallel-agent-dispatch
Dispatch contract for spawning parallel agents covering worktree collisions, scope overflow, and silent exits. Use when fanning out concurrent agents or authoring a lead prompt.
What this skill does
# Parallel Agent Dispatch Conventions that apply every time more than one agent runs in parallel. Prevents the top failure modes observed across real multi-agent sessions: dirty-worktree cross-contamination, context overflow mid-task, and silent exits that require manual salvage from orphan branches. For lookup tables, worked examples, evidence trails, and the detailed salvage / recovery routines, see [REFERENCE.md](REFERENCE.md). ## When to Use This Skill | Use this skill when... | Use `agent-teams` instead when... | |---|---| | Spawning >1 agent via plain `Agent` tool fan-out (N concurrent invocations) | Single-agent delegation or one-off subagent spawn | | Using `TeamCreate` + teammate spawn for coordinated parallel work | A simple background task with no parallel siblings | | Running worktree-isolated parallel implementation across repos/features | A read-only inline subagent that does not write to disk | | Coordinating parallel investigation or audit swarms | The work fits in the current session without forking | ## Dispatch from the Main Thread When Possible `Agent`, `TeamCreate`, and other parallel-spawn tools may not be present in a sub-agent's sandbox even when they are available in the main conversation. Designing a fan-out from inside a coordinating sub-agent risks silent degradation to sequential single-thread execution — the wall-clock cost of a 5-way design landing in a 5× slower sequential mode. When planning a parallel dispatch: - **Default**: dispatch from the main conversation. The full tool surface is guaranteed. - **Sub-agent orchestrator**: only when the team's outputs do not need to feed back into the main thread. Brief the sub-agent to verify tool availability up front and report sequential fallback as a first-class outcome (see `agent-teams` → "Sub-Agent Caveat: Spawn Teams from the Main Thread" for the detection contract). ## The Three Pillars ### 1. Worktree Preflight Before spawning, the orchestrator must verify: | Check | Rationale | |-------|-----------| | Main working tree is clean (`git status --porcelain` empty) | Agents inherit cwd; uncommitted changes cross-contaminate worktrees | | No existing worktree at each planned path (`git worktree list`) | Nested or duplicate worktrees are the #1 source of salvage work | | Each agent gets a **unique** branch name | Prevents commits landing on the wrong branch when cwd resolution drifts | | Shared counters snapshot (next ADR/PRP number, feature-tracker IDs) | Prevents numbering collisions in parallel doc writes | If any check fails, **refuse to dispatch** and report the blocker. Do not "clean up" uncommitted user work — surface it and ask. #### Transient worktree leaks while a wave runs `Agent(isolation: "worktree")` is supposed to be a sealed filesystem view, but issue [#1319](https://github.com/laurigates/claude-plugins/issues/1319) documents a transient leak: a file the child wrote inside its worktree briefly appears in the **parent** as an untracked entry at the same relative path, then vanishes when the child commits. While a wave is running, the orchestrator must: - Treat untracked files in the parent checkout as **potentially leaked from a child agent**. Do not stash, restore, or commit them. - Wait for the child's completion notification, then diff the parent's orphan against the child's commit. Identical contents = leak; safe to let the child's branch reclaim it. - Avoid `git commit` on the parent branch while child worktree agents are still running — a leaked file caught by `git add -A` lands on the wrong branch. `/git:coworker-check` raises the verdict `worktree_leak_suspected` when an untracked file in the parent matches a path in any linked worktree. Run it before every parent-side commit during a wave. #### cwd-reset leaking git writes into the main repo Distinct from the transient-leak shape above: issue [#1480](https://github.com/laurigates/claude-plugins/issues/1480) documents a git-write agent under `isolation: "worktree"` whose bare `git` commands ran against the **main checkout**, not its worktree — the agent thread's bash cwd reset between calls landed on the session's primary cwd (the main repo root), so every `git fetch` / `git checkout -B` / `git rebase --autostash` mutated `main`. Brief every git-**write** agent: - **Never assume `cwd == worktree`.** Pin the root once (`git rev-parse --show-toplevel` → `$WORKTREE`) and prefix every git call with `git -C "$WORKTREE" …` — the cwd does not persist between calls. - **Forbid bare branch-switching / autostash.** Confirm the agent is inside its worktree before any `git checkout -B` / `git rebase --autostash` — in the main repo these swallow the user's uncommitted work. After the agent returns, run the **post-run main-repo integrity check** (see [REFERENCE.md](REFERENCE.md) "Worktree cwd-reset guardrail (#1480)"): a changed branch or new dirty state is silent main-repo mutation — salvage it like a missing Return Contract before reporting done. ### 2. Scope Budget (per-agent prompt rules) Every agent prompt must declare: - **File scope**: exclusive write paths (glob or explicit list). No agent may write outside its declared scope. Out-of-scope discovery → stop and report (see `agent-teams`). - **Read budget**: soft cap on files examined before producing output. A reasonable default is "≤10 files per exploration hop, ≤3 hops before returning a result." - **Output budget**: expected length of the return summary. Discourages agents from echoing full file contents when a diff or line reference will do. These budgets are what prevents the "security audit agent hit context limits" and "prompt is too long" failure modes — without them, a well-intentioned agent exhausts its window on exploration and truncates its actual deliverable. #### Shared-File Exclusion List Even when each agent's declared file scope is disjoint, a second list of **orchestrator-only files** must be excluded from every agent's write-path. These are the files that many agents are tempted to touch because their work "relates to" them, and where last-writer-wins silently destroys earlier work. Adapt this template to the repository's stack: - Blueprint manifest (`docs/blueprint/manifest.json`) — ID registry, agents risk clobbering each other's pre-allocated IDs - Per-project feature tracker (stats, phases, notes) — touched by every slab - Top-level plan / roadmap docs — agents cite these, they do not edit them - Build manifests (`CMakeLists.txt`, `pyproject.toml`, `package.json`, `Cargo.toml`, `go.mod`) — added-dependency edits are cross-cutting - `justfile` / `Makefile` — new recipes land through the orchestrator so conflicting recipe names surface at review time - Local task-queue stores (e.g. `~/.task/` for taskwarrior) — serialised writes, never concurrent Every dispatched agent brief must call these out explicitly as **not in scope**, regardless of what the agent's declared write-paths say. The exclusion list belongs under a `### Orchestrator-only files` heading in the brief, not buried in prose. > Evidence: five-agent parallel dispatch, zero merge conflicts (2026-04-23). > Before this discipline, informal dispatches suffered silent manifest clobbers > because each agent independently "also" updated the manifest. #### Pre-Allocated Blueprint IDs The Worktree Preflight table's **shared counter snapshot** must expand into **explicit per-agent ID assignment** in each brief — "Use WO-012 for this slice. Other agents claim WO-013 and WO-014." "Pick the next free ID" is a race condition under parallelism: two agents read the same counter, both allocate the same number, the second commit silently overwrites the first's manifest entry. Pre-allocation eliminates the race — the orchestrator, running alone, is the only writer. The same discipline applies to any shared monotonic identifier: ADR numbers, migration sequences, feature-request codes, PRP slugs. #### Wave Splits for
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.