Skip to content

Commit e923f51

Browse files
cliffhallclaude
andcommitted
docs: always start PR work in a new git worktree
AGENTS.md's "When work begins" rule now creates the feature branch in a new git worktree rather than by switching branches in the primary checkout, which concurrent agent sessions share, and removes it once the PR merges or closes. pr-flow step 2 carries the recipe (a sibling worktree, --no-track, the npm install inline, stacked branches cut from the parent) and step 10 the removal. Mirrors modelcontextprotocol/inspector#2663. Closes #5138 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: cliffhall <cliff@futurescale.com>
1 parent 6d613ec commit e923f51

2 files changed

Lines changed: 52 additions & 7 deletions

File tree

‎.claude/skills/pr-flow/SKILL.md‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,40 @@ gh issue edit <N> --repo modelcontextprotocol/servers --add-assignee @me
3939

4040
## 2. Branch
4141

42-
`v2/<type>/<N>-<slug>`, cut from **`origin/v2/main`**:
42+
`v2/<type>/<N>-<slug>`, cut from **`origin/v2/main`** into a **new git
43+
worktree**, never by switching branches in the primary checkout. Several agent
44+
sessions work this repo on one machine at once and share the primary checkout:
45+
a `git switch` there moves the branch out from under every other session using
46+
it, and carries one task's uncommitted edits, `dist/` output and
47+
`node_modules` into another's. A worktree per issue gives each task its own
48+
tree and leaves the primary checkout alone.
49+
50+
Run it from the primary checkout. The worktree is a **sibling** directory named
51+
for the checkout plus the issue number (`servers` → `../servers-4810`), never a
52+
directory inside the repo, where every format, lint and typecheck scope would
53+
see a second copy of the source:
4354

4455
```sh
4556
git fetch origin v2/main
46-
git switch -c v2/fix/4810-filesystem-symlink-escape origin/v2/main
57+
git worktree add --no-track "../$(basename "$PWD")-4810" \
58+
-b v2/fix/4810-filesystem-symlink-escape origin/v2/main
59+
cd "../$(basename "$PWD")-4810"
60+
npm install
4761
```
4862

63+
- `--no-track` keeps the new branch from tracking `origin/v2/main`, so
64+
`git status` does not report your work as "ahead of v2/main", and the first
65+
push is an explicit `git push -u origin <branch>` to a branch of its own name.
66+
- ⚠️ **The `npm install` is part of the step.** A worktree starts with no
67+
`node_modules`, no `dist/` and no `.venv` (`/local-dev`). The root install
68+
builds every TypeScript server; a Python server builds its `.venv` on its
69+
first `uv run`. Background the install if you have edits to make first; the
70+
gate needs it finished.
71+
- Every later step (edits, the gate, commits, the push) runs **inside the
72+
worktree**.
73+
- The harness's `EnterWorktree` tool, where available, does the same; name the
74+
branch by the rule above.
75+
4976
`<type>` follows the issue's type label: `bug` → `fix`, `enhancement` → `feat`,
5077
`documentation` → `docs`, `chore` → `chore`. A `question` has no branch type,
5178
because answering one ships nothing: if it turns out to need a change, relabel
@@ -56,10 +83,11 @@ branch and keeps the work legible in `git branch -a` next to `main`.
5683
history, so the PR diff would show unrelated changes.
5784

5885
**Stacking.** When one issue's work depends on another PR that has not merged
59-
yet, branch from that PR's branch and open the PR with `--base` set to it. Say
60-
in the body that it is stacked and on which PR. When the lower PR merges,
61-
retarget the stacked one to `v2/main` (`gh pr edit <PR> --base v2/main`) and
62-
rebase it if GitHub reports conflicts.
86+
yet, branch from that PR's branch (its worktree is cut from it:
87+
`git worktree add … -b <child> <parent-branch>`) and open the PR with `--base`
88+
set to it. Say in the body that it is stacked and on which PR. When the lower
89+
PR merges, retarget the stacked one to `v2/main`
90+
(`gh pr edit <PR> --base v2/main`) and rebase it if GitHub reports conflicts.
6391

6492
## 3. Sign off every commit (DCO)
6593

@@ -391,3 +419,16 @@ issue will not be done, the issue shipped nothing: close it as not planned and
391419
**delete its card** (`/board-ops`) rather than moving it to Done.
392420
393421
If PRs were stacked on this one, retarget each to `v2/main` (step 2).
422+
423+
**Then remove the worktree and its local branch**, from the primary checkout,
424+
once the PR shows as merged (or closed, for abandoned work). A stale worktree
425+
keeps its branch checked out, so git refuses to check that branch out anywhere
426+
else, and it holds a full `node_modules` on disk per issue:
427+
428+
```sh
429+
git worktree remove "../$(basename "$PWD")-<N>"
430+
git branch -D v2/fix/<N>-<slug>
431+
```
432+
433+
`git worktree remove` refuses a worktree with uncommitted or untracked changes;
434+
read what is there before reaching for `--force`.

‎AGENTS.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,11 @@ here.
491491
- **When work begins**, assign the issue to yourself, set Status to
492492
**In Progress**, and create a branch named
493493
`v2/<type>/<ISSUE_NUMBER>-<slug>` (for example
494-
`v2/fix/4810-filesystem-symlink-escape`) from `origin/v2/main`.
494+
`v2/fix/4810-filesystem-symlink-escape`) from `origin/v2/main`, **in a new
495+
git worktree**: never by switching branches in the primary checkout, which
496+
concurrent agent sessions share. Remove the worktree once the PR merges or
497+
is closed. The recipe is the `pr-flow` skill (step 2, and step 10 for the
498+
removal).
495499
- **When work is complete**, run the checks under
496500
[Before pushing](#before-pushing), open a PR against `v2/main` labeled `v2`
497501
with `Closes #<ISSUE_NUMBER>` as the body's first line, and set Status to

0 commit comments

Comments
 (0)