main-bash-cwd-persists-nested-worktree

main-bash-cwd-persists-nested-worktree is a skill for Claude Code from wan-huiyan/agent-traffic-control. It costs 486 tokens per session (3,024 once invoked), scanned A, original, MIT.

A guide for preventing nested Git worktrees, which are separate branch checkouts accidentally created inside another worktree.

In plain words
What is it for?
Use it when creating parallel worktrees, checking their filesystem locations, or diagnosing path mismatches and cleanup problems.
Why use it?
It explains how a persistent shell folder can cause later worktrees to be created at unexpected paths while Git operations still appear to work.

Skill for Claude Code

Written for Claude Code: disable-model-invocation in frontmatter. Also seen: mentions subagents; mentions Claude Code.

Not installable: its command points at a path on the author’s own machine, so it runs nowhere else. The line is /Users/x/Documents/<name>.

Part of the agent-traffic-control plugin — 105 skills shipped together

Good fit Use it when creating parallel worktrees, checking their filesystem locations, or diagnosing path mismatches and cleanup problems.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

This one installs as part of its plugin. Adding the marketplace and installing the plugin brings it with everything else the plugin ships.

Claude Code
/plugin marketplace add wan-huiyan/agent-traffic-control
Claude Code
/plugin install agent-traffic-control

Made for: Claude Code.

Or install agent-traffic-control, the plugin that ships this one along with the rest of its 105 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for main-bash-cwd-persists-nested-worktree

README.md
[![agentmods](https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree/github.svg)](https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree)
Your own site
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for main-bash-cwd-persists-nested-worktree

Your own site · 80×15
<a href="https://agentmods.dev/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree"><img src="https://agentmods.dev/badge/skills/wan-huiyan/agent-traffic-control/main-bash-cwd-persists-nested-worktree.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 486 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,024 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00486 $0.03024
Opus 5 $0.00243 $0.01512
Sonnet 5 $0.00097 $0.00605
Haiku 4.5 $0.00049 $0.00302

Measured 9d ago against content hash 1fc2fa44b1b6, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-09, from the pricing page.

Security

Grade A, and why

main-bash-cwd-persists-nested-worktree scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/agent-traffic-control/skills/main-bash-cwd-persists-nested-worktree/SKILL.md · 185 lines

How it starts

The opening of the file, as written. The whole thing — 185 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Main-agent Bash cwd persistence → nested worktrees at wrong path

Problem

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:

  • Dispatched subagents pointed at the intended path will report "worktree path mismatch."
  • Cleanup (git worktree remove .claude/worktrees/track-B) from the project root won't find it.
  • Per-worktree caches, venvs, and uploads end up under the wrong parent directory.

Context / Trigger conditions

  • Main agent runs more than one git worktree add in the same session.
  • Between worktree-add calls, the main agent ran a Bash command that included a cd to a path other than the project root.
  • The later git worktree add uses a relative path (e.g., .claude/worktrees/<name>).
  • Symptom: 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).

Solution

Three reliable mitigations, in order of preference:

  1. 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.

Read the full file on GitHub · 185 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 185 lines · 486 tokens per session scan A 1fc2fa44b1b6

Subscribe to this mod's changes

main-bash-cwd-persists-nested-worktree is a skill published in the GitHub repository wan-huiyan/agent-traffic-control (3 stars, last pushed 4d ago), licensed MIT. It adds 486 tokens to every session and 3,024 once invoked, about $0.0024 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

ql-housekeep

Detect repo-hygiene issues that accumulate during long-running autonomous development (merge-conflict markers, orphan worktrees, CPC-variant duplicates, stale branches, version-manifest drift). Detection-only by default — reports findings, never deletes or modifies without explicit user confirmation.

andyzengmath/quantum-loop · 57 tokens

nazgul:doctor

Run the Nazgul read-only preflight diagnostic — checks jq/gh presence and auth, git-hooks drift, cache-vs-repo plugin version, the bash-vs-zsh hazard, the NAZGULDIR footgun, config-schema staleness, either install mode's .gitignore Nazgul-block drift (stamp and flush-left region), cross-session messaging and Remote…

OrodruinLabs/nazgul · 151 tokens

hotfix

Emergency fix workflow that bypasses normal sprint processes with a full audit trail. Creates hotfix branch, tracks approvals, and ensures the fix is backported correctly.

IdoCohen560/claude-unity-game-studio · 35 tokens

cloudflare-workers-ci-cd

Complete CI/CD guide for Cloudflare Workers using GitHub Actions and GitLab CI. Use for automated testing, deployment pipelines, preview environments, secrets management, or encountering deployment failures, workflow errors, environment configuration issues.

secondsky/claude-skills · 50 tokens

cloudflare-workers-observability

Cloudflare Workers observability with logging, Analytics Engine, Tail Workers, metrics, and alerting. Use for monitoring, debugging, tracing, or encountering log parsing, metric aggregation, alert configuration errors.

secondsky/claude-skills · 47 tokens

cloudflare-workers-dev-experience

Cloudflare Workers local development with Wrangler, Miniflare, hot reload, debugging. Use for project setup, wrangler.jsonc configuration, or encountering local dev, HMR, binding simulation errors.

secondsky/claude-skills · 47 tokens