← ClaudeAtlas

dev-repo-worktreeslisted

Per-session git worktree pattern for ~/dev/<repo> code repos. Prevents the CONCURRENT-SESSION-HEAD-DRIFT bug class where two Claude Code sessions writing to the same physical checkout collide on the single .git/HEAD pointer + index + working tree. Ships a wrapper script + hookify warn rule + the rule prose. Complements dev-repo-checkpoints (recovery) by preventing the failure at the structural layer (isolation).
adelaidasofia/ai-brain-starter · ★ 18 · AI & Automation · score 81
Install: claude install-skill adelaidasofia/ai-brain-starter
# Dev-Repo Worktrees Per-session git worktree pattern for `~/dev/<repo>/` code repos that prevents concurrent Claude Code sessions from colliding on the shared `.git/HEAD`. ## Why this exists **The failure mode (CONCURRENT-SESSION-HEAD-DRIFT):** Two Claude Code sessions both editing code in `~/dev/<repo>/` share one physical checkout, which means one `.git/HEAD` + one index + one working tree. When session A checks out their feature branch, session B's next `git commit` lands on session A's branch by accident. Recovery requires branch-label manipulation + `git stash` dances + branch-switch-safety hook overrides. Observed multiple times in long-running multi-session workflows. **The cause:** Bash `cd` is per-command, not per-session. Every invocation re-cds; HEAD-state from prior commands is whatever the last command left it. Bash sessions cannot share filesystem state with other Bash sessions — but git operations on the same checkout absolutely DO share state, and the model can't observe that. **The fix:** every Claude Code session that writes code in `~/dev/<repo>/` works in its own per-session git worktree at `~/dev/<repo>-<slug>/`. Each worktree has its own HEAD + own index + own working tree, while sharing the underlying object store. Zero collision possible. ``` ~/dev/<repo>/ NEVER write here in a session ~/dev/<repo>-<slug>/ YES — session checkout, isolated HEAD ``` The main checkout stays as the maintenance + reference path —