/agent-traffic-control:verify-pytest-imports-worktree-not-primary-checkoutfrom agent-traffic-control
When you run pytest (or any `python -c "import <pkg>"`) from a git WORKTREE but the venv has an editable install (`pip install -e .`) made from the PRIMARY checkout, `import <pkg>` silently resolves to the PRIMARY checkout's source, NOT the worktree code you think you're testing. Use when: (1) you edited code in a worktree, ran the suite, it passed/failed — but you're unsure it exercised the worktree's edits, (2) tests pass on changes that "shouldn't" pass (or fail on changes you reverted), (3) a `src/`-layout project with absolute `import src.*` / `import <pkg>.*` imports, one shared `.venv`, and multiple worktrees. Fix: prepend the worktree root to `PYTHONPATH` and VERIFY resolution with `print(<pkg>.__file__)`.
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.
You have one virtualenv with an editable install (pip install -e .) created
from the primary repo checkout. You then create a git worktree to do
isolated feature work, edit code there, and run the test suite from the worktree
directory. The suite runs against the primary checkout's source, not your
worktree edits — silently. Green tests "prove" nothing about your branch; a fix
you only made in the worktree looks like it had no effect, or a bug you only
reverted in the worktree still appears.
src/-layout project whose code uses absolute imports (import src.app,
from mypkg.x import y) — so the package is resolved via sys.path, not via
the cwd.pip install -e . (or pip install -e ".[dev]") run from
the primary checkout. The editable install drops a __editable__.<pkg>.pth
/ finder into site-packages that hardcodes the primary checkout's path.pytest / python -m pytest / python -c "import <pkg>" from a
git worktree directory (e.g. .../.claude/worktrees/feature-x).sys.path precedence at import time is roughly: the script/cwd entry, then
PYTHONPATH entries, then site-packages (where the editable .pth lives).
pytest does not reliably put the worktree's project root first (it only adds
rootdir/cwd under specific pythonpath/conftest/rootdir conditions, and a
src/ layout usually means src's parent isn't auto-added). So import <pkg>
falls through to the editable install's hardcoded primary path. Nothing
errors — it's just the wrong tree.
Prepend the worktree root to PYTHONPATH so it wins over the editable
.pth, and verify resolution before trusting any result:
WT=/abs/path/to/worktree # the worktree you edited
VENV=/abs/path/to/primary/.venv # the shared venv with the editable install
# 1. VERIFY which tree import resolves to — do this FIRST, every time:
PYTHONPATH="$WT" "$VENV/bin/python" -c \
"import src.app, pathlib; print('src from:', pathlib.Path(src.app.__file__))"
# want: src from: /abs/path/to/worktree/src/app.py (NOT the primary checkout)
# 2. Run the suite with the same override:
cd "$WT" && PYTHONPATH="$WT" "$VENV/bin/python" -m pytest tests/ -q
Alternatives (heavier): create a fresh venv inside the worktree and
pip install -e . there; or use tox/uv run with per-tree environments. The
PYTHONPATH prepend is the fastest and needs no install.
The print(<pkg>.__file__) line resolves to a path under the worktree, not
the primary checkout. A quick negative control: run the same one-liner WITHOUT
PYTHONPATH — it should print the primary path, confirming the trap is real and
the override is doing the work.
brief-runner S26: fixing a template/CSS bug in worktree
.claude/worktrees/s26-configure-fix, the venv lived at the primary checkout
(/Users/.../the-handover-repo/.venv) with pip install -e .. Before running the
wizard tests I checked:
$ PYTHONPATH="$PWD" /…/the-handover-repo/.venv/bin/python -c \
"import src.app, pathlib; print('src from:', pathlib.Path(src.app.__file__))"
src from: /Users/.../the-handover-repo/.claude/worktrees/s26-configure-fix/src/app.py ✓
Confirmed the worktree's src won; the 17-test wizard suite then genuinely
exercised the worktree edits. Without the check, a green run would have been
meaningless.
flask-debug-cross-worktree-edit-stale, multi-worktree-file-url-stale-content,
main-bash-cwd-persists-nested-worktree): here the files are fine in the
worktree, but the Python import machinery points elsewhere because of the
editable install's hardcoded path. Same family ("am I really running the tree I
think I am?"), different mechanism.cd — pass PYTHONPATH (and an absolute venv python) on the same command
line every time.__file__ rather than assuming.ruff/mypy/coverage that import the package: verify
the resolved path, not just that the tool ran..pth that site-packages installs.pythonpath / import-mode docs — why src/ roots aren't auto-added.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub wan-huiyan/agent-traffic-control --plugin agent-traffic-controlOther plugins' skills for the same job
118 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