subagent-bash-cd-wrong-worktreelisted
Install: claude install-skill wan-huiyan/agent-traffic-control
# Subagent + bash `cd` + multi-worktree → commit lands on wrong branch
## Problem
You dispatched a subagent (via the Task tool) to do work in a specific git worktree.
You wrote bash steps like:
```bash
cd /path/to/.claude/worktrees/feature-X
pip install -r requirements.txt
git add foo.py
git commit -m "..."
```
The subagent reports DONE with a commit SHA. The SHA is real (`git rev-parse <sha>`
resolves) but `git log` on `feature-X`'s branch does not show it. `git branch
--contains <sha>` reveals the commit landed on whatever branch was checked out
in the **parent repository directory** (not your target worktree).
**Why subagents miss this:** they trust their own `cd` step to have worked, then
call `git commit` and see a successful commit message echoed by Git. Git commits
the staged change to whatever HEAD is in the cwd Git resolves, which (after the
shell reset) is the launch directory's HEAD — not the worktree's.
## Trigger Conditions
- Multi-worktree git setup (`git worktree list` shows ≥ 2 entries)
- Subagent dispatch (general-purpose Task tool, any model)
- Subagent prompt instructed `cd <abspath> && <commands>` for shell steps
- Subagent reported DONE with a SHA that doesn't appear in `git log` on the
target worktree's branch
- Subagent's first bash call shows the `cd` worked; subsequent calls silently
ran in a different cwd
## Root Cause
Each Bash tool call starts a fresh shell. Working directory persists *within* a
single tool call (chained with `&&` or `