/agent-traffic-control:git-stash-pop-pulls-unrelated-stashfrom agent-traffic-control
Diagnose and avoid `git stash pop` pulling in a stale stash from a different branch when the preceding `git stash` was a no-op. Use when: (1) `git stash` reports "No local changes to save" but you `git stash pop` anyway as a reflex; (2) `git stash pop` surfaces files you don't recognize, often with "both modified" merge conflicts in files unrelated to your current work; (3) `git status` after a stash pop shows changes in files from other features / other branches; (4) `git stash list` reveals stash entries from sibling worktrees or older branches. The stash stack is GLOBAL across branches and worktrees — it's LIFO and branch-agnostic. Pairing `git stash` / `git stash pop` defensively (e.g., before `git checkout -- file`) only works when the initial stash actually saved something; otherwise the pop reaches deeper into history. Save under user-wide skills.
Ships in agent-traffic-control. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
git stash pop pulls an unrelated stash when preceding git stash was a no-opYou defensively wrap a risky operation with git stash / ... / git stash pop
to preserve in-progress work. The working tree is clean, so git stash prints
"No local changes to save" and exits 0. Later, git stash pop pulls in
modifications from a different branch's stash entry — sometimes months old,
sometimes from another worktree, often producing merge conflicts in files you
never touched in this session.
You'll see one or more of:
git stash immediately echoed "No local changes to save"git stash pop runs without error and announces something like
On branch <X>: WIP on <other-branch>: <sha> <commit-msg-from-elsewhere>git status afterward shows:
both modified: <path> for paths from unrelated featuresgit stash list shows entries like stash@{0}: WIP on feature/sca-polish: ...
that reference branches you're not onThe stash stack is a global, branch-agnostic, LIFO data structure, shared
across every worktree of the repo. git stash pop always pops stash@{0} —
it doesn't care which branch the stash was created on. When git stash is a
no-op (clean tree), nothing is pushed onto the stack, so a subsequent
git stash pop reaches whatever was on top before this session — potentially
unrelated work from another branch, sometimes from months ago.
git stash / git stash pop reflexively. Check the output
of git stash first:
git stash push -m "session-N defensive snapshot" 2>&1 | tee /tmp/stash-msg
grep -q "Saved working directory" /tmp/stash-msg && DID_STASH=1 || DID_STASH=0
# ... do risky thing ...
[ "$DID_STASH" = "1" ] && git stash pop
-m with git stash push so your stash entries are
identifiable in git stash list.git stash list | head -5 # show top of stack
git stash show -p stash@{0} # full diff
git stash, commit
to a throwaway branch:
git checkout -b /tmp/snapshot-$$
git add -A && git commit -m "snapshot"
git checkout -
# later: git cherry-pick /tmp/snapshot-$$ ; git branch -D /tmp/snapshot-$$
If you've already popped an unrelated stash:
git status -s
git reset HEAD
git checkout -- <file1> <file2> ...
For unmerged paths, the same git checkout -- <file> works after git reset.git status -s # should be empty
git stash list # confirm the stale stash is still there if you need it
git stash drop stash@{0}
After preventive measures:
git stash should either successfully save (print
Saved working directory and index state ...) or print "No local changes to
save" — your conditional pop respects which case occurred.After recovery:
git status -s returns emptygit log --oneline -5 shows no unexpected new commitsThis session ran into the bug while verifying a base-branch behavior:
$ git stash # working tree was already clean
No local changes to save
$ git checkout origin/release-uk -- tests/test_app_flow.py
$ pytest tests/test_app_flow.py -q
$ git checkout HEAD -- tests/test_app_flow.py
$ git stash pop # ← reached into unrelated history
On branch feat/report-bundler
Changes to be committed:
modified: deliverables/future_roadmap.html
Unmerged paths:
both modified: docs/plans/future_sessions_plan.md
both modified: tests/test_ci_core.py
both modified: webapp/ci_core.py
both modified: webapp/cloud_run_task.py
$ git stash list
stash@{0}: WIP on feature/sca-polish: 498faed feat: P2 Specification Curve ... # ← old, unrelated branch
Recovery:
$ git reset HEAD
$ git checkout -- deliverables/future_roadmap.html docs/plans/future_sessions_plan.md \
tests/test_ci_core.py webapp/ci_core.py webapp/cloud_run_task.py \
webapp/cloud_runner.py webapp/research_utils.py webapp/templates/sca_results.html
$ git status -s
# (clean)
git stash pop is partially destructive on conflicts — if you can't
cleanly resolve, prefer git stash drop stash@{0} to discard the pop and
recover from your last commit.git stash and git stash pop are not a matched
pair. They operate on a stack that exists outside the session.git stash list and clean up entries you're done with.git-recover-lost-branch (if a stash drop loses important
work), git-worktree (alternative to stash for inter-worktree state).git-stash(1) man page — "The latest stash you created is stored in refs/stash; older stashes are found in the reflog of this reference."What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-control118 skills in this plugin
/agent-refusal-with-evidence-beats-literal-complianceA dispatched agent that does exactly what you asked can ship a defect you would
have stopped yourself, because it can see something at the worksite that you
could not see when you wrote the brief. Use when: (1) you are writing a brief
that prescribes a specific fix, threshold, wording or value rather than the
outcome you want; (2) an agent reports that it did not do what you asked and
you are deciding whether that is insubordination or judgement; (3) an agent
asserts "this is fine" or "not needed" with no measurement behind it; (4) you
are reviewing overnight output and want to know which decisions were checked
and which were assumed. Two halves, and both are needed: give the agent
explicit permission to satisfy the INTENT of an instruction while refusing its
letter, and REQUIRE the evidence with the refusal — what it built or measured,
what that showed, what it did instead. Evidence is the whole difference between
a refusal you can bank and one you have to re-litigate. Four agents correctly
declined an instruction in a single run; one built the suggested fix, measured
that it turned a silent safe refusal into a permanently red pipeline, and
reverted it unpushed.
/auto-merge-rearms-while-agent-live-kill-then-disarm-verify