/agent-traffic-control:worktree-outer-ls-mistaken-for-main-statefrom agent-traffic-control
Prevent citing files as "on main" when they actually live only in a sibling worktree's working tree. Use when (1) you're working inside a worktree at `<repo>/.claude/worktrees/<X>/` and need to verify whether a file or feature is on `origin/main`, (2) you're tempted to run `ls /path/to/outer-repo/...` or `find /path/to/outer-repo` to check, (3) you're about to cite that filesystem-walk result in a PR description, handoff doc, or commit message as if it represented main's state. Trap: in a multi-worktree setup, the outer repo's working tree is on whatever branch the user (or another session) last checked out — which can be ANY sibling worktree's feature branch, never guaranteed to be main. Running `ls` on the outer dir lists THAT branch's files, not main's. A handoff doc that says "X is on main" or "X was written by session S" based on outer-`ls` evidence will fail a reviewer's dead-reference check and ship a fabricated claim. v1.1 adds the GIT-STATUS variant: the same frame inversion bites `git diff` / `git status` / `git log` run after a `cd` into the base/outer repo — git reports the BASE working tree (a different branch with its own uncommitted edits), so your worktree's changes appear to VANISH and you wrongly conclude a parallel session reverted your work. Run git from your worktree (or `git -C <worktree>`); never `cd` to the base repo to inspect state.
Trending skills
7-day visitors to each skill page
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.
ls Mistaken for Main-StateYou're working inside a git worktree at <repo>/.claude/worktrees/<branch>/.
You need to verify whether some file (e.g., docs/handoffs/session_184_X.md)
exists on origin/main — perhaps because:
The natural-feeling check is:
ls /Users/.../repo/docs/handoffs/ | grep session_184
# → session_184_drivers_breakdown_full_sweep_prompt.md
You walk up out of the worktree, list the outer repo's docs/handoffs/, see
the file, and cite it as "on main". That conclusion is wrong in any repo
with multiple worktrees in use.
All four must be true to fire this trap:
git worktree list shows >1 entry).claude/worktrees/<X>/)origin/main's statels, find, cat, tree)
on the outer repo's path instead of a git plumbing commandThe outer working tree's HEAD can be on:
main branch (only if no one explicitly switched it)git checkout <feature> in the outer dir)git worktree addYou cannot tell which from a casual ls. Concrete failure mode observed in S184b
(2026-05-12, PR #778): handoff doc cited session_184_drivers_breakdown_full_sweep_prompt.md
as "on main, unconsumed" based on outer-ls. The reviewer ran git ls-tree origin/main
and proved the file did not exist on main — it lived only in a sibling worktree's working
tree. Three textual mentions had to be rewritten before the PR could merge.
ls on the outer repo pathWhen the question is "does X exist on main?", ls is the wrong tool. The outer working
tree is just another working tree — its state is no more canonical than yours.
# Does docs/handoffs/session_184_X.md exist on origin/main?
git ls-tree --name-only origin/main docs/handoffs/ | grep session_184
# What's the content of that file on main?
git show origin/main:docs/handoffs/session_184_X.md
# All files in a directory on main:
git ls-tree --name-only origin/main docs/handoffs/
# Listing across all refs (when you don't care WHICH branch, just whether it exists anywhere):
git log --all --oneline -- docs/handoffs/session_184_X.md
Always git fetch origin main --quiet before this audit so the local origin/main ref is
current — otherwise you're checking against a stale snapshot.
git log --all is great for "is this file anywhere git has ever seen?" but a hit doesn't
mean main has it. If the answer to "where does it live?" matters, follow up with:
git branch -a --contains $(git log --all --format='%H' -- docs/handoffs/session_184_X.md | head -1)
# Lists every ref that has the commit that introduced the file.
If origin/main is not in that list, the file is NOT on main — even if your outer-repo ls
showed it.
Before pushing a handoff doc or PR body that asserts " is on main" / " was written by session S" / " exists in repo":
# Extract every cited path
grep -oE 'docs/[a-zA-Z0-9_/-]+\.(md|py|sqlx|html|json)' your_doc.md \
| sort -u \
| while read path; do
git ls-tree --name-only origin/main "$path" >/dev/null 2>&1 \
&& echo "✓ on main: $path" \
|| echo "✗ MISSING on main: $path"
done
Anything ✗ MISSING either needs a real annotation ("this file lives on a non-main branch
in worktree Y; recover with git show <branch>:<path>") or removal.
# Before fixing
ls /path/to/outer-repo/docs/handoffs/ | grep session_184
# Shows session_184_drivers_breakdown_full_sweep_prompt.md
# Truth
git ls-tree --name-only origin/main docs/handoffs/ | grep session_184
# Returns nothing — file is NOT on main
# Where it actually lives
git log --all --oneline -- 'docs/handoffs/session_184_*' 2>/dev/null | head -3
# If no commits printed: file is in some worktree's working tree but never committed.
# Otherwise: lists the branch(es) that committed it.
In S184b (2026-05-12), while writing session_184b_campaign_pre_launch_zeros_handoff.md,
I needed to characterize the relationship to the canonical S184 session. I ran:
ls /Users/<user>/Documents/the-project-repo/docs/handoffs/ | grep 184
# → session_184_drivers_breakdown_full_sweep_prompt.md
…and wrote in the handoff: "canonical S184 drivers-breakdown sweep prompt at
session_184_drivers_breakdown_full_sweep_prompt.md on main, unconsumed."
PR #778 code-review caught it:
Sibling reference is broken:
docs/handoffs/session_184_drivers_breakdown_full_sweep_prompt.mdexists neither on main nor in the worktree. The handoff cites it 3 times as "on main, unconsumed" / "written by S183" — that file does NOT exist anywhere reachable.
Verification with git ls-tree:
git ls-tree --name-only origin/main docs/handoffs/ | grep -i "184\|drivers" | head
# session_107a_topdrivers_handoff.md
# session_110_topdrivers_triple_fix_handoff.md
# (no session_184_*)
The file existed only in a sibling worktree's working tree (the outer-repo path's HEAD
had been switched to that sibling's branch at some point). Fix: rewrite the 3 mentions to
describe S184 as "an unrelated parallel drivers-breakdown stream running in a sibling
worktree, no artifact on main yet" — drop the specific filename, drop the "on main" claim.
Recovery commit: fc4d523f on docs/s184b-summer-wow-handoff; merged via PR #778.
ls the outer repo unless you brief it
to use git ls-tree origin/main. Spell it out in the agent prompt.gh ls-tree doesn't exist — but gh api repos/<owner>/<repo>/contents/<path>?ref=main
works as a remote-only fallback when you can't trust the local origin/main ref freshness.
Heavier than git ls-tree; only use when offline-from-local-git.actions/checkout@v4
fetches merge_commit_sha, not main — file-existence asserts in CI that use plain [ -f ]
in the workflow may not catch this class. Verification belongs in handoff-doc review (per
session-handoff v1.6 Phase 4 step 22 dead-reference check), not in CI.worktree add can switch outer HEAD: when you git worktree add ../other some-branch, the outer working tree keeps its current branch UNLESS the user ran a
git checkout in the outer dir at some point. The instability comes from human action,
not git itself — but the human action is invisible to a session that joined later.git diff/status/log run from the BASE repo shows ITS working tree, not yours (v1.1)The same frame inversion bites with git status commands, not just ls — and it's scarier
because your own uncommitted work appears to vanish. From inside a worktree, if you
cd /path/to/base-repo && git diff (or git status / git log), git reports the base
repo's working tree — which is parked on some other branch with its own uncommitted edits.
Your worktree's staged changes aren't there; an unrelated file you never touched IS there. The
instinctive read is "a parallel session reverted my work / detached my HEAD."
Worked case (the project drawer, 2026-06-22). Mid-fix I ran cd /…/the-project-repo && git diff --stat
to review my change. It showed only an unrelated docs/deliverables/...s207...html edit and
NONE of my bq_queries.py/test changes → momentary "did my work get reverted?!" panic. Cause:
the cd jumped to the base checkout (a different branch with its own dirty file); my changes
were intact in the worktree the whole time. Running git status -sb from the worktree (no
cd) showed both my modified files correctly.
The discipline:
cd to the base/outer repo to inspect state. Each
worktree has its own index + HEAD; git always reports the working tree of the cwd.cd is almost always wrong-cwd, not data loss.
Before concluding a parallel session reverted you, check git rev-parse --show-toplevel and
git branch --show-current — confirm you're in the worktree, not the base repo.git -C <worktree-path> … over cd when you must target a specific tree, so the
cwd never silently changes which working tree git reads. (In this harness the Bash cwd also
resets between calls, compounding the confusion — see main-bash-cwd-persists-nested-worktree.)subagent-bash-cd-wrong-worktree v1.0.0 — sister: cd doesn't persist between Bash calls in
subagents; commits land on the outer working tree's branch instead of the worktree's branch.
Different mechanism (cd state) but same root cause (multi-worktree disorientation).session-handoff-number-collision-with-unmerged-sibling v1.1.0 — picking the wrong session
NUMBER because a sibling's same-numbered handoff isn't on main yet. Same family (parallel-
worktree state confusion); different trigger (which-N-do-I-use vs does-file-X-exist).worktree-historical-test-replay-missing-dirs — replaying historical tests in a worktree
misses dirs that are only on newer commits. Same "outer-vs-current" frame inversion.flask-debug-cross-worktree-edit-stale — Flask reloader picks up edits from another worktree
via shared module imports. Sibling problem at the runtime layer.superpowers:using-git-worktrees — broader worktree workflow guidance, doesn't focus on the
filesystem-walk trap.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-verifyDisarming auto-merge on a PR whose agent is still running does not hold it —
the agent re-arms within minutes and the PR merges, because arming is a step in
the agent's brief and disarming is not an instruction to the agent at all. Use
when: (1) you want to STOP a pull request from merging that an agent opened and
armed, for review, for a rethink, or because it is landing into a queue you are
trying to drain; (2) a PR you disarmed merged anyway; (3) you are telling agents
which PRs are on hold and want the hold to be enforced rather than announced;
(4) you are about to run `gh pr merge --disable-auto` and have not decided what
to do about the agent. The order is KILL THE AGENT FIRST, THEN DISARM, THEN
VERIFY the disarm by reading `autoMergeRequest` back — a disarm you did not read
back is not a hold. The stronger form needs no ordering at all: convert the PR
to a draft with `gh pr ready --undo`. A draft cannot merge whatever any agent
does to it, so the hold survives an agent you missed, an agent that restarts,
and an agent you did not know about.
/batch-member-cites-a-path-only-a-non-member-addsYou wrote something correct that the default reader cannot reach: a batch member citing a
path only a NON-member adds, or a rule, ruling or ledger sitting on an unlanded branch.
/batch-merge-subject-is-not-evidence-a-member-landedYou are about to close, delete the branch of, or mark as landed a pull
request because a batch, roll-up or merge-train commit on the target branch
names it in the subject line, and because the member's own commits all
predate that merge by wall clock. Neither of those is evidence. A batch
branch is assembled at some moment BEFORE it merges, so anything the member
pushed after assembly is outside it, and the subject records INTENT at
assembly time rather than CONTENT at merge time. Use before closing a
member, when an ancestry check against a squashed batch says no, or when a
member's branch still shows commits ahead of the target. Compare file
content against the target branch instead, expecting exactly one legitimate
difference: the shared aggregate file every member appends to.
/check-a-stale-branch-is-not-undoing-newer-main-workA branch built on an out-of-date main is about to merge, or has merged, and may undo work
that landed since. Use when a green, conflict-free PR deletes files you never touched,
newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger
(tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a
reviewer says your small PR touches dozens of files you did not change.
/ci-leg-skipping-moves-minutes-it-does-not-remove-themYou are about to propose, price or approve a CI cost saving that works by
making a job or matrix leg SKIP on pull requests — a path filter, a safe
list, a changed-files gate, an exemption list. Check first whether the
pipeline runs a complement or backstop on merge, on push, or nightly:
many do, and then the legs a pull request skipped are exactly the legs some
later run executes, so a branch that goes green once and merges bills the
same total either way and the wall clock does not move at all. Use when
pricing a filter change, when a percentage saving is quoted with no basis,
or when choosing between filtering legs and batching pull requests. The
question that separates money from bookkeeping is whether the change
removes RUNS or merely moves LEGS.