concurrent-session-checkout-clobbers-shared-worktreelisted
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