You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
loops/work: Bash tool cwd does not persist across calls despite tool docs — caused a worker's edits to land in the canonical checkout #566
Opus implementation worker dispatched for issue #459, briefed to cd into an out-of-tree sibling worktree (../claude-code-plugins-issue-459) and work only there. Worker self-reported in its return payload: "my edits initially landed in the canonical checkout by mistake; I moved them into the worktree via git diff | git apply and restored the canonical checkout clean."
Orchestrator-side observation across this same session: nearly every Bash tool call in this transcript is followed by a harness line Shell cwd was reset to <original-cwd> — even though the Bash tool's own description states "The working directory persists between commands." Concretely: cd "D:/repos/github.com/melodic-software/claude-code-plugins" followed by a git command in the same call works, but a separate, later Bash call starts back at the session's original cwd rather than wherever the prior call left off.
Observed vs expected
Observed: cwd does not persist across separate Bash tool invocations in this session, contradicting the tool's documented behavior. A worker (or orchestrator) that cds into a worktree in one call and issues file-editing commands in a later call — without re-cd-ing every single time — silently operates from the wrong directory. In the work-items(triage): step-2 "wait for user direction" gate contradicts the skill's own autonomous/agent triage mode #459 case this caused edits to land in the canonical checkout instead of the assigned worktree; it was caught and fixed only because the worker happened to notice before finishing.
Expected: either (a) cwd genuinely persists between Bash calls as documented, or (b) if this environment/session cannot guarantee that, every subagent brief that assigns a worktree must say so explicitly and instruct re-cd-ing (or fully-qualified git -C <path> / absolute paths) on every single command, rather than relying on an initial cd.
Impact
A worker that doesn't self-catch this (unlike this one) would silently commit into the canonical checkout's working tree, or push a branch containing whatever the canonical checkout happened to have staged — a correctness/safety gap for the whole "OUT-OF-TREE per-issue worktree" convention this lane's standing rules depend on (rule 1).
Suggested fix direction
Short-term: every implementation-subagent brief in this lane should tell workers to prefix every file-touching command with git -C <worktree-path> (or re-cd every call) rather than trusting a one-time cd. Longer-term this may be a harness-level cwd-persistence bug worth reporting upstream if it reproduces outside this repo's tooling.
Worker briefs assign an out-of-tree sibling worktree and rely on a one-time cd <worktree> to redirect all subsequent file-touching commands. In this environment the Bash tool's cwd does not reliably persist across separate tool calls (contrary to the tool's own docs), so a later, separate Bash call silently runs from the session's original cwd — the canonical checkout. The fix is to stop trusting persistent cwd in briefs: instruct workers to make every file-touching command self-locating via git -C <worktree-path> / absolute paths (or to re-cd in the same call as the command).
This is a doc/prompt-wording change only. No code, no harness change (the upstream cwd-persistence bug is explicitly out of scope for this repo).
Where worker briefs are actually authored
Two authoritative sites compose implementation-worker briefs — the fix belongs in both:
plugins/implementation/skills/implement-dispatch/SKILL.md — "Dispatch cadence" → step 1 Compose the brief (line 33). This is the runtime checklist enumerating every required brief element (scope fence, divergence-escalation clause, invariants, acceptance criteria, model routing). It is the SSOT for what every dispatched brief must carry.
plugins/planning/skills/plan/context/plan-template.md — the "Divergence escalation (copy into every worker brief verbatim)" block (lines 227–236). This is where verbatim copy-into-every-brief clauses live, mirrored by the routing-table note at line 253 ("every worker row implies a dispatch brief carrying the scope fence + the divergence-escalation clause above").
The out-of-tree per-issue worktree convention itself is a consuming-repo standing rule (the loop/work lane's rule 1), not defined in this repo — so the fix targets the generic brief-authoring machinery, gated on "when a worker is assigned an out-of-tree worktree."
Change 1 — implement-dispatch/SKILL.md, step 1 "Compose the brief"
Append a new required brief element to the enumerated list (after "any model routing the plan specifies"):
, and — when the worker is assigned an out-of-tree/sibling worktree — a working-directory-discipline clause: cwd is NOT guaranteed to persist across separate Bash tool calls in this environment, so the brief MUST forbid relying on a one-time cd and require every file-touching command to be self-locating (git -C <worktree-path> …, absolute paths, or a cd <worktree-path> && … in the same call as the command). Pass the absolute worktree path explicitly in the brief.
Change 2 — plan-template.md, add a companion verbatim clause
Directly beneath the divergence-escalation text block (after line 236), add a second verbatim block, and extend the line 253 routing-table note to also reference it ("...carrying the scope fence + the divergence-escalation clause + the working-directory clause below, when a worktree is assigned"):
Working directory discipline (copy into every worker brief that assigns an out-of-tree worktree, verbatim):
WORKING DIRECTORY (mandatory): your assigned worktree is <ABSOLUTE-WORKTREE-PATH>.
Do NOT rely on `cd` persisting across separate tool calls — in this environment
the shell cwd can reset between calls, silently landing edits in the wrong
checkout. Make EVERY file-touching command self-locating: use `git -C
<ABSOLUTE-WORKTREE-PATH> …`, absolute paths, or `cd <ABSOLUTE-WORKTREE-PATH> &&
<command>` within the SAME call. Before finishing, verify no edits leaked outside
the worktree (e.g. `git -C <canonical-checkout> status` is clean).
The orchestrator substitutes the real absolute paths for the <…> placeholders when composing each brief.
Why these two, and nothing else
/implementation:implement (inline cadence) does not dispatch workers, so it needs no change. The source-control:worktree skill uses the harness-native EnterWorktree (a session-level cwd transition), not the out-of-tree cd-into-sibling pattern, so it is unaffected. Both edits are additive prompt wording gated on the worktree-assignment condition — no behavior change for briefs that don't assign a worktree.
Follow-up (optional, non-blocking)
Add/adjust an eval assertion in plugins/implementation/skills/implement-dispatch/evals/evals.json for a worktree-assigned scenario, asserting the composed brief carries the self-locating-command instruction.
Confidence: HIGH
Both brief-authoring sites were located directly; the fix is a clean, low-risk, additive wording change confined to prompt/doc files, gated on the worktree-assignment condition.
Activity
kyle-sexton commentedon Jul 20, 2026
This was generated by AI during triage.
T2 planning pass — implementation plan
Root cause (confirmed)
Worker briefs assign an out-of-tree sibling worktree and rely on a one-time
cd <worktree>to redirect all subsequent file-touching commands. In this environment the Bash tool's cwd does not reliably persist across separate tool calls (contrary to the tool's own docs), so a later, separate Bash call silently runs from the session's original cwd — the canonical checkout. The fix is to stop trusting persistent cwd in briefs: instruct workers to make every file-touching command self-locating viagit -C <worktree-path>/ absolute paths (or to re-cdin the same call as the command).This is a doc/prompt-wording change only. No code, no harness change (the upstream cwd-persistence bug is explicitly out of scope for this repo).
Where worker briefs are actually authored
Two authoritative sites compose implementation-worker briefs — the fix belongs in both:
plugins/implementation/skills/implement-dispatch/SKILL.md— "Dispatch cadence" → step 1 Compose the brief (line 33). This is the runtime checklist enumerating every required brief element (scope fence, divergence-escalation clause, invariants, acceptance criteria, model routing). It is the SSOT for what every dispatched brief must carry.plugins/planning/skills/plan/context/plan-template.md— the "Divergence escalation (copy into every worker brief verbatim)" block (lines 227–236). This is where verbatim copy-into-every-brief clauses live, mirrored by the routing-table note at line 253 ("every worker row implies a dispatch brief carrying the scope fence + the divergence-escalation clause above").The out-of-tree per-issue worktree convention itself is a consuming-repo standing rule (the loop/work lane's rule 1), not defined in this repo — so the fix targets the generic brief-authoring machinery, gated on "when a worker is assigned an out-of-tree worktree."
Change 1 —
implement-dispatch/SKILL.md, step 1 "Compose the brief"Append a new required brief element to the enumerated list (after "any model routing the plan specifies"):
Change 2 —
plan-template.md, add a companion verbatim clauseDirectly beneath the divergence-escalation
textblock (after line 236), add a second verbatim block, and extend the line 253 routing-table note to also reference it ("...carrying the scope fence + the divergence-escalation clause + the working-directory clause below, when a worktree is assigned"):The orchestrator substitutes the real absolute paths for the
<…>placeholders when composing each brief.Why these two, and nothing else
/implementation:implement(inline cadence) does not dispatch workers, so it needs no change. Thesource-control:worktreeskill uses the harness-nativeEnterWorktree(a session-level cwd transition), not the out-of-treecd-into-sibling pattern, so it is unaffected. Both edits are additive prompt wording gated on the worktree-assignment condition — no behavior change for briefs that don't assign a worktree.Follow-up (optional, non-blocking)
Add/adjust an eval assertion in
plugins/implementation/skills/implement-dispatch/evals/evals.jsonfor a worktree-assigned scenario, asserting the composed brief carries the self-locating-command instruction.Confidence: HIGH
Both brief-authoring sites were located directly; the fix is a clean, low-risk, additive wording change confined to prompt/doc files, gated on the worktree-assignment condition.
docs(implementation): broaden worktree-cwd clause to git ops + echo i…
feat(implementation): front-load CI-hygiene and early-push clauses in…
docs(source-control): anchor babysit worker commands to the worktree …