/agent-traffic-control:main-bash-cwd-persists-nested-worktreefrom agent-traffic-control
Prevent and diagnose nested git worktrees created at the wrong filesystem path when orchestrating parallel work from the main Claude Code agent. Use when (1) you ran `git worktree add .claude/worktrees/<name> ...` from the main agent's Bash tool, (2) `git worktree list` shows the new worktree at an unexpected nested path like `.claude/worktrees/<previous-worktree>/.claude/worktrees/<name>` instead of the intended top-level location, (3) a subagent dispatched to the intended path reports "worktree path mismatch" or operates from a longer nested path. Root cause: the main agent's Bash tool **persists cwd between calls** (per its docstring: "The working directory persists between commands"). An earlier `cd /abs/path && cmd` changes the main shell's cwd; a later `git worktree add <relative-path> ...` resolves against that persisted cwd rather than the project root, silently creating nested layouts. This is the **inverse** of the subagent variant (subagent-bash-cd-wrong-worktree) — subagent shells reset per call, main shell doesn't. **Also covers the sibling case (v1.1): from the project ROOT, a `git worktree add ../<name> ...` escapes UP to the repo's PARENT dir (e.g. `/Users/x/Documents/<name>`), OUTSIDE the `.claude/worktrees/` convention — and a later Read/Edit/Write using the assumed `.claude/worktrees/<name>` absolute path fails with a MISLEADING "file does not exist" (the file exists, the worktree is just elsewhere).** **Also covers (v1.2): a drifted cwd makes `git diff A B -- <repo-relative-path>` return EMPTY while `git diff A B --stat` (no pathspec) shows the same file as changed — because pathspecs resolve relative to cwd but `--stat` reports against the repo root. Tell: a pathspec-filtered git command comes back empty yet `--stat` / `git show <rev>:<path>` disagree → suspect cwd drift, not the commit/branch/range.**
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.
The main-session Bash tool now says: "cd carries to the next call only in the main session, if the command succeeds and ends inside the working directories. Outside them the shell returns to the start folder; otherwise it stays where it was." So:
cd to a path inside the working directories (the project and any added folders) (for example .claude/worktrees/track-A) still persists, so the nested-worktree trap and the git diff -- <path> empty-pathspec trap below still happen exactly as described.cd to a path outside them (a worktree under /tmp, or ../sibling) no longer sticks: the next call starts back in the start folder. Relative paths used after such a cd resolve against the start folder, not the worktree. Chain cd <abs-path> && cmd in one call, or pass absolute paths.You're orchestrating multiple parallel-dispatch subagents, each in its own git worktree. From the main agent's Bash tool you do:
git worktree add .claude/worktrees/track-A origin/main -b feat/track-A
# ... dispatch Track A subagent ...
# ... investigate codebase ...
cd /path/to/repo/.claude/worktrees/track-A && grep -rn "foo" src/ # persists cwd!
# ... time passes, you dispatch Track B ...
git worktree add .claude/worktrees/track-B origin/main -b feat/track-B
You expect track-B at <repo>/.claude/worktrees/track-B. Instead git worktree list reports it at <repo>/.claude/worktrees/track-A/.claude/worktrees/track-B — nested inside the Track A worktree.
Branches, commits, and pushes still work (git resolves them via .git/worktrees/<name> metadata regardless of disk location), but:
git worktree remove .claude/worktrees/track-B) from the project root won't find it.git worktree add in the same session.cd to a path other than the project root.git worktree add uses a relative path (e.g., .claude/worktrees/<name>).git worktree list shows nested paths, OR a subagent given the intended path can't find its worktree, OR pwd inside a subagent reports a longer-than-expected path.The Bash tool's own description says it: "The working directory persists between commands, but shell state does not." This is the opposite of subagent Bash, which resets cwd per call (see subagent-bash-cd-wrong-worktree).
Three reliable mitigations, in order of preference:
Always pass an absolute path to git worktree add from the main agent.
git worktree add /Users/<user>/Documents/the-handover-repo/.claude/worktrees/track-B origin/main -b feat/track-B
This is the cleanest fix and is robust against any cwd drift.
Reset cwd to project root in the same chained call before any git worktree add with a relative path:
cd /Users/<user>/Documents/the-handover-repo && git worktree add .claude/worktrees/track-B origin/main -b feat/track-B
Create ALL worktrees up-front in a single batch at the start of the session, before any other Bash commands that might cd.
When dispatching parallel subagent prompts, also bake an absolute-path verification step into each prompt:
First action: verify worktree path matches expectation.
cd /Users/<user>/Documents/the-handover-repo/.claude/worktrees/<name>
pwd # MUST end in <name>; STOP and report if it doesn't
git rev-parse --abbrev-ref HEAD # MUST be feat/<name>
After creating a worktree, immediately:
git worktree list | grep <name>
The reported path must NOT be nested under another worktree. If it is, before any subagent dispatch:
# Move it to the correct location (requires admin; or just remove + re-add)
git worktree remove <wrong-nested-path>
git worktree add /abs/path/to/.claude/worktrees/<name> origin/main -b feat/<name>
What went wrong (Session 15, the-handover-repo):
# Main agent at /Users/<user>/Documents/the-handover-repo (project root)
git worktree add .claude/worktrees/s15-lows-bundle origin/main -b feat/s15-lows-bundle
# → created at .../the-handover-repo/.claude/worktrees/s15-lows-bundle ✅
# Later, investigation:
cd /Users/<user>/Documents/the-handover-repo/.claude/worktrees/s15-lows-bundle && grep "_JINJA_ENV" src/
# → main shell cwd is now inside s15-lows-bundle worktree
# Even later, second worktree:
git worktree add .claude/worktrees/s15-csv-upload origin/main -b feat/s15-csv-upload
# → created at .../s15-lows-bundle/.claude/worktrees/s15-csv-upload ❌
Fix applied in that session: none mid-session (PRs all pushed correctly via branch refs). The lesson is to use absolute paths next time.
../<name> escapes UP to the repo parent, then a file-tool call "file does not exist"A second, even-easier-to-hit shape — cwd was correct (the project root), the relative path itself was wrong:
cd /Users/x/Documents/myrepo # at project root — cwd is fine
git worktree add -b docs/foo ../foo origin/main # ../ escapes to /Users/x/Documents/foo ❌
# intended .claude/worktrees/foo, but ../foo = the repo's PARENT dir
tail ../foo/docs/file.md # works HERE — same bash, cwd still repo root
# ... later, an Edit/Write/Read with the ASSUMED path:
# Edit /Users/x/Documents/myrepo/.claude/worktrees/foo/docs/file.md
# → "File does not exist" ← MISLEADING: the file exists at /Users/x/Documents/foo/...
The ../<name> reads like "a worktree beside the others" but .claude/worktrees/ is two levels down, so ../ goes the wrong direction entirely. The trap is the downstream symptom: the worktree was created fine and even tail in the same bash worked (cwd-relative), but the next file-tool call uses a hard-coded absolute path under .claude/worktrees/ and reports the file missing — pointing you at the file, not at the worktree's real location.
Guards (in addition to the absolute-path rule above):
../: git worktree add .claude/worktrees/<name> <ref> (from the project root) or the absolute equivalent.git worktree list | grep <name> # the path column is the source of truth
Use that exact path — never an assumed .claude/worktrees/<name> — when the next tool call needs an absolute path.git worktree add, suspect the worktree location before suspecting your file path.git diff -- <repo-relative-path> return EMPTY while --stat shows the changeSame root cause (main-shell cwd persisted into a subdir after an earlier cd), different — and very disorienting — symptom: git pathspecs are resolved relative to cwd, but --stat/--name-only without a pathspec report against the repo root. So the two disagree, and the file looks both changed and unchanged at once:
# earlier in the session, cwd drifted into a subdir:
cd /repo/<analytics_pkg>/cloudrun/<dashboard_app> && python -m pytest ... # persists cwd
# later, trying to inspect a commit that DID touch bq_queries.py:
git show --stat HEAD | grep bq_queries # → "bq_queries.py | 62 ++++--" (file IS in the commit)
git diff HEAD~1 HEAD -- <analytics_pkg>/cloudrun/<dashboard_app>/bq_queries.py
# → EMPTY ❌ (pathspec resolved from cwd = .../<dashboard_app>/<analytics_pkg>/... which doesn't exist)
git show HEAD:<analytics_pkg>/.../bq_queries.py | grep <symbol> # → matches (object-name form is cwd-INDEPENDENT)
The tell is the contradiction: git show --stat / git diff A B --stat (no pathspec) lists the file as changed, but git diff A B -- <repo-relative-path> returns nothing, and git show HEAD:<path> (a <rev>:<path> object name, which is always repo-root-relative) shows the content fine. When a pathspec-filtered git command comes back empty but the unfiltered --stat disagrees, suspect cwd drift before suspecting the commit, the branch, a .gitattributes -diff driver, or a bad range.
Guards:
pwd when a pathspec-filtered git result surprises you — the harness's own "Shell cwd was reset to …" tool-result lines are reporting the drift, not just noise.cd /abs/repo/root && git diff … -- <path> for any pathspec-filtered inspection, OR use the cwd-independent git show <rev>:<path> / --stat (no pathspec) forms.cd inside a compound Bash command (cd X && cmd) still mutates the persistent cwd for every later call — it is not scoped to that one command..git/worktrees/<name> metadata, not by filesystem path. So this bug is silent — you only notice when a subagent reports a path mismatch or when you try to git worktree remove from the project root.cd / cwd-independent git forms), so it lives here with the other cwd-drift symptoms.subagent-bash-cd-wrong-worktree) describes the opposite failure mode: subagent shells reset cwd per call, so a cd followed by git commit in a separate Bash call commits to the parent repo's HEAD. Both are real, and the fix is the same: use absolute paths and verify with pwd before any state-changing command.superpowers:using-git-worktrees — general worktree workflow.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.