← ClaudeAtlas

concurrent-session-checkout-clobbers-shared-worktreelisted

A second Claude Code session (or agent/person) sharing the same working directory runs `git checkout`/`git switch`, flipping the branch for the whole working tree underneath your session and clobbering your uncommitted work. Use when: (1) a file you just edited has silently reverted — often with a "file was modified, either by the user or by a linter" system reminder, (2) `git branch --show-current` shows a branch you didn't switch to, (3) `git reflog` shows a `checkout: moving from X to Y` you never ran, (4) unfamiliar files/changes appear in `git status`. Covers detecting the collision and recovering via an isolated git worktree.
wan-huiyan/agent-traffic-control · ★ 2 · Code & Development · score 79
Install: claude install-skill wan-huiyan/agent-traffic-control
# Concurrent session's `git checkout` clobbers your shared working directory ## Problem Two Claude Code sessions (or any two agents/people) operate in the **same** working directory on the same clone. `git checkout` / `git switch` changes `HEAD` for the *entire working tree* — it is not per-session. When session B switches branches, session A's tree changes underneath it: - Uncommitted edits to tracked files may be carried across, reverted, or left in a confusing half-state. - Untracked files (new files you created) stay on disk but risk being swept into session B's next `git add -A`. - Edits get silently lost — e.g. a config field you added disappears. It is invisible until something breaks: a function you wrote is "gone", a test errors on a symbol you defined, or a harness emits *"file was modified, either by the user or by a linter"* for a file you didn't expect to change. ## Context / Trigger Conditions - A file you edited reverted to an older version with no action from you. - `git branch --show-current` is not the branch you were working on. - `git status` lists changes or untracked files you don't recognize. - **Decisive:** `git reflog` shows `checkout: moving from <yours> to <other>` that you never performed. ## Solution Do **not** keep fighting inside the shared directory — you will collide again. Isolate into a git worktree. 1. **Confirm the collision** — `git reflog -5` reveals the foreign checkout. `git log <your-branch> --oneline` confirms your