Skip to content

Commit c813e7a

Browse files
docs(agents): harden the worktree recipe with --no-track, and name .git/config in the shared-namespace inventory (#13403)
The prescribed 'git worktree add -b <branch> origin/main' writes the new branch's upstream config (branch.NAME.remote / branch.NAME.merge) into the one .git/config every linked worktree shares, and that write can fail AFTER the branch is created -- leaving a branch with no worktree, a state the recipe never mentions. --no-track skips the config write entirely and still bases the worktree on origin/main; nothing in the agent flow needs the upstream, because 'git push -u origin <branch>' sets one a command later. Line-neutral in both files (AGENTS.md 1162/1162, CLAUDE.md 86/86). Claude-Session: https://claude.ai/code/session_01EXxTW8mvPBhoHxmyPZ63de Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 94efa2a commit c813e7a

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ localStorage / auth gotchas.
232232
11. **Worktree-first — never edit on the shared `main` checkout.** This repo is edited by **multiple agents at once**;
233233
the shared tree has its HEAD switched and reset *under you*, silently clobbering uncommitted work — a feature
234234
branch on the *shared* checkout is **not** enough (it still gets switched under you). Before your **first file
235-
edit**, be in a dedicated worktree on a feature branch: `git fetch origin main &&
236-
git worktree add ../objectstack-<task> -b <branch> origin/main && cd ../objectstack-<task> && pnpm install`. Two
235+
edit**, be in a dedicated worktree on a feature branch: `git fetch origin main && git worktree add --no-track
236+
../objectstack-<task> -b <branch> origin/main && cd ../objectstack-<task> && pnpm install`. Two
237237
PreToolUse hooks **enforce** this — `.claude/hooks/guard-main-checkout.sh` blocks `Edit`/`Write`/`NotebookEdit`,
238238
and `.claude/hooks/guard-main-checkout-bash.sh` blocks the identical write arriving through **Bash** (`>`/`>>`
239239
redirection, `sed -i`, `perl -i`, `tee`, `cp`, `mv`, `rm`, `touch`) — and both check the **target file's own
@@ -394,7 +394,7 @@ git worktree add ../objectstack-<task>-cmp <ref> # a second tree to compa
394394

395395
**⛔ The stash is one CASE — a worktree isolates your checkout and exactly four ref
396396
namespaces (`HEAD`, `refs/bisect`, `refs/worktree`, `refs/rewritten`) and NOTHING else:**
397-
not the object store, not the config, not any other ref, so "worktrees isolate refs,
397+
not the object store, not `.git/config`, not any other ref, so "worktrees isolate refs,
398398
except stash" is exactly backwards. **`refs/remotes/*` is shared** — a sibling's fetch
399399
advances **your** `origin/main` (measured next door: three moves in ten minutes), so
400400
`git checkout origin/main -- <paths>` restores wherever that ref points **now**, possibly

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ shared checkout is NOT enough** — it still gets switched under you. You MUST b
2929
**dedicated per-task worktree**:
3030

3131
```
32-
git fetch origin main && git worktree add ../<repo>-<task> -b <branch> origin/main && cd ../<repo>-<task> && pnpm install
32+
git fetch origin main && git worktree add --no-track ../<repo>-<task> -b <branch> origin/main && cd ../<repo>-<task> && pnpm install
3333
```
3434

3535
Then make all edits there. This applies **per repo**: if a task spans `framework` and

0 commit comments

Comments
 (0)