parallel-sessions-protocol
Skill1 starsChanged 4 months agoApache-2.0View on GitHub
Coordinate any number of AI or human dev sessions working the same git repository in parallel — start-of-work registration (a draft PR is the shared board, with claim declarations), resource claiming (sequential numbers, file ownership), ledger-writes-only-at-merge-time, merge discipline (local merge preview, exclusive working directories, no `git add -A`), end-of-work registration (push-or-declare WIP, worktree cleanup, triggered write-backs), and a three-checkpoint awareness refresh. Use when multiple sessions / agents / worktrees develop one repo at the same time; when the user says 多会话并行, 并行轨道, 开工登记, 收工登记, 公告板, 会话撞车, 多个会话同时开发, coordinate parallel sessions, multiple Claude sessions on one repo, sessions keep colliding, track claims; when sequential resources (migration or decision numbers) or shared changelog/ledger docs keep colliding between branches; or when a session needs to know what other sessions are doing before acting. When peer tracks come from clones on other machines, or the work releases to a deployment target that peer machines also mutate, also invoke a cross-machine shared-repo coordination skill such as 365-cross-computer-shared-repo if installed (this skill still owns the on-machine surface). NOT for release/QA pipeline coordination through a dedicated controller lane, not for plain merge-conflict fixing, not for in-session subagent orchestration, not for CI test parallelism.
In this repository11 other files it gives its agents.
- 365-chatgpt-pro-deliverySkill
- 365-five-step-dev-claudeSkill
- 365-five-step-dev-codexSkill
- 365-five-step-retro-claudeSkill
- 365-session-rotation-maintainerSkill
- discover-project-skillsSkill
- gws-weekly-digestSkill
- gws-workspaceSkill
- project-health-checkSkill
- shopify-store-launch-baselineSkill
- shopify-theme-deliverySkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 8 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 8
Keep any number of parallel sessions on one repository from trampling each other, without capping how many run.
- Distinctive: line 38
Before writing any code:
- Distinctive: line 50
When the track ends (merged or abandoned), the PR closes and the board self-cleans.
- Distinctive: line 92
If one still happens (another merge landed between your rebase and your merge): the only correct resolution is keep both sides in full.
- Distinctive: line 105
Never park a worktree on the main branch — it blocks every other session's operations that need to check out main.
- Distinctive: line 107
Never
git add -A: when tracks run in parallel. - Very specific: line 110
After rebasing a pushed branch, push with --force-with-lease (plain push is rejected.
- Very specific: line 115
Run git fetch + gh pr list (~30 seconds) at:
- Distinctive: line 147
Worktree hygiene: Remove your worktree when done.
- Distinctive: line 150
Refresh the board: Update the draft PR's "Current status" line.
- Very specific: line 183
If the project has a chat webhook (Feishu / Slack / …), configure it as an environment variable (e.g.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Parallel Sessions Protocol
Keep any number of parallel sessions on one repository from trampling each other, without capping how many run. Field-proven under real load: one day of 7 simultaneous worktrees and 8 merged PRs produced six distinct collision incidents; every mechanism below exists because one of them happened. Posture: guarded-mutation — this skill creates branches and draft PRs; merging stays governed by each project's own authorization rules.
Preconditions: a git repository with a GitHub remote and an authenticated
gh CLI (references/setup-guide.md). If either is missing, say so and stop
— the board mechanism cannot work without them.
Core model: one track = one session + one branch + one exclusive working directory + one claim declaration. Sharing a working directory across sessions is the root cause of cross-track pollution — never do it. The number of tracks is unbounded; the constraint is behavior, not count.
Cross-machine routing: this protocol governs the conflict surface on ONE
machine's filesystem. If active tracks come from clones on OTHER machines
(the board shows PRs from peers you cannot git -C into), or this track will
release to a deployment target that peer machines also mutate, additionally
invoke a cross-machine shared-repository coordination skill if one is
installed (in this suite: 365-cross-computer-shared-repo, whose boundary
section classifies the target and decides whether release-lock rules apply).
The two skills are complementary and run at the same time; neither replaces
the other. Without such a skill, at minimum refresh origin/main explicitly
before integrating and verify a release candidate contains the currently
deployed version.
Mechanism 1 — Register before you code (the board)
Before writing any code:
git fetch originandgh pr list --state open— see the whole board first.- Branch from latest
origin/main; take an exclusive working directory (the main checkout counts as one — at most one session may own it at a time; every other session uses its own worktree). - Immediately open a draft PR whose body has three fixed sections
(template in
references/draft-pr-template.md):- Claimed scope — directories/files this track will touch
- Claimed numbers — sequential resources taken (migration/decision numbers…); write "none" if none
- Current status — one line, updated at milestones
- When the track ends (merged or abandoned), the PR closes and the board self-cleans. Abandoned tracks delete their branch and worktree.
The board is gh pr list.
Dispatching is where registration leaks — in field use, three of four recorded collisions came from spawned sessions (task chips, subagents, background tasks) that never registered. So a dispatch prompt MUST carry these three lines; a dispatch without them is the dispatcher's protocol violation, not the spawnee's:
- Register on the board before writing any code: open a draft PR with Claimed scope / Claimed numbers / Current status.
- Work in your own exclusive worktree — never the dispatcher's working directory and never the main checkout.
- Task grade: X | suggested model tier: Y | if your inherited tier is higher than Y, switch down before starting. (Grading is the dispatcher's job — the spawnee inherits a tier chosen for the parent task, not for this one.)
Mechanism 2 — Claim before you use
| Resource | Rule |
| Sequential numbers (migrations, decision entries, …) | Before taking a number: check the max on main and scan every open PR's "Claimed numbers" section. Take the smallest free one; write it into your draft PR. |
| Files / directories | Do not touch files inside another track's claimed scope. If you must: wait for its merge, or escalate to the human owner to sequence the work. |
| Collision anyway | The later merger yields (renumbers / rebases). The earlier merge never changes — renumbering merged history breaks every reference to it. |
Mechanism 3 — Ledger writes only at merge time
Shared ledger docs (a current-task / decisions / changelog style file that every track must eventually write) are where parallel tracks collide by construction. Structural fix:
- Never touch shared ledger files while the track is alive. Process notes go in the track's own files (briefs, reports) — zero conflict by construction.
- As the final step before merge: rebase onto latest main, then append your ledger entries (append-only files: add at the end; newest-first files: insert at the top), then request the merge immediately.
- Merges are serial, so ledger writes become serial too — conflicts go from guaranteed to rare.
- If one still happens (another merge landed between your rebase and your merge): the only correct resolution is keep both sides in full. Dropping either side erases another track's accounting. Never pick one.
Mechanism 4 — Merge discipline
- Merges are serial. Who may merge what is the project's rule (some projects let sessions self-merge docs-only PRs; check the project's AGENTS.md/CLAUDE.md) — this skill never overrides it.
- Always preview locally before merging:
git merge origin/main --no-commit --no-ffon your branch. GitHub's MERGEABLE flag lags behind the latest main and reports CLEAN on branches that conflict — verified in production. - Never park a worktree on the main branch — it blocks every other session's operations that need to check out main.
- Never
git add -Awhen tracks run in parallel; always add explicit paths. A blanket add sweeps other tracks' uncommitted files into your commit, and if their content happens to match main you will not even notice. - After rebasing a pushed branch, push with
--force-with-lease(plain push is rejected; plain--forcecan destroy a concurrent update).
Mechanism 5 — Refresh at three checkpoints (+ health glance)
Run git fetch + gh pr list (~30 seconds) at:
- Start of work — prevents claiming work another session already
started. Also glance at the client's live-session list when one is
available (e.g. a
list_sessionstool): a sibling working the same topic shows up there before its draft PR exists. Field lesson: a registered claim still got collided with, inside the gap between its registration and the collider's last board read — the board alone is not fresh enough at dispatch-heavy hours. - Before asking the owner anything, or reporting a major conclusion — prevents asking questions another session already resolved (this exact embarrassment happened: four questions asked from a stale worksheet that had been answered and merged hours earlier).
- Before merging — prevents merging on a stale base.
At start of work, also glance at CI: gh run list --limit 5. If main is red,
report it before starting anything new — a red cron once ran 45 consecutive
failures over four days because every session assumed someone else was
watching. The glance multiplies detection odds by the number of sessions; it
is still probabilistic, so recommend a dedicated automated watchdog for
guarantees (out of scope here).
Mechanism 6 — Register at end of work (teardown)
Mechanism 1 point 4 covers a track that ends (merged or abandoned). This mechanism covers the more common case: the session stops — done for now, paused, or interrupted — while the track lives on. Before ending or pausing:
- Push or declare. Push unmerged work to the track's own branch. If you cannot push, write a WIP declaration into the draft PR body: current state, and where the next session should pick up (one wip commit had to be rescued from an interrupted session by another track).
- Worktree hygiene. Remove your worktree when done; if you must leave it, log why in the PR body. Orphan worktrees accumulate silently (a routine audit found two in one repo) and later block merges.
- Refresh the board. Update the draft PR's "Current status" line.
- Write back triggered items. Any pending-verification / ledger entry whose trigger condition has already fired gets closed now, not "later" — one audit found five merged PRs whose log entries still said "awaiting merge".
Leftovers from interrupted sessions are inventoried and claimed by the next session entering the repo, via the board — never assume the original session will come back.
The human owner's interface
Unlimited tracks does not mean unlimited throughput. Two serial bottlenecks survive any protocol: the production write path, and the owner's review/decision bandwidth. The board makes the queue visible — "ready, awaiting merge" and "waiting for an answer" items are countable — so the owner throttles intake deliberately instead of being surprised. Per-track safety gates (requirement confirmation, production-write authorization, evidence-based acceptance) stay intact regardless of parallelism.
Failure modes this protocol was built from
| Real incident (one day, one repo) | Killed by |
| Two tracks claimed the same decision number — twice | Mechanism 2 |
| Shared ledger files edited by four tracks → merge conflicts | Mechanism 3 |
git add -A swept another track's four uncommitted files into a commit | Mechanism 4 |
| Owner asked four questions another session had already resolved | Mechanism 5 ② |
| A track started work another session didn't know about | Mechanism 1 |
| CI red for 45 consecutive runs, unnoticed by anyone | Mechanism 5 glance |
Optional: notification channel
If the project has a chat webhook (Feishu / Slack / …), configure it as an
environment variable (e.g. NOTIFY_WEBHOOK_URL in a gitignored env file —
never commit it, never hardcode it in a skill or repo). Use it for merge
announcements and CI alerts to humans. It is not an inter-session
channel — sessions coordinate through the board, not through chat.
Safety gates
- Opening draft PRs and branches: allowed freely (that is the registration).
- Merging: strictly per the project's own authorization rules; when in doubt, ask the owner. Never treat this skill as merge authorization.
- Deleting another session's worktree/branch: only after verifying it is
clean (
git -C <path> status --porcelainempty) and either messaging that session or getting the owner's go-ahead. - Force-push: only
--force-with-lease, only on your own track's branch.
References
references/draft-pr-template.md— the three-section board template, with filled examplesreferences/protocol-rationale.md— design principles (structural beats disciplinary; zero new systems) and the full incident backgroundreferences/setup-guide.md—ghCLI setup from zero, worktree basics, and the traps (MERGEABLE lag, checked-out-branch merge failures, force-with-lease)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

