| name | worktree-git-discipline |
| description | Use before any git commit/stash/history operation in a repo that multiple Claude sessions may share — never rewrite another session's HEAD, never pop a shared stash. Prevents cross-session commit corruption. |
| origin | SkyyRose |
Worktree Git Discipline
One git worktree is one HEAD, but this repo routinely has more than one Claude
session pointed at the same worktree — a Ralph loop and a foreground session both
committing to the same branch is normal, not an edge case. History rewrites assume
the last commit is yours. It might not be. git commit --amend in a shared worktree
rewrites whichever commit HEAD currently points to — if another session landed
one while you were composing your edit, --amend silently folds your staged file
into their commit. The symptom is subtle: no error, just someone else's diff
gaining content they never wrote. reset and rebase carry the same risk in the
other direction — they can discard a commit another session is mid-way through
building on.
Boot first: read CLAUDE.md's Shared-worktree git discipline critical
rule → run git worktree list to see every checkout attached to this repo →
run git log -1 to see whose commit HEAD is right now. Do not commit against
your memory of where HEAD was a few tool calls ago — it moves without you.
When to Use
- Immediately before any
git commit in a worktree you did not create exclusively
for this task (i.e. not a fresh EnterWorktree).
- Before any — the stash ref () lives in the
common dir, not per-worktree; a bare can pop a different
session's WIP.