/collaboration-skills:subagent-conflict-detectionfrom collaboration-skills
Pre-flight check before dispatching subagents with worktree isolation to avoid file-scope overlap, stale dispatch bases, and collisions with other live agents editing shared paths.
Ships in collaboration-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.
Claude Code's own isolation primitives are the Subagents feature ("each subagent runs in its own context window with a custom system prompt, specific tool access, and independent permissions") and isolation:"worktree"'s base-branch selection. Neither one checks whether a NEW dispatch's file scope overlaps an in-flight one, or whether the worktree base is stale — that pre-flight discipline is what this skill adds on top.
references/official-docs.md.Before dispatching a new subagent via the Agent tool — especially with isolation: "worktree" — if ANY other subagent is currently running or has an active worktree.
Trigger phrases / situations:
Agent tool when git worktree list shows non-main worktrees[in_progress] tasks in TaskList that involve subagent workSkip when: dispatching the first subagent in a session, or all prior subagents have completed AND their worktrees are cleaned/merged.
git worktree list --porcelain | grep '^worktree ' | cut -d' ' -f2- | tail -n +2
Plain git worktree list is fine for a human to eyeball, but don't parse it: filtering
on [main] breaks when the default branch isn't named main, and splitting on
whitespace breaks on a path containing a space — cut -d' ' -f2- keeps everything after
the first space instead of splitting on every space, so it doesn't have that problem.
--porcelain sidesteps the [main]-name issue — tail -n +2 drops the first
(main-checkout) worktree line. For each remaining worktree path,
capture:
(cd <path> && git status --short)(cd <path> && git log -1 --format=%s)Expect one permission prompt per worktree for these two checks, whichever form you write
them in. Per the permissions docs, a Bash
rule "must match each subcommand independently"; git -C <path> status is a different
invocation form that Bash(git status *) doesn't match; and cd combined with git
"prompts when the cd changes into a different directory, since running git in a new
directory can execute that directory's hooks". So this skill's allowed-tools covers the
Step-1 listing (Bash(git worktree *)) but not the per-worktree checks — the prompt is
expected; approve it.
Read the planned subagent's task prompt. Extract:
## Task scope and ## Inputs sections — see leader-developer-handoff-contract)Sources/.../Settings/)For each in-flight subagent's dirty-file set vs the new dispatch's likely scope:
isolation: "worktree". Note in dispatch prompt: "in-flight subagent X is editing target Y; do not touch files Z."The intersection check above only reasons about file paths, but a booted Simulator is
just as exclusive a resource as a file: pre-assign a UDID per subagent in the dispatch prompt
rather than letting each agent boot/pick one implicitly. Some simctl settings are device-global,
not per-app — xcrun simctl ui <udid> appearance|content_size changes the whole device's state,
so agent A switching to dark mode or Dynamic Type contaminates agent B's screenshots if they
share a simulator (see apple-dev-skills:interactive-simulator-ux-audit for the driving pattern this protects).
isolation: "worktree" does not always branch from your current local HEAD — the base
depends on worktree.baseRef ("fresh" vs "head"), and a resumed agent can drift off its
starting branch. Before dispatching, confirm the base:
git rev-parse --abbrev-ref HEAD # on the branch you think you are?
git log --oneline -3 # does it include the commit/PR this work depends on?
git merge-base --is-ancestor <dep-sha> HEAD && echo "base OK" || echo "STALE BASE"
For the baseRef decision table, the sync-before-dispatch recovery recipe, the real incident
that motivated this check, and the two resumed-agent traps (stale pwd/branch, ghost index
entries), see references/worktree-base-and-recovery.md.
When ANOTHER Claude session (or human) is actively editing the same working checkout — or a git submodule vendored into your repo (e.g. a shared .claude/skills/<plugin> submodule) — do NOT edit that shared checkout in place. Two writers on one working tree clobber each other's uncommitted edits, fight over branch HEAD, and produce confusing diffs.
Instead, collaborate through isolation + PR:
origin/main (not the shared checkout's possibly-dirty local state):
git -C <shared-repo-or-submodule-path> fetch origin && git -C <…> worktree add /tmp/<name> -b <branch> origin/mainThis is the cross-session mirror of the within-session conflict check: same goal (no two writers on one tree), different scope (independent sessions / submodules rather than your own in-flight subagents). When unsure whether another agent is on a path, treat it as occupied and use the worktree+PR path — it's cheap insurance.
When overlap detected, present to user:
⚠️ Conflict detected between new dispatch and in-flight subagent:
In-flight: <subagent-id> editing:
- <file 1>
- <file 2>
New dispatch would touch:
- <file 1> ← OVERLAP
- <file 3>
Options:
1. Serialize — wait for in-flight to merge, then dispatch
2. Carve — rewrite new dispatch prompt to exclude overlapping files
3. Proceed anyway — risk: subagent commits compete on push
--force-with-lease does NOT silently overwrite — it rejects the push when the remote ref has moved since the client last fetched. The real footgun is a different one: worktree B rebases onto a stale base (e.g. the main SHA from before worktree A pushed), producing a divergent history; resolving it then requires a force-push that can drop worktree A's commits. Prevent this by serializing or carving scopes before dispatch.If your Leader runs a pre-dispatch pre-flight (process cleanup, rebase onto main, tool trust), insert this conflict-detection step before it. For why mise trust is required before mise install/mise exec take effect in a fresh worktree or CI checkout, see apple-dev-skills:mise-tool-management.
If git worktree list shows stale entries (worktree dir gone but git registration alive), they are NOT a conflict source — they just need git worktree prune. Don't block dispatch on stale registrations; check ls <worktree-path> to confirm the directory actually exists before computing dirty-file intersection.
Leader is about to dispatch: "Developer for error funnel refactor — files: Sources/App/Composition/Live.swift, Sources/App/Root/RootViewModel.swift, Tests/RootViewModelTests.swift"
`git worktree list` shows in-flight subagent `agent-abc123` editing:
M Sources/App/Components/BannerController.swift
Intersection: Module overlap (same `Sources/App/`, different files) → WARN.
Verdict: dispatch with `isolation: "worktree"`. Note in prompt: "in-flight subagent on BannerController.swift — do not touch that file; module Sources/App/ is shared."
github-contribution-workflow — routes worktree/submodule collision questions here; that skill owns PR/branch mechanics, this one owns pre-dispatch and cross-session conflict checks.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
12 skills in this plugin
/agent-impl-notes-logKeep a running impl-notes file next to the phase meeting log while a subagent executes a task, recording design decisions, intentional deviations from spec, tradeoffs, and open questions as they happen rather than after the fact. Use at the start of any non-trivial subagent dispatch (multi-file change, ambiguous spec, new dependency or module, refactor), when ambiguity is hit mid-task, or before deviating from spec. Not the post-hoc meeting log (session-to-meeting-log); the two coexist./backlog-routing-by-topicRoute a stray idea that surfaces mid-task to the §Backlog of the right living doc in a spec-phase-orchestration repo (design.md, foundations.md, plan.md, methodology.md, or today's meeting log) as a single line, without derailing the current work. Use when a not-now-but-don't-forget idea comes up, when tidying a meeting log's parking-lot items, or when asked where an idea should go. Not for decisions that must be acted on now (those belong in the body of plan.md)./claude-skill-plugin-packagingPackage Claude Code skills as a plugin plus marketplace and install them into other repos — globally, pinned per project via committed settings, or as a skills-dir plugin. Use when sharing skills across repos, wiring an existing skill plugin into a project, choosing flat project skills versus a plugin, aggregating other people's skill repos by reference, or when a submodule or nested folder of skills is not being discovered. Does not cover PR/issue mechanics (github-contribution-workflow) or how to write the skill itself (skill-authoring-patterns)./github-contribution-workflowDrive GitHub contributions through the gh CLI — pull requests, issues, GitHub-side file edits, repo secrets, contribution-flow repo settings, submodule pin bumps. Use when about to run `gh pr create` / `gh pr merge` / `gh pr checks` / `gh issue create` / `gh secret set` / `gh api`, or asked "open a PR", "merge this", "bump the submodule". Does NOT cover pure local git, diff-vs-commit sanity (pr-diff-verification), security repo settings (apple-dev-skills:apple-public-repo-security), worktree conflicts (subagent-conflict-detection), plugin distribution (claude-skill-plugin-packaging)./leader-developer-handoff-contractShape the prompt a Leader sends when dispatching a sub-agent (Developer, Designer, Code Reviewer, drafting agent) so the result comes back verifiable and integrable. Use when about to call the Agent tool, writing or reviewing a dispatch prompt, deciding what a sub-agent must read or which skills it must invoke, or when asked "what should the sub-agent prompt include" / "which element am I missing". Does NOT own how many review rounds to run or how findings are adjudicated (subagent-review-cycles), nor the impl-notes file format (agent-impl-notes-log)./methodology-pattern-extractorExtract recurring collaboration patterns from accumulated meeting logs (optionally session JSONL) and record them in docs/methodology.md with evidence of where each was sighted. Use when the user asks to update methodology, extract recurring patterns across the meeting logs, or consolidate recurring collaboration flows; or when five or more meeting logs have accumulated while §Patterns is still empty. Not for writing the meeting logs themselves (session-to-meeting-log) or for parking one-off ideas (backlog-routing-by-topic). Takes no arguments — the fork scans all of `meetings/*.md`.npx claudepluginhub wei18/apple-dev-skills --plugin collaboration-skillsOther plugins' skills for the same job