git stash Is Shared Across Worktrees. Two Parallel Agents Popped Each Other's Work
Book: Prompt Engineering Pocket Guide Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools Me: xgabriel.com | GitHub Two coding agents were working on one repository at the same time, each in its own git worktree, each on its own…
Two separate agents were working on the same Git repository, each in their own git worktree. They both performed the same steps: stashing a fix, running tests to confirm it failed without the fix, and then restoring the fix. Agent A popped its own stash, which mistakenly brought back Agent B's stash. Conversely, Agent B's pop brought back Agent A's fix.
After this, both worktrees contained each other's files, and the stash list was empty. This occurred because the git stash pop command took the newest stash from a shared list, without checking which worktree or branch created it. Git worktrees share everything except per-worktree files such as HEAD, index, and refs/stash. However, the manual specifies that stash and its reflog are shared across all worktrees.
Despite this, the design assumes the stash belongs to one owner who is aware of its contents. Two agents working in parallel create an exception to this assumption, as neither is aware of the other's presence and both consider stash@{0} as their own.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.