standards/CLAUDE.md: pin the main checkout to origin/main; all branch access in per-agent worktrees (+ cleanup)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 0
- Forks
- 1
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 7
Description
Problem
Agents that only read the shared standards/CLAUDE.md are not creating worktrees — the shared standards say nothing about worktrees at all. Worktree usage exists only as a default inside the start-work skill (plugins/start-work/), behind an easy --no-worktree opt-out. Any agent that doesn't run /start-work gets no directive.
But the deeper need is workspace isolation for many concurrent agents — up to 6–7 running at once. The real hazard isn't just parallel writes; it's that if one agent checks out a branch in the shared main checkout — even just to read or analyze it — it yanks the ground out from under every other agent using that checkout. Each agent needs its own private workspace, even for reads.
The model (decided)
Anchor rule: the main checkout is permanently pinned to origin/main. Any branch other than main — for any reason, read or write — lives in that agent's own worktree.
- Main checkout stays on
origin/main. It's the shared landing pad every new agent starts from. Nothing evergit checkouts another branch there. - Reading another branch's files →
git show <branch>:<path>orgit grep <rev> -- <path>. These never touch a working tree, so they're safe under concurrency and need no worktree. Use them freely for peeks. - Materializing a branch on disk (building, running, editing, or grepping across the whole tree) → the agent's own worktree at
.claude/worktrees/<id>-<slug>/. Nevergit checkout <branch>in the main checkout to do this. - Keep main current. Because nothing is ever worked on in the main checkout, it is always safe to fast-forward it to
origin/mainat any time, so new agents start from the latest code. - Agents clean up their own worktrees when done — from outside the worktree (you can't remove the one you're standing in — see #168). A worktree created just to read/review a branch is disposable and torn down when the analysis finishes; a worktree for active work persists until its PR merges, then is removed.
- Bulk cleanup of abandoned worktrees — a cautious, semi-regular sweep — is handled by a separate skill, tracked in #196. This issue only requires that the standard mention such a sweep exists; the mechanics and safety gates live in #196.
Enforcement level (decided)
Standards directive — instruction-level rule in standards/CLAUDE.md, reaching every agent via the shared-standards sync. No hook-based hard block for now (possible follow-up if the directive proves insufficient).
Opt-out policy (decided)
Per-repo opt-out file, mirroring .allow-push-main. A repo carrying .allow-in-place in its root disables the worktree discipline for that repo — work proceeds in the main checkout. Intended for repos where worktrees genuinely break local tooling and concurrent-agent isolation isn't needed:
- #134 — a dev whose git GUI (GitKraken) chokes on worktrees nested under
.claude/worktrees/and who can't view uncommitted WIP across worktrees. A repo-level marker lets that person disable the default for their repos without weakening it for the multi-agent case.
Opt-out is per repo (owner's call), not per-invocation — the point is to stop casual per-task --no-worktree bypassing while honoring repos with a real incompatibility. (Marker name open: .allow-in-place vs .no-worktree vs .allow-main-checkout — pick one, use it consistently.)
Proposed content (for standards/CLAUDE.md)
New section, adjacent to Git Hygiene Before New Work / Branch Naming and PR Linking:
Worktrees and the Main Checkout
The main checkout stays permanently on
origin/main. It is the shared landing pad every new
agent starts from — no branch is ever checked out there. With several agents running at once,
switching the main checkout onto a branch pulls the ground out from under every other agent
reading it, so the rule is absolute: any branch other thanmain, for any reason, lives in
that agent's own worktree.
- Reading another branch's files: use
git show <branch>:<path>orgit grep <rev> -- <path>.
These never touch a working tree, so they're safe under concurrency and need no worktree.- Materializing a branch on disk (building, running, editing, or grepping the whole tree):
create your own worktree at.claude/worktrees/<id>-<slug>/(thestart-workskill does this
automatically). Nevergit checkout <branch>in the main checkout to do it.- Keeping main current: because nothing is ever worked on in the main checkout, it is always
safe to fast-forward it toorigin/main(git -C <main> fetch origin main && git -C <main> merge --ff-only origin/main) so new agents start from the latest code.- Clean up your own worktree when done — from outside it (you can't remove the worktree you're
standing in; see #168). A worktree spun up just to read or review a branch is disposable — tear it
down when the analysis finishes. A worktree for active work persists until its PR merges, then is
removed.- Per-repo opt-out: a repo carrying
.allow-in-placein its root disables this — work proceeds
in the main checkout. Use only where worktrees break local tooling (e.g. a git GUI that can't walk
a nested worktree's.gitpointer) and concurrent-agent isolation isn't needed.Left unmanaged,
.claude/worktrees/accumulates abandoned trees; a periodic bulk sweep
(/worktree-cleanup) reclaims them cautiously — see that skill for the safety rules.
Scope / where things live
- Discipline (rules 1–5) →
standards/CLAUDE.mddirective (this issue). - Self-cleanup (rule 5) → directive; could also be wired into
start-work/ a small teardown helper. - Bulk cautious sweep (rule 6) → separate skill, tracked in #196.
start-work.shhonoring.allow-in-place→ small follow-up so the script matches the standard (behave as--no-worktreewhen the marker is present).
Acceptance criteria
-
standards/CLAUDE.mdgains a Worktrees and the Main Checkout section stating: the main checkout stays onorigin/main; never check out another branch there;git show/git grepfor cross-branch reads; own worktree for materialized branches; fast-forward main to stay current; clean up your own worktree from outside it. - Documents the per-repo opt-out file and when it's appropriate.
- Mentions the bulk sweep exists and points to
/worktree-cleanup(#196) for its rules — without duplicating the safety gates here. - Opt-out marker name finalized and used consistently.
- Wording is strong enough that an agent reading only the shared standards keeps the main checkout on
mainand uses a worktree for any other branch by default. - Cross-references worktree-removal guidance (#168) rather than duplicating it.
- Reachable on the next
setup-envsync (no code path changes required for the directive itself).
Open questions
- Opt-out marker name (
.allow-in-placevs.no-worktreevs.allow-main-checkout). - Relationship to #134 — does the per-repo marker fully satisfy it, or keep #134 open for a per-developer setting?
- Should
start-work.shhonor the marker in this issue, or as a small separate follow-up?
Related
- #196 —
/worktree-cleanupskill (the cautious bulk sweep this discipline relies on). - #168 — worktree removal mechanics (can't remove the CWD; Windows CWD-lock; removal order).
- #134 — request for a per-user
--no-worktreedefault; addressed at the repo level here.
Out of scope
- Hook-based hard enforcement (pre-commit / PreToolUse block) — possible follow-up.
- Bulk-sweep mechanics — tracked in #196.
- Worktree removal mechanics — tracked in #168.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with standards/CLAUDE.md and compare its adjacent Git Hygiene and Branch Naming sections with the acceptance criteria. Review #168 and #196 for the removal and cleanup references, then settle on one opt-out marker name and document the main-checkout, branch-reading, worktree, cleanup, and sync rules. Done means the section is reachable through setup-env and covers every listed criterion without implementing out-of-scope mechanics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git
- Domain
- developer-experience, documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100