Skip to content

fix(source-control): default an unset worktree_root instead of refusing - #1853

Merged
kyle-sexton merged 8 commits into
mainfrom
fix/worktree-root-default
Jul 31, 2026
Merged

kyle-sexton merged 8 commits into
mainfrom
fix/worktree-root-default

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Closes #1852

Summary

worktree_root ships unset and the helper refused outright when it was, so /worktree create was unusable on a fresh install until the user configured a root by hand — a hard failure standing in for a missing default. It now falls back to ${CLAUDE_PLUGIN_DATA}/worktrees, and the stale rationale that justified the refusal is corrected across every surface that repeated it.

Fix

The default. The invariant worth protecting is that the worktree lands OUTSIDE every repository, not that a human typed the path. ${CLAUDE_PLUGIN_DATA} satisfies it on its own — the harness's per-plugin state directory, never inside a checkout, never a repository-discovery root — and it is already babysit_worktree_root's default, so this reuses the sibling key's precedent rather than inventing a second answer.

Exit 3 survives for the one case with no safe root to pick: no configured value AND no plugin data dir (a raw CLI invocation outside a plugin install). The containment guard is untouched — a root pointed inside a repository is still rejected, and that check, not the unset check, is what enforces the nesting invariant.

The rationale. Four surfaces attributed the nesting ban to Claude Code's CLAUDE.md/rules double-load bug, fixed upstream in v2.1.69. The ban is still correct for a narrower reason measured on 2.1.220: from a worktree nested inside a checkout, a read matching a path-scoped rule's glob also loads the PARENT checkout's copy of that rule; an externally-placed worktree emits zero such events.

This matters beyond tidiness — left as-is, the next reader auditing the guard against a fixed bug concludes the guard is obsolete and removes it. The worktree skill now carries the finding as a four-part upstream-drift record (claim, basis including how to reproduce the InstructionsLoaded trace, as-of date, recheck trigger) so the invariant can be re-derived rather than trusted.

worktree_root was also missing from the README configuration table while every sibling key was listed.

Verification

  • 139 helper assertions pass, 0 fail.
  • The 8 new fallback assertions all FAIL against the pre-fix helper — verified by stashing the helper and re-running — so they pin the new behavior rather than passing vacuously.
  • Both handoff paths covered, --root and --root-file. The skill always writes a file, so a fallback reaching only --root would have left the common case broken; the empty-content and unexpanded-token file cases both assert the fallback now.
  • Refusal still tested, with CLAUDE_PLUGIN_DATA explicitly cleared so the no-safe-root branch is exercised rather than skipped.
  • shellcheck -x clean on both changed shell files. evals.json re-parsed as valid JSON after the contract update (2-line diff, no reformatting).

One thing I did NOT do: shfmt reports formatting drift on worktree-create.sh, but it does so on the unmodified file too — the repo does not run shfmt on this plugin, and reformatting it would bury this change in noise.

Related

  • Sibling precedent: babysit_worktree_root, defaulting to the plugin data dir
  • docs/conventions/upstream-drift/README.md — the record shape the corrected rationale takes
  • Refs melodic-software/medley#1713 — the same measured finding, fixed there in the repo-local resolver

Update after review

Codex raised a P1 on the first draft and it was correct: the fallback read ${CLAUDE_PLUGIN_DATA}, which in a Bash-tool subprocess is not scoped to the invoking plugin — this repo's own probe (docs/extensibility-contract-smoke-tests.md) recorded it naming an unrelated installed plugin's data directory. Since this helper's only callers are the worktree skill and orchestrated workers, both Bash-tool subprocesses, there was no caller for which it would have been right.

Substituting the token into skill markdown does not rescue it either — plugins/architecture/skills/improve/SKILL.md:72 records that it substitutes in hook/monitor/MCP paths only.

The default now derives from the repository: a worktrees/ directory beside the checkout (/src/app → /src/worktrees). Every caller supplies --repo-dir, so $toplevel is always reachable, and the parent of a checkout is outside the repository by construction. A regression guard pins it — a stray CLAUDE_PLUGIN_DATA must not steer placement, and that assertion reproduces the reported defect against the old code.

`worktree_root` ships unset, and the helper refused outright when it was —
so `/worktree create` was unusable on a fresh install until the user
configured a root by hand. That is a hard failure standing in for a missing
default.

The invariant worth protecting is that the worktree lands OUTSIDE every
repository, not that a human typed the path. `${CLAUDE_PLUGIN_DATA}`
satisfies it on its own — the harness's per-plugin state directory, never
inside a checkout, never a repository-discovery root — and it is already
`babysit_worktree_root`'s default, so this reuses the sibling key's
precedent rather than inventing a second answer. Exit 3 survives for the
one case with no safe root to pick: no configured value AND no plugin data
dir, which is a raw CLI invocation outside a plugin install. The
containment guard is untouched; a root pointed inside a repository is still
rejected, and that check — not the unset check — is what enforces nesting.

The rationale was also stale in four surfaces. They attributed the nesting
ban to Claude Code's CLAUDE.md/rules double-load bug, fixed upstream in
v2.1.69. The ban is still right, for a narrower reason measured on 2.1.220:
from a worktree nested inside a checkout, a read matching a path-scoped
rule's glob also loads the PARENT checkout's copy of that rule. Left as-is,
the next reader auditing the guard against a fixed bug would conclude the
guard is obsolete and remove it. The worktree skill now carries that
finding as a four-part upstream-drift record — claim, basis (the
InstructionsLoaded trace and how to reproduce it), as-of date, and a
recheck trigger — so the invariant can be re-derived rather than trusted.

Test plan: 139 helper assertions pass, 0 fail. The 8 new ones covering the
fallback all FAIL against the pre-fix helper (verified by stashing it), so
they pin the new behavior rather than passing vacuously. Both handoff
paths are covered — `--root` and the skill's `--root-file` — because the
skill always writes a file, so a fallback reaching only `--root` would
leave the common case broken. shellcheck clean. (shfmt still reports
pre-existing drift on this helper; the repo does not run shfmt here, and
reformatting it is not this change's business.)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95d604c5ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Resolves two conflicts, both from parallel releases rather than competing
intent:

- plugin.json version: main shipped 0.44.0 while this branch had bumped
  0.40.1 to 0.41.0. Retargeted to 0.45.0 — this branch changes behavior
  (an unset worktree_root now defaults instead of refusing), so it takes a
  minor bump above main's current version rather than reusing 0.41.0.
- CHANGELOG.md: both sides prepended entries. Composed — main's 0.44.0,
  0.43.0, and 0.42.x entries are kept verbatim and this branch's entry sits
  above them under its new 0.45.0 heading.

Swept for semantic conflict beyond the markers: README.md was the third
file both sides touched, and the changes are disjoint — main documented a
new pr-linkage-mcp-gate hook, this branch added the missing worktree_root
row to the configuration table. Both survive.

Re-ran the helper suite after resolving: 139 assertions pass, 0 fail.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 24s —— View job


Reviewing PR #1853

  • Gather context (diff, CLAUDE.md, REVIEW.md)
  • Understand the request (code review of this PR)
  • Review worktree-create.sh fallback logic
  • Review test coverage changes
  • Review skill/docs/changelog updates
  • Post final review

Review

This is a well-scoped, well-tested change: the fallback logic, the corrected rationale, and the doc/README/CHANGELOG updates are all consistent with each other and with the described precedent (babysit_worktree_root). One finding worth resolving before merge, below.

1. CLAUDE_PLUGIN_DATA is not reliably scoped to this plugin on the invocation path the PR calls "the common case" (blocking)

worktree-create.sh#L202-L204 asserts ${CLAUDE_PLUGIN_DATA} is "the harness's per-plugin state directory," and L218-L219 trusts it unconditionally as the fallback root.

But this repo's own smoke test — docs/extensibility-contract-smoke-tests.md Test B — measured the opposite for exactly this call shape: "A skill-invoked Bash-tool subprocess does NOT inherit CLAUDE_PLUGIN_OPTION_*... it pointed at an unrelated installed plugin's data directory, not the invoking plugin's... ${CLAUDE_PLUGIN_DATA} resolves per-plugin only inside a plugin's own declared commands; in a general Bash-tool subprocess it carries one session default, so it is not a dependable per-plugin signal for a skill-spawned script either."

The worktree skill invokes the helper exactly this way — context/create.md#L82 is a plain bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" ... line the model runs via its Bash tool, not a plugin-declared command/hook/MCP component. Per Test B, that's precisely the case where CLAUDE_PLUGIN_DATA is a stray session-level value, not source-control's own data dir.

Consequence: on the fresh-install path this PR exists to fix, /worktree create may silently place the worktree under some other installed plugin's data directory rather than source-control's own — the nesting invariant (outside every repo) still holds, but the "mirrors babysit_worktree_root" safety argument doesn't, because that sibling key's consumers are invoked as plugin-declared components where the variable does resolve per-plugin (per Test B's own carve-out), not as ad hoc Bash-tool subprocesses.

This is the same concern @chatgpt-codex-connector raised on worktree-create.sh:219 — it's grounded in this repo's own verified findings, not speculation, so I'd treat it as blocking rather than advisory. Two ways to close it that fit the existing design:

  • Have the skill resolve its own plugin data dir (the ${CLAUDE_PLUGIN_ROOT}-adjacent convention, or a value the skill can derive without depending on the ambient env var) and pass it to the helper explicitly — e.g. a --data-dir flag alongside --root/--root-file — rather than letting the helper read the ambient CLAUDE_PLUGIN_DATA.
  • At minimum, note in the helper's contract comment that the fallback is only guaranteed correct when the caller is a plugin-declared component (true for babysit_worktree_root's consumers) and flag the skill-invoked path as the known gap, so a future reader doesn't extend the same assumption elsewhere.

Fix this →

Nits (non-blocking)

  • The rest of the change is solid: the containment guard (unchanged) still enforces the actual nesting invariant regardless of which root gets picked, the --root and --root-file handoffs both get fallback coverage, and the 8 new test cases genuinely pin the new behavior (confirmed by the PR description's stash-and-rerun verification claim, which lines up with what the diff shows).
  • The corrected upstream-drift rationale (four surfaces updated from "double-load bug" to the narrower, reproducible path-scoped-rule-glob finding) is a good catch — the old comments really would have misled a future reader into thinking the guard was obsolete.
  • Per CLAUDE.md's fresh-docs mandate, this PR's contract-surface changes (config schema description, --help text) don't touch any page in docs/OFFICIAL-DOCS.md's scope, so no WebFetch citation was required here — correctly not attempted.

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 12s —— View job


Claude is reviewing this PR

  • Gather context (read diff, changed files)
  • Security review of changed files
  • Post findings

Security review

Scope: only the files changed in this PR (git diff origin/main...HEAD), per the review lane's instructions. GitHub Actions / supply-chain concerns are deferred to zizmor's advisory lane and not re-reported here — this PR touches no workflow files anyway.

IMPORTANT — unset-worktree_root fallback trusts an unscoped CLAUDE_PLUGIN_DATA, which can point at a different plugin's data directory

File: plugins/source-control/scripts/worktree-create.sh#L217-L238

This confirms the finding chatgpt-codex-connector already flagged inline (P1) — I independently verified it against the repo's own documentation and it holds:

  • The new fallback does root="${CLAUDE_PLUGIN_DATA%/}/worktrees", reading CLAUDE_PLUGIN_DATA from the helper's own process environment at runtime.
  • The skill invokes this helper as a plain Bash-tool command (context/create.md line 82-83: bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" --name ... --root-file ...), not as a declared plugin command/hook/MCP subprocess.
  • This repo's own docs/extensibility-contract-smoke-tests.md (Test B, lines ~70-82) documents, from a measured probe, that a skill-invoked Bash-tool subprocess does not get a per-plugin-scoped CLAUDE_PLUGIN_DATA: "The only plugin variable present was a single session-level CLAUDE_PLUGIN_DATA, and it pointed at an unrelated installed plugin's data directory, not the invoking plugin's." The doc explicitly concludes ${CLAUDE_PLUGIN_DATA} "is not a dependable per-plugin signal for a skill-spawned script."

Failure scenario: with worktree_root unset (the fresh-install default this PR targets) and another plugin installed alongside source-control, /worktree create can silently place the new worktree — including any .worktreeinclude-matched gitignored files it copies in, which routinely hold secrets (.env, credentials) — under that other plugin's data directory rather than source-control's own. That's a cross-plugin data-isolation break: content from the user's repository lands in storage scoped to, and potentially consumed by, an unrelated plugin. It also undercuts the PR's own stated invariant ("the worktree lands OUTSIDE every repository... ${CLAUDE_PLUGIN_DATA} satisfies that on its own") — the invariant only holds if the value is reliably this plugin's data dir, which the repo's own probe says it isn't in this exact call path.

Note: the same ambient-read pattern predates this PR (babysit_worktree_root already defaults to ${CLAUDE_PLUGIN_DATA}/worktrees, cited here as precedent), so this may be a pre-existing exposure rather than one wholly new to this diff — but this PR extends the pattern to a second, skill-invoked entry point and asserts CLAUDE_PLUGIN_DATA as unconditionally safe in the code comments/PR description without accounting for the caveat this repo already documented about that exact invocation shape.

Suggested fix: have the worktree skill resolve ${CLAUDE_PLUGIN_DATA} via its own markdown text-substitution (which is correctly plugin-scoped per the same doc) and pass it into the helper explicitly — e.g. a new --data-dir flag, or folded into the existing --root-file non-shell handoff — rather than letting worktree-create.sh read the ambient environment variable.

Fix this →

Severity: IMPORTANT · Confidence: High (independently verified against the repo's own measured/documented probe of this exact code path, not just asserted)

Other areas checked, no issues found

  • Path handling / injection: --root, --root-file, and the CLAUDE_PLUGIN_DATA fallback all flow into git worktree add and cp/mkdir -p as literal argv values — never through eval or unquoted expansion — so no shell-injection surface from a hostile root value.
  • --root-file NUL/newline handling (lines 156-178) correctly rejects NUL bytes before they'd be silently dropped by command substitution, and rejects any newline rather than trimming — sound.
  • Containment guard (lines 413-467) is unchanged in logic by this PR (only its comments/messages changed to correct the double-load-bug rationale) and still walks up to the nearest existing ancestor via git rev-parse --show-toplevel / --is-inside-git-dir, which is immune to a raw string-prefix bypass.
  • .worktreeinclude copy loop (lines 590-620) is NUL-delimited and unchanged by this PR; not newly introduced attack surface.
  • No changes to CI/workflow files, no permission or trust-boundary changes elsewhere in the diff (plugin.json, README.md, CHANGELOG.md, evals.json, SKILL.md, create.md are prose/doc/version-only changes).

@github-actions

github-actions Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude has reviewed this PR 5 times. The lane skips further automatic reviews after 5; deleting this comment resets the count.

Same two text conflicts as the previous merge, same resolution shape: this
branch keeps 0.45.0 (it stays above main's newest release), and the
changelog composes — this branch's 0.45.0 entry sits above main's new
0.44.1 entry, both verbatim.

Helper suite re-run after resolving: 139 assertions pass, 0 fail.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 38s —— View job


Security review of PR #1853

  • Gather context (diff, prior review findings)
  • Check current state of the CLAUDE_PLUGIN_DATA scoping finding flagged in prior reviews
  • Review remaining diff for new security issues
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD). This trigger fired on a branch sync, but comparing 08612bb (the commit my prior review on this PR was against) to the current head b101645 shows the branch only picked up unrelated origin/main merges (loop-lane/lanes/work-items changes) — none of the files in this PR's actual scope (worktree-create.sh, worktree-create.test.sh, create.md, SKILL.md, plugin.json, evals.json) changed in that window. So this is a re-review of the same code my prior pass covered, not new content.

IMPORTANT — unset-worktree_root fallback still trusts an unscoped CLAUDE_PLUGIN_DATA; this finding is unresolved

File: plugins/source-control/scripts/worktree-create.sh#L217-L223

This is the same finding I raised in my prior pass on this PR (and that chatgpt-codex-connector independently flagged inline on worktree-create.sh:219) — I re-verified it against the current head and it still holds, unchanged:

  • The fallback still does root="${CLAUDE_PLUGIN_DATA%/}/worktrees", reading CLAUDE_PLUGIN_DATA from the helper's own process environment at runtime.
  • The skill still invokes this helper as a plain Bash-tool command — context/create.md#L82-L83 is unchanged from the prior review: bash "${CLAUDE_PLUGIN_ROOT}/scripts/worktree-create.sh" --name ... --root-file ..., not a declared plugin command/hook/MCP subprocess.
  • This repo's own docs/extensibility-contract-smoke-tests.md (Test B) documents, from a measured probe, that a skill-invoked Bash-tool subprocess does not get a per-plugin-scoped CLAUDE_PLUGIN_DATA — it carries one session-level value that can point at an unrelated installed plugin's data directory, and is "not a dependable per-plugin signal for a skill-spawned script."

Failure scenario (unchanged): with worktree_root unset — the fresh-install default this PR targets — and another plugin installed alongside source-control, /worktree create can silently place the new worktree, including any .worktreeinclude-copied gitignored files (which routinely hold secrets: .env, credentials), under that other plugin's data directory rather than source-control's own. That's a cross-plugin data-isolation break, and it undercuts the PR's own stated safety argument that ${CLAUDE_PLUGIN_DATA} "satisfies [the outside-every-repo invariant] on its own" the same way babysit_worktree_root's does — that sibling key's consumers run as plugin-declared components where the variable resolves per-plugin (per Test B's own carve-out); this skill's invocation shape does not.

Nothing in the diff since my last pass narrows this — no --data-dir flag, no skill-side resolution of the plugin's own data dir, no contract-comment caveat scoping the fallback's safety claim to plugin-declared-component callers only.

Suggested fix (unchanged): have the worktree skill resolve ${CLAUDE_PLUGIN_DATA} via its own markdown text-substitution (correctly plugin-scoped per Test B) and pass it into the helper explicitly — e.g. a --data-dir flag alongside --root/--root-file — rather than the helper reading the ambient environment variable.

Fix this →

Severity: IMPORTANT · Confidence: High (verified against the repo's own measured probe of this exact code path; unchanged since my prior review on this PR)

Other areas re-checked, no new issues

  • Path handling / injection: --root, --root-file, and the CLAUDE_PLUGIN_DATA fallback still flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion.
  • Containment guard (unchanged logic, only comments corrected) still enforces the actual nesting invariant regardless of which root gets picked.
  • --root-file empty/token fallback tests added in this diff (worktree-create.test.sh) correctly exercise both the plugin-data-dir-present and plugin-data-dir-absent branches, and explicitly clear CLAUDE_PLUGIN_DATA to hit the genuine refusal path — no test-coverage gap that would mask this finding.
  • No workflow files touched; no permission or trust-boundary changes elsewhere in the diff (plugin.json's changes are version bump + description text only).

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 20s —— View job


Reviewing PR #1853 (code-review lane)

  • Gather context (diff vs origin/main, prior review threads, CLAUDE.md/REVIEW.md)
  • Check whether the CLAUDE_PLUGIN_DATA scoping finding (raised by the security lane + Codex) has been addressed
  • Review test coverage and remaining diff for correctness/maintainability issues
  • Post findings

Review

Scope: files changed vs origin/main (8 files). Per this repo's lane split, the CLAUDE_PLUGIN_DATA-scoping concern already flagged by the security lane and by chatgpt-codex-connector (worktree-create.sh:219) is a security/data-isolation finding, so I'm leaving that one to the security lane rather than re-deriving it here — for the record, it's still open as of b101645: the helper still reads the ambient env var directly and context/create.md:82 still invokes it as a plain Bash-tool subprocess, unchanged from what those reviews examined.

On correctness, error handling, test coverage, and maintainability, this change is solid:

  • Root-resolution logic (worktree-create.sh#L217-L238) unifies the --root and --root-file inputs into one $root check before the fallback/refuse branch, so both handoff paths get identical treatment — no risk of the fallback working for one flag and not the other.
  • Containment guard is untouched — the actual nesting-invariant enforcement doesn't move, only the rationale comments do, and the corrected rationale (measured path_glob_match finding vs. the fixed double-load bug) is applied consistently across the helper, --help text, plugin.json description, SKILL.md, and create.md.
  • Test coverage is genuinely pinned, not just added: the new fallback assertions cover both --root and --root-file (including the empty-file and unexpanded-token cases), and the refuse-path assertions now explicitly clear CLAUDE_PLUGIN_DATA so that branch stays exercised rather than silently subsumed by the new default.
  • evals.json update matches the new behavior (unset key → successful fallback, not a refusal) and stays valid JSON with a minimal diff.

Two minor/non-blocking items:

  1. CHANGELOG.md is missing a blank line between the new 0.45.0 entry and the following ## [0.44.1] heading — CHANGELOG.md#L31-L32. Every other version heading in the file is preceded by a blank line; this one isn't. Fix this →
  2. The new upstream-drift record in SKILL.md (SKILL.md#L42) correctly carries all four required parts (claim, basis, as-of date, recheck trigger) per docs/conventions/upstream-drift/README.md, but doesn't link back to that owner doc, and the skill isn't added to its Adopters table. Not required by the doc, but every other conforming record it catalogs does both — worth doing for discoverability of the convention, low priority.

Nothing here blocks merge from a correctness/maintainability standpoint; the one item that does block (per the security lane) is the CLAUDE_PLUGIN_DATA scoping gap, tracked separately.

…tory

The first draft of this default read ${CLAUDE_PLUGIN_DATA}, mirroring
babysit_worktree_root. Review caught that it does not hold, and the
repository's own probe is the evidence: in a general Bash-tool subprocess
that variable is not scoped to the invoking plugin — the probe recorded it
naming an unrelated installed plugin's data directory
(docs/extensibility-contract-smoke-tests.md "Result").

This helper has no caller for which it would be correct. Its call sites are
the worktree skill (skills/worktree/context/create.md) and orchestrated
workers (skills/worktree/SKILL.md) — both Bash-tool subprocesses. There is
no WorktreeCreate hook in this plugin. Nor can the skill substitute the
token into its own markdown and hand it over: ${CLAUDE_PLUGIN_DATA}
substitutes in hook/monitor/MCP paths only, as
plugins/architecture/skills/improve/SKILL.md already records. So the plugin
data dir was unreachable from every real caller, and the fallback would
either have placed worktrees under another plugin's storage or silently
never fired.

The repository is the one thing every caller does supply: --repo-dir, hence
$toplevel. The default is now a worktrees/ directory beside the checkout
(/src/app -> /src/worktrees), which is outside the repository by
construction. Detection stays where it was; resolution moved below the
$toplevel probe, since the fallback cannot be computed before the repository
is known.

The containment guard is untouched and still proves the placement rather
than trusting the derivation.

Test plan: 139 assertions pass, 0 fail; shellcheck clean. The new
assertions fail against the previous helper (verified by stashing it),
including the decisive one — with a stray CLAUDE_PLUGIN_DATA set, the old
code lands the worktree under <foreign>/worktrees, which is precisely the
defect reported. Coverage spans both handoff paths (--root and --root-file,
including the unexpanded-token shape the skill actually produces), and
asserts explicitly that the derived root is outside the repository.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 2m 36s —— View job


Reviewing PR #1853 (code-review lane, re-review at b9cb956)

  • Gather context (diff vs origin/main, prior review threads)
  • Check current state of previously-flagged nits (CHANGELOG blank line, upstream-drift record link)
  • Review latest commit (b9cb956) for new correctness/maintainability issues
  • Post findings

Review

b9cb956 replaces the ${CLAUDE_PLUGIN_DATA} fallback with a default derived from the repository's own location (dirname "$toplevel"/worktrees), closing the blocking finding the security lane and chatgpt-codex-connector raised on the earlier revision — that variable is not reliably scoped to the invoking plugin in the Bash-tool-subprocess call shape this helper actually has. I traced the new logic end to end and it holds:

  • Detection/resolution split is correct. The unset check (plugins/source-control/scripts/worktree-create.sh#L214-L218) runs before $toplevel is known and only sets a flag; actual resolution (#L263-L264) waits until after $toplevel is resolved (#L240), since the derived default needs the repo's location. Both --root and --root-file populate the same $root before this check (#L120-L172), so the fallback is genuinely unified across both handoff paths, not just --root.
  • Exit 3 now comes solely from the containment guard (#L443-L474), not from a missing-fallback branch — the fallback can no longer fail to resolve (it only needs $toplevel, which --repo-dir always supplies), so refusal is scoped correctly to "the resolved root actually lands inside a repository."
  • The regression test at worktree-create.test.sh#L153-L162 is the right one to have: it sets a foreign CLAUDE_PLUGIN_DATA and asserts the worktree still lands at the derived default, not under the foreign path — this is the exact defect the prior revision had, now pinned rather than just fixed.
  • Filesystem-root edge case (dirname /repo → /) is called out in a comment (#L260-L262) as deliberately-correct rather than special-cased, which is the right call — /worktrees is still outside /repo.

One non-blocking edge case worth a test, not a blocker: since the default is now derived from the repo's own location rather than an unrelated external path, a repo whose parent directory happens to itself be part of another git working tree (e.g. a repo cloned inside a monorepo-of-repos layout) will hit the containment guard and refuse (exit 3) on an unconfigured key — reintroducing, for that narrower layout, the exact "unusable until manually configured" failure mode this PR exists to fix generally. Tracing the guard logic (#L437-L474), it does correctly catch and refuse this case rather than silently misplacing the worktree, so it's not a correctness bug — but it's a real interaction introduced by deriving the default from $toplevel, and no test exercises it. Worth a case in worktree-create.test.sh alongside the existing "root nested inside a different checkout" test (#L176-L182), so a future change to the derivation doesn't silently drop the guard for this shape.

Previously-flagged nits — status

  • CHANGELOG blank line (flagged in my prior pass): still open — CHANGELOG.md#L39-L40 still has no blank line between the [0.45.0] entry's last bullet and the ## [0.44.1] heading, unlike every other version heading in the file. Cosmetic, non-blocking.
  • upstream-drift record cross-linking (flagged in my prior pass): still open — the SKILL.md record still doesn't link back to docs/conventions/upstream-drift/README.md, and the worktree skill still isn't listed in that doc's Adopters table. Not required by the convention doc itself, low priority.
  • Docs/messaging consistency: verified no stale CLAUDE_PLUGIN_DATA/"plugin data dir" references remain across the helper, tests, SKILL.md, create.md, README.md, plugin.json, CHANGELOG.md, or evals.json for the worktree_root key specifically (the unrelated babysit_worktree_root sibling key correctly keeps its own plugin-data-dir default, unaffected by this change).

Note: I was unable to execute shellcheck or run the test suite directly in this sandbox (commands required approval that wasn't available in this lane) — I verified correctness by static tracing of the script instead of by running it. The PR description's own verification claims (139 assertions, shellcheck clean) are consistent with what the diff shows.

Nothing here blocks merge — the one prior blocking finding (unscoped CLAUDE_PLUGIN_DATA) is resolved by this commit's redesign.

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 37s —— View job


Security review of PR #1853

  • Gather context (diff vs origin/main, prior review findings on CLAUDE_PLUGIN_DATA scoping)
  • Check whether commit b9cb956 ("derive the default worktree root from the repository") resolves the previously-flagged scoping gap
  • Review remaining diff for new security issues
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD), current head b9cb956.

Previously-flagged finding: RESOLVED

My last two passes on this PR (and chatgpt-codex-connector's inline P1 comment on worktree-create.sh:219) flagged that the unset-worktree_root fallback read the ambient ${CLAUDE_PLUGIN_DATA} env var, which this repo's own docs/extensibility-contract-smoke-tests.md documents is not reliably scoped to the invoking plugin in a skill-invoked Bash-tool subprocess — it can point at an unrelated installed plugin's data directory, letting a worktree (including any .worktreeinclude-copied secrets) land under foreign storage.

Commit b9cb956 closes this by dropping the CLAUDE_PLUGIN_DATA read entirely. I verified the current state directly:

  • worktree-create.sh#L263-L270: the unconfigured-root default is now root="$(dirname "$toplevel")/worktrees" — derived from $toplevel (resolved via --repo-dir, a value every real caller supplies), not from any environment variable. grep -n CLAUDE_PLUGIN_DATA across the changed files confirms the helper no longer reads it anywhere; the only remaining references are an explanatory comment (L202-L210) and a new regression test.
  • worktree-create.test.sh#L153-L161 adds a decisive regression guard: it sets CLAUDE_PLUGIN_DATA to a foreign path and asserts the resolved worktree root does not follow it — this is exactly the failure mode the prior finding described, now pinned as a test.
  • The derivation is a sibling of the checkout (/src/app → /src/worktrees), which is outside the repository by construction, and the containment guard further down (unchanged logic, L437-L474) still independently proves placement via git rev-parse --show-toplevel / --is-inside-git-dir rather than trusting the derivation — so even a bug in the new default logic would be caught, not silently trusted.

This also fully addresses chatgpt-codex-connector's inline finding, which named the same root cause.

Remaining diff (doc/config/eval files) — no issues

plugin.json, README.md, SKILL.md, context/create.md, evals.json, and CHANGELOG.md changes are all prose/description updates consistent with the corrected rationale (the nesting ban is now attributed to the measured path_glob_match finding rather than the fixed double-load bug) and the new default behavior. No permission, trust-boundary, or contract-surface changes beyond what's already covered above.

No new security issues found

  • Injection / path handling: unchanged from prior passes — --root, --root-file, and the derived default all flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion.
  • --root-file NUL/newline handling: unchanged, still sound.
  • Containment guard: unchanged logic; still immune to a raw string-prefix bypass.
  • No workflow files touched; no permission or trust-boundary changes elsewhere in the diff.

Conclusion: the previously blocking finding is resolved and independently regression-tested. No open security findings on this PR as of b9cb956.

@kyle-sexton

Copy link
Copy Markdown
Member Author

Fixed in b9cb956 — the P1 was correct, and worse than described.

I checked the repo's own probe: docs/extensibility-contract-smoke-tests.md records CLAUDE_PLUGIN_DATA in a Bash-tool subprocess pointing at an unrelated installed plugin's data directory. And this helper has no caller for which it would be correct — its call sites are the worktree skill (context/create.md:82) and orchestrated workers (SKILL.md:94), both Bash-tool subprocesses; there is no WorktreeCreate hook in this plugin.

The suggested remedy — substitute the token into skill markdown and hand it over via the non-shell channel — does not work either: plugins/architecture/skills/improve/SKILL.md:72 already records that ${CLAUDE_PLUGIN_DATA} "does not substitute in skill markdown content (it is a hook/monitor/MCP path substitution only)". So the plugin data dir is unreachable from every real caller, both ways.

The default now derives from the repository instead: a worktrees/ directory beside the checkout (/src/app → /src/worktrees). Every caller supplies --repo-dir, so $toplevel is always available, and the parent of a checkout is outside the repository by construction. Resolution moved below the $toplevel probe since it cannot be computed earlier; detection stayed put. The containment guard is untouched and still proves the placement rather than trusting it.

Regression guard added, and it reproduces the reported defect: with a stray CLAUDE_PLUGIN_DATA set, the previous code lands the worktree under <foreign>/worktrees. All 8 new assertions fail against the old helper (verified by stashing it) and pass against the new one. 139 total, 0 failing, shellcheck clean.

Composing this branch's changelog entry against main's dropped the blank
line separating it from the next heading, tripping MD032 and MD022. Content
unchanged.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 14s —— View job


Reviewing PR #1853 (code-review lane, re-review at 83223a1)

  • Gather context (diff vs origin/main, prior review threads)
  • Check whether the CHANGELOG blank-line nit is now resolved
  • Review latest commit for new correctness/maintainability issues
  • Post final findings

Review

83223a1 is a one-line change relative to my previous pass (b9cb956): it inserts the blank line I'd flagged between the [0.45.0] entry's last bullet and the ## [0.44.1] heading. Confirmed directly — git diff b9cb956..83223a1 touches only CHANGELOG.md, adding exactly that blank line, matching every other version heading in the file now.

Nothing else changed, so the rest of my prior findings on b9cb956 stand as-is:

  • Root-resolution redesign holds up. The default is now derived from $toplevel (dirname "$toplevel"/worktrees) rather than the ambient ${CLAUDE_PLUGIN_DATA}, closing the P1 raised by the security lane and chatgpt-codex-connector — that variable isn't reliably scoped to the invoking plugin in this helper's actual (Bash-tool-subprocess) call shape. Detection (worktree-create.sh#L214-L218) stays before $toplevel is known; resolution (#L263-L264) correctly waits until after (#L240), since the derived default needs the repo's location.
  • Both handoff paths (--root, --root-file) share one $root check, so the fallback isn't accidentally scoped to only one of them.
  • Exit 3 now comes solely from the containment guard, not a missing-fallback branch — refusal is scoped to "the resolved root actually lands inside a repository," which is the right invariant.
  • The regression test (worktree-create.test.sh#L153-L161) sets a foreign CLAUDE_PLUGIN_DATA and asserts the worktree still lands at the derived default — this is the exact defect the earlier revision had, now pinned.
  • Filesystem-root edge case (dirname /repo → /) is explicitly called out in a comment as deliberately-correct, not accidentally-untested.

One still-open, non-blocking item from my prior pass, unaffected by this commit: the upstream-drift record in SKILL.md carries all four required parts (claim, basis with repro steps, as-of date, recheck trigger) but still doesn't link back to docs/conventions/upstream-drift/README.md, and the worktree skill still isn't listed in that doc's Adopters table. Not required by the convention doc itself — worth doing for discoverability, low priority, doesn't block merge.

One edge case I flagged as worth a test but not a bug, also still untested: a repo whose parent directory is itself part of another git working tree will hit the containment guard and refuse (exit 3) on an unconfigured key, reintroducing this PR's own "unusable until manually configured" failure mode for that narrower layout. The guard handles it correctly (refuses rather than misplacing), so it's not a correctness defect — just an interaction with no dedicated regression test alongside the existing "root nested inside a different checkout" case (worktree-create.test.sh#L176-L182).

Conclusion: both previously-open items from this lane (the blocking CLAUDE_PLUGIN_DATA scoping concern, owned by the security lane, and the CHANGELOG formatting nit, owned by this lane) are now resolved. Nothing here blocks merge.
· branch fix/worktree-root-default

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 52s —— View job


Security review of PR #1853 (re-review at 83223a1)

  • Gather context (diff vs origin/main, prior security-review findings)
  • Check what changed since the last security pass (b9cb956 → 83223a1)
  • Confirm the previously-resolved CLAUDE_PLUGIN_DATA scoping finding is still resolved
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD), current head 83223a1.

What changed since my last security pass (b9cb956)

Only one commit: 83223a1 restores a blank line between the [0.45.0] entry and the ## [0.44.1] heading in CHANGELOG.md. This is a whitespace-only documentation edit with no security surface — confirmed via git diff b9cb956..HEAD, which touches only that one line in CHANGELOG.md.

Previously-flagged finding: still resolved

My prior two passes on this PR flagged that the unset-worktree_root fallback read the ambient ${CLAUDE_PLUGIN_DATA} env var, which this repo's own docs/extensibility-contract-smoke-tests.md documents is not reliably scoped to the invoking plugin in a skill-invoked Bash-tool subprocess (it can point at an unrelated installed plugin's data directory). Commit b9cb956 closed this by deriving the default from the repository's own location instead. Re-verified against the current head:

  • grep -n CLAUDE_PLUGIN_DATA across the changed helper/test/skill files shows the helper itself (worktree-create.sh) no longer reads the variable — the only occurrence there is an explanatory comment stating explicitly that the default must NOT be ${CLAUDE_PLUGIN_DATA}.
  • The unconfigured-root default remains root="$(dirname "$toplevel")/worktrees", derived from --repo-dir (a value every real caller supplies), and the containment guard (worktree-create.sh#L443-L474, unchanged) independently proves placement via git rev-parse --show-toplevel/--is-inside-git-dir rather than trusting the derivation.
  • The regression guard at worktree-create.test.sh#L153-L161 sets a foreign CLAUDE_PLUGIN_DATA and asserts the resolved root does not follow it — pinning the exact failure mode originally reported.

This also fully addresses chatgpt-codex-connector's inline P1 on worktree-create.sh:219, which named the same root cause.

No new or open security issues

  • Injection / path handling: unchanged from prior passes — --root, --root-file, and the derived default all flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion.
  • --root-file NUL/newline handling: unchanged, still sound.
  • Containment guard: unchanged logic, immune to a raw string-prefix bypass.
  • No workflow files touched anywhere in this PR; no permission or trust-boundary changes in plugin.json, README.md, SKILL.md, context/create.md, or evals.json beyond the already-reviewed prose/description updates.

Conclusion: no open security findings on this PR as of 83223a1. The one previously-blocking finding (unscoped CLAUDE_PLUGIN_DATA) remains resolved and regression-tested; the only change since my last pass is a whitespace-only CHANGELOG fix with no security relevance.

… root

Second correction to this fallback, from independent review. The previous
commit derived the default from the repository (a worktrees/ sibling of the
checkout) on the premise that the plugin data dir was unreachable from a
skill. That premise was wrong, and I had verified only half of it.

${CLAUDE_PLUGIN_DATA} DOES substitute in a SKILL.md body. The repository's
own probe records it (docs/extensibility-contract-smoke-tests.md, Test D:
"${CLAUDE_PLUGIN_DATA} substituted in the same body" while unset
${user_config.*} tokens stayed literal), and plugins/x/skills/read/SKILL.md
relies on it in production, noting "this file is the only surface where that
expands". What does NOT substitute is a context/ file, read as raw bytes —
which is what plugins/architecture's changelog observed and overgeneralized
into "does not substitute in skill markdown content". I trusted that
sentence instead of the probe.

So the value is reachable; it just has to arrive by substitution rather than
from the environment, which is not per-plugin in a Bash-tool subprocess.
SKILL.md's body now carries the token, the skill writes the resolved path to
a second temp file, and the helper takes it via a new --data-root-file flag:
a configured root still wins, the data dir is only the fallback, and
<data-dir>/worktrees is the resolved default.

The repository-derived default is dropped because it was independently
wrong: under a discovery layout like ghq's <root>/github.com/<owner>/<repo>
a checkout sibling lands INSIDE the tree the discovery tool walks. Verified
against a fixture — `ghq list` reported the worktree as a repository of its
own, and a leading dot did not hide it. That is the pollution the worktree
skill tells users to keep a configured root clear of.

Fail-closed by construction: if substitution regresses, the file holds the
literal token, which the helper detects and refuses rather than creating a
literally-named relative directory in the repository.

The two file channels now share one reader, so --data-root-file inherits
--root-file's NUL, newline, and missing-file guards rather than duplicating
them. That reader assigns to a global instead of echoing: an `exit` inside a
$( ) capture kills only the subshell, so a captured version would have
turned every hard guard into an empty value. Verified with a probe before
relying on it.

Test plan: 153 assertions pass, 0 fail; shellcheck clean. New cases cover
the literal-token refusal, precedence (configured root wins over the data
dir), a missing data-root-file (exit 2), a newline in it (exit 2, payload
never executed), and no-root-at-all (exit 3). Eight fail against the
pre-change helper, verified by stashing it.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 3m 48s —— View job


Security review of PR #1853 (re-review at ce25fb5)

  • Gather context (diff vs origin/main, prior review findings on CLAUDE_PLUGIN_DATA scoping)
  • Check whether ce25fb5 ("supply the plugin data dir instead of deriving a root") changes the security posture
  • Trace the new --data-root-file / SKILL.md-substitution data flow end to end
  • Cross-check the design against docs/extensibility-contract-smoke-tests.md (Test B, Test D)
  • Review remaining diff for new issues
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD), current head ce25fb5. This commit lands a second redesign of the fallback since my last pass (which reviewed 83223a1's repo-derived default) — it replaces that repo-derived default with the plugin data directory again, but sourced differently this time.

The originally-flagged CLAUDE_PLUGIN_DATA scoping finding: still resolved, now on firmer footing

My last two security passes on this PR (and chatgpt-codex-connector's inline P1) flagged that reading ${CLAUDE_PLUGIN_DATA} from the helper's own process environment is unsound, because docs/extensibility-contract-smoke-tests.md Test B documents that in a skill-invoked Bash-tool subprocess, that variable is a single session-level value that can name an unrelated plugin's data directory.

ce25fb5 closes the same gap a different way, and I traced it end to end:

  • worktree-create.sh#L298-L332: the helper no longer reads CLAUDE_PLUGIN_DATA from the environment anywhere. The fallback root now comes exclusively from --data-root-file, read through the same byte-verbatim, NUL/newline-guarded channel (read_path_file, shared with --root-file) already reviewed as sound.
  • The value reaches that file via SKILL.md#L91 embedding the literal ${CLAUDE_PLUGIN_DATA} token in the skill's own body text, and docs/extensibility-contract-smoke-tests.md Test D records that this specific surface — a skill body, as opposed to a context/ file read as raw bytes — does substitute the token per-plugin. context/create.md#L81 then has Claude carry the already-resolved value down and Write it verbatim to a temp file, never re-deriving it from the environment.
  • Fail-closed: worktree-create.sh#L303-L308 detects a data-root-file still holding the literal ${CLAUDE_PLUGIN_DATA token (i.e., substitution didn't fire) and treats it as absent rather than using it as a literal relative path — pinned by the new worktree-create.test.sh case at L173-187.
  • Whatever root wins is still independently proven by the unchanged containment guard (git rev-parse --show-toplevel/--is-inside-git-dir), so even a bug in this resolution wouldn't silently place a worktree inside a repo.

This is a legitimate fix, verified against the same probe doc the prior findings cited, not just asserted.

IMPORTANT — the security rationale for why the environment read was rejected is now stale and self-contradictory in two places, creating a regression hazard

Files:

ce25fb5's own commit message says its premise-correction was exactly this: the previous commit (b9cb956) believed "the plugin data dir was unreachable from a skill... I trusted that sentence instead of the probe." But ce25fb5's diff only rewrote the resolution-block comment (worktree-create.sh#L274-L297, and the CHANGELOG's first worktree_root paragraph) — it left a second, earlier copy of the now-disproven claim untouched in both files:

  • worktree-create.sh#L237-L239: "Nor can the skill substitute the token into its markdown and hand it over: the token substitutes only in hook/monitor/MCP paths, not skill content. So the plugin data dir is unreachable from every caller this helper actually has." — this directly contradicts the working code 40 lines below it (#L284-L286, #L298-L332), which does exactly what this comment says is impossible, and is exercised by a passing test.
  • CHANGELOG.md#L36-L38: "The token cannot be substituted into skill markdown and handed over either: it substitutes only in hook/monitor/MCP paths. The repository checkout is the one root every caller can actually reach." — this sits four lines below a paragraph (#L16-L24) in the same changelog entry that says the opposite and describes the mechanism that does it.

Why this is a security finding, not a style nit: this PR's entire second workstream (the "corrected rationale" / upstream-drift record) exists because stale security rationale in comments previously misled readers into thinking a still-load-bearing guard was based on a fixed bug — the PR description calls this out explicitly: "the next reader auditing the guard against a fixed bug concludes the guard is obsolete and removes it." The same failure mode now exists for the opposite claim: a future reader (or agent) trusting the stale "unreachable from every caller" text has no way to tell it's wrong without independently re-deriving what ce25fb5's commit message already re-derived, and could act on it in either direction — reintroducing an environment-variable read of CLAUDE_PLUGIN_DATA (regenerating the original cross-plugin data-isolation break this whole PR chain fixed), or distrusting/removing the now-correct --data-root-file substitution path. Given this PR was revised twice specifically because of exactly this kind of trusted-but-wrong rationale, leaving a second, contradicting copy of the disproven claim in the merged diff is the same defect recurring inside the fix for it.

Suggested fix: replace worktree-create.sh#L231-L239 and CHANGELOG.md#L31-L39 with the corrected reasoning already present elsewhere in the same files (the --data-root-file/SKILL.md-substitution explanation at worktree-create.sh#L274-L297 / CHANGELOG.md#L16-L24), or delete the stale paragraphs outright rather than leaving two contradictory explanations of the same design decision in the merged history.

Severity: IMPORTANT · Confidence: High (directly quoted text from the current head, contradicting adjacent code/text in the same files, confirmed not touched by ce25fb5's diff via git show)

No other new security issues found

  • Injection / path handling: unchanged from prior passes — --root, --root-file, --data-root-file all flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion. The data-root value travels from SKILL.md substitution to the temp file via the Write tool's JSON string parameter (no shell parsing) exactly like the existing --root-file handoff.
  • --data-root-file NUL/newline handling: shares read_path_file with --root-file, already reviewed as sound; a new test (worktree-create.test.sh#L173-L228 region) pins the newline-rejection and literal-token-refusal cases specifically for this new flag.
  • Containment guard: unchanged logic; still independently proves placement regardless of which source won.
  • Precedence: a configured --root/--root-file still wins over --data-root-file (tested), so the fallback can't silently displace a user's deliberate choice.
  • No workflow files touched; no permission or trust-boundary changes in plugin.json, README.md, or evals.json beyond prose/description updates consistent with the new design (modulo the stale CHANGELOG paragraph above).

Note: as in my prior passes on this PR, I could not execute shellcheck or the test suite in this sandbox (command execution required approval unavailable in this lane) — this review is by static tracing of the diff and cross-referencing the cited probe document, not by running the code.

Conclusion: the previously-blocking CLAUDE_PLUGIN_DATA scoping finding remains resolved, and resolved more robustly than the prior revision (no reliance on repo topology that a ghq-style discovery layout could still defeat). One new IMPORTANT finding: two stale, self-contradicting copies of the now-disproven "the plugin data dir is unreachable from every caller" rationale remain in worktree-create.sh and CHANGELOG.md, which is worth cleaning up before merge given this PR's own stated concern about exactly this failure mode.

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 4m 51s —— View job


Reviewing PR #1853 (code-review lane, re-review at ce25fb5)

  • Gather context (diff vs origin/main, prior review threads)
  • Understand what changed in the latest commit (ce25fb5) — reverses the prior "derive from repo" approach in favor of an explicit --data-root-file handoff
  • Review the new approach for correctness/maintainability
  • Check previously-flagged nits and whether they're now moot
  • Post final findings

Review

ce25fb5 is a third design for the unconfigured-root fallback. b9cb956 derived the default from $toplevel (<parent-of-checkout>/worktrees) to close the P1 that ${CLAUDE_PLUGIN_DATA} isn't reliably scoped in a Bash-tool subprocess. This commit reverses that: the CHANGELOG (CHANGELOG.md#L26-L29) explains the repo-derived default was itself rejected — it lands inside a ghq-style discovery tree (<root>/github.com/<owner>/<repo>), and ghq list then enumerates each worktree as a repository of its own. The new answer is <plugin-data-dir>/worktrees again, but reached differently: the skill substitutes ${CLAUDE_PLUGIN_DATA} into SKILL.md's own body (confirmed renderable in skill content by this repo's own docs/extensibility-contract-smoke-tests.md Test D), carries the resolved value down into context/create.md, and hands it to a new --data-root-file flag through the same byte-verbatim Write-tool channel --root-file already uses — never read from the ambient environment.

I traced the new logic end to end and the implementation itself is correct:

  • read_path_file is properly shared between --root-file and --data-root-file (worktree-create.sh#L183-L207), so the second channel inherits the same NUL/newline guards rather than a parallel, potentially-drifted copy.
  • Resolution order is right: root_unset detection (#L228-L230) happens before $toplevel is known (it doesn't need it anymore, but the ordering is harmless), and the --data-root-file read only happens inside the root_unset branch (#L263-L275) — a configured root always wins, matching the documented contract.
  • Fail-closed on a literal ${CLAUDE_PLUGIN_DATA} token (#L272): if the skill's substitution ever regresses, the helper detects the un-substituted token and falls through to refusal rather than creating a directory literally named after the token.
  • Regression coverage is solid: worktree-create.test.sh now covers a stray CLAUDE_PLUGIN_DATA not steering placement (#L182-L186), a data-root-file still holding the literal token refusing (#L197-L209), the discovery-tree-avoidance case, and both the --root/--root-file handoff paths plus the empty-content and unexpanded-token shapes reaching the same default.
  • My previously-flagged edge case is now moot: the "repo whose parent is itself part of another git working tree" interaction I raised against b9cb956 no longer applies — the default no longer derives from the repo's location at all.

Stale, self-contradicting rationale left over from the design this commit replaced (blocking)

Two spots still describe the previous ("derive from repo," data-dir "unreachable") design as if it shipped, and directly contradict the code/text right next to them:

  1. worktree-create.sh#L226-L239 — this comment block says "the fallback is derived from the repository's own location" and "the plugin data dir is unreachable from every caller this helper actually has... it substitutes only in hook/monitor/MCP paths, not skill content." Both claims are now false: the code ~30 lines below (#L263-L275) resolves the fallback from the plugin data directory via --data-root-file, and the whole point of this commit is that ${CLAUDE_PLUGIN_DATA} does substitute in skill content (SKILL.md's body) and is carried over explicitly. A future reader tracing "why isn't CLAUDE_PLUGIN_DATA used here" will read this block, conclude the data dir is unreachable, and be flatly contradicted by the next 40 lines.
  2. CHANGELOG.md#L31-L39 — the "Not ${CLAUDE_PLUGIN_DATA}..." paragraph still says "The token cannot be substituted into skill markdown and handed over either: it substitutes only in hook/monitor/MCP paths... The repository checkout is the one root every caller can actually reach." This directly contradicts the paragraph immediately above it (#L16-L24, "The data directory is supplied, not read from the environment... The skill instead substitutes ${CLAUDE_PLUGIN_DATA} into its own SKILL.md body, where it does render per-plugin") and the rejected-repo-derived-default paragraph right before it (#L26-L29). This looks like leftover text from the very first draft (95d604c) that survived two subsequent rewrites without being deleted.

Both should be removed or rewritten to match the shipped design — leaving them risks a future change re-deriving "wrong" conclusions from stale reasoning that reads as authoritative.

Fix this →

Nits (non-blocking)

  • Leftover "derived default" wording in worktree-create.test.sh at #L641 ("--root-file with empty content reaches the derived default") and #L661 ("resolve to the derived default rather than refuse") — same leftover terminology from the b9cb956 revision; the default is no longer "derived," it's the supplied plugin data dir. Test logic itself is correct and unaffected.
  • The central new claim — that ${CLAUDE_PLUGIN_DATA} substitutes in SKILL.md's own body but not in a context/*.md file read later via the Read tool — is plausible (progressive-disclosure reference files are plain reads, not re-rendered) and consistent with docs/extensibility-contract-smoke-tests.md Test D for the SKILL.md-body half, but unlike every other empirical claim in this PR, this specific SKILL.md-vs-context-file distinction has no recorded probe in that doc. Given this is the third attempt at this fallback, worth a one-line addition to the smoke-tests doc if it's easy to verify — not blocking, since CLAUDE.md's fresh-docs mandate scopes this SKILL.md prose-body claim as out of scope for citation.
  • Previously-flagged low-priority item still open and unaffected by this commit: the upstream-drift record in SKILL.md still doesn't cross-link docs/conventions/upstream-drift/README.md or appear in its Adopters table.

I was unable to run shellcheck or the test suite directly in this sandbox (commands required approval not available in this lane); verified via static tracing instead, consistent with prior passes on this PR.

Conclusion: the redesign itself is sound and well-tested, but the stale rationale in worktree-create.sh and CHANGELOG.md should be cleaned up before merge — it actively misleads a future reader about how the fallback is reached.

@kyle-sexton

Copy link
Copy Markdown
Member Author

Reworked in ce25fb5 — the P1 stands, and my first fix for it was also wrong.

What I got wrong twice. The original draft read CLAUDE_PLUGIN_DATA from the environment (the reported P1). My first correction derived the root from the repository instead, on the premise that the plugin data dir was simply unreachable from a skill. That premise was false and I had verified only half of it — I trusted plugins/architecture's changelog claim that the token "does not substitute in skill markdown content" instead of checking this repo's own probe.

${CLAUDE_PLUGIN_DATA} does substitute in a SKILL.md body: docs/extensibility-contract-smoke-tests.md Test D records it substituting while unset ${user_config.*} tokens stayed literal, and plugins/x/skills/read/SKILL.md relies on it in production, noting "this file is the only surface where that expands". What does not substitute is a context/ file, read as raw bytes — which is what the architecture entry actually observed and overgeneralized.

The design now. SKILL.md's body carries the token; the skill writes the resolved path to a second temp file; the helper takes it via a new --data-root-file. A configured root always wins, the data dir is only the fallback, and <data-dir>/worktrees is the default. Fail-closed: if substitution ever regresses the file holds the literal token, which the helper detects and refuses rather than creating a literally-named directory.

The repository-derived default is gone for an independent reason. Under a discovery layout like ghq's <root>/github.com/<owner>/<repo>, a checkout sibling lands inside the tree the discovery tool walks. Verified against a fixture — ghq list reported the worktree as a repository of its own, and a leading dot did not hide it. That is exactly the pollution this skill tells users to keep a configured root clear of.

Also folded in: the two file channels share one reader, so --data-root-file inherits --root-file's NUL/newline/missing-file guards. That reader assigns to a global rather than echoing — an exit inside a $( ) capture kills only the subshell, which would have turned every guard into a silent empty value. I probed that before relying on it.

153 assertions pass, 0 fail, shellcheck clean. New cases: literal-token refusal, precedence, missing data-root-file (exit 2), newline in it (exit 2, payload never executed), no-root-at-all (exit 3). Eight fail against the pre-change helper.

…ifiable

CI caught this: the case passed on Windows and failed on Linux. Both
outcomes were wrong for the same reason — the fixture put the fake plugin
data dir under the same temp tree as the repository, so "the worktree
escapes the repository's ancestry" was either unfalsifiable (Windows, where
the two path spellings differed and the `case` glob never matched) or
trivially false (Linux, where they matched).

The fixture now mirrors the layout it claims to test: a checkout nested at
<discovery-root>/github.com/<owner>/<repo>, with the data dir in its own
mktemp tree outside it, as a real plugin data dir is. Proved falsifiable by
pointing the data dir back inside the discovery root and confirming the
assertion fires.

154 assertions pass.
@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 26s —— View job


Security review of PR #1853 (re-review at 8a758cf)

  • Gather context (diff vs origin/main, prior review findings)
  • Check what changed since the last reviewed commit (ce25fb5)
  • Review remaining diff for new security issues
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD), current head 8a758cf.

What changed since my last security pass (ce25fb5)

Only one new commit, 8a758cf, and it touches exactly one file: plugins/source-control/scripts/worktree-create.test.sh (+38/-9). Confirmed via git rev-parse HEAD:<path> that worktree-create.sh (ec89a44...) and CHANGELOG.md (c349dfa...) are byte-identical to what I reviewed at ce25fb5 — no production code changed.

The commit itself is a test-fixture fix, not new functionality: CI caught that the "discovery-root" regression case shared a temp-directory ancestry between the fake plugin data dir and the fixture repo, making the assertion unfalsifiable on Windows and trivially true on Linux. The fix gives the fake data dir its own mktemp -d tree, outside the discovery-root fixture, and nests the fixture repo two levels deep (<discovery-root>/github.com/acme/widget) to mirror a real ghq-style layout. The commit message documents proving falsifiability by pointing the data dir back inside the discovery root and confirming the assertion then fires — that's sound test hygiene, and it's test-only code with no execution path in the shipped helper, so it carries no security surface of its own.

Previously-flagged finding: still open, unaffected by this commit

My prior pass (at ce25fb5) raised an IMPORTANT finding that two spots contain rationale left over from an earlier, since-abandoned design and directly contradict the code/text next to them. Re-verified against current head — both are still present, unchanged:

  1. worktree-create.sh#L226-L239 still says "the fallback is derived from the repository's own location" and "the plugin data dir is unreachable from every caller this helper actually has... it substitutes only in hook/monitor/MCP paths, not skill content." Both claims are contradicted by the code ~30 lines below (#L274-L297), which resolves the fallback from the plugin data directory via --data-root-file, sourced from a SKILL.md-body substitution.
  2. CHANGELOG.md#L31-L39 (the "Not ${CLAUDE_PLUGIN_DATA}..." paragraph) still contradicts the paragraph directly above it (#L16-L24) describing the shipped --data-root-file design.

Why this still matters as a security finding rather than a style nit: this PR's whole second workstream exists specifically to correct stale rationale that could mislead a future reader into removing a still-load-bearing guard. The same failure mode applies here in the opposite direction — stale text claiming the plugin data dir is "unreachable" could lead a future change to reintroduce an ambient ${CLAUDE_PLUGIN_DATA} environment read (regenerating the original cross-plugin data-isolation break this PR chain fixed), since the comment offers no signal that it's obsolete.

Severity: IMPORTANT · Confidence: High (directly quoted text from the current head, contradicting adjacent code/text in the same files; unresolved across three consecutive commits since it was first flagged)

Suggested fix (unchanged): replace or delete worktree-create.sh#L226-L239 and CHANGELOG.md#L31-L39, keeping only the corrected reasoning already present at worktree-create.sh#L274-L297 / CHANGELOG.md#L16-L24.

Fix this →

No other new security issues found

  • Injection / path handling: unchanged from prior passes — --root, --root-file, --data-root-file all flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion.
  • Test fixture changes (worktree-create.test.sh) use mktemp -d, local git repos, and controlled fixture data only — no untrusted input, no new subprocess trust boundary.
  • Containment guard: unchanged logic; still independently proves placement via git rev-parse --show-toplevel/--is-inside-git-dir regardless of which root wins.
  • No workflow files touched anywhere in this PR; no permission or trust-boundary changes in plugin.json, README.md, SKILL.md, context/create.md, or evals.json beyond the already-reviewed prose/description updates.

Note: as in prior passes on this PR, I could not execute shellcheck or the test suite in this sandbox (command execution required approval unavailable in this lane) — verified by static tracing and git rev-parse blob-identity checks instead.

Conclusion: the previously-blocking CLAUDE_PLUGIN_DATA scoping finding remains resolved. One IMPORTANT finding carries over unresolved from my last pass: stale, self-contradicting rationale in worktree-create.sh and CHANGELOG.md describing an abandoned design — worth cleaning up before merge, since this PR's own stated purpose is correcting exactly this kind of misleading rationale. The one new commit (8a758cf) is a test-only fix with no security surface.

@kyle-sexton

Copy link
Copy Markdown
Member Author

@codex review

The P1 on the worktree_root fallback is addressed in ce25fb5, and the approach changed twice in response to it — please re-check against the current head rather than the original diff.

What changed since your finding:

  1. The env read is gone. CLAUDE_PLUGIN_DATA is no longer consulted anywhere in the helper. Your citation of docs/extensibility-contract-smoke-tests.md was correct: in a Bash-tool subprocess it is not per-plugin, and every caller of this helper runs in one (the skill at context/create.md, orchestrated workers per SKILL.md) — there is no WorktreeCreate hook in this plugin today.

  2. An intermediate fix was also wrong and has been replaced. I first derived the root from the repository (<parent>/worktrees). That independently violated the skill's own discovery-root convention: under a ghq layout it lands inside the tree ghq list walks, which I confirmed against a fixture — the worktree was enumerated as a repository of its own, and a leading dot did not hide it.

  3. Current design. ${CLAUDE_PLUGIN_DATA} is substituted in the worktree SKILL.md body, where it does render per-plugin (Test D in the same smoke-test doc; plugins/x/skills/read/SKILL.md relies on this in production). The skill writes the resolved path to a temp file and passes it via a new --data-root-file. A configured root always wins; the data dir is only the fallback. Fail-closed — if substitution regresses, the file carries the literal token, which the helper detects and refuses rather than creating a literally-named directory.

Both file channels now share one reader, so --data-root-file inherits --root-file's NUL/newline/missing-file guards. That reader assigns to a global rather than echoing, because an exit inside a $( ) capture kills only the subshell — I probed that before relying on it.

154 assertions pass, shellcheck clean. New coverage: literal-token refusal, precedence, missing data-root-file (exit 2), newline in it (exit 2, payload never executed), no-root-at-all (exit 3). Eight fail against the pre-change helper.

Worth your attention specifically: whether the substitution channel is sound for an installed plugin (Test D's rig was --plugin-dir), and whether the shared reader's global-assignment contract is airtight.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a758cffda

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plugins/source-control/CHANGELOG.md Resolved
The 0.45.0 release note and the helper comment still carried the paragraph
from the intermediate repository-derived design, asserting that
${CLAUDE_PLUGIN_DATA} cannot be substituted into skill markdown and that the
repository checkout is the only reachable root. What shipped does the
opposite: the skill substitutes the token in its own SKILL.md body and hands
the value over via --data-root-file.

Left in place, the release notes contradicted themselves one paragraph
apart and told a maintainer the wrong thing about how the default resolves.
The surviving text already explains the reachability constraint correctly
where it belongs — at the resolution block and in the entry above.
@kyle-sexton

Copy link
Copy Markdown
Member Author

P2 fixed in c20ec77 — the finding was correct.

Both surfaces still carried the rationale from the discarded intermediate design (the repository-derived root), asserting that ${CLAUDE_PLUGIN_DATA} cannot be substituted into skill markdown and that the checkout is the only reachable root. What shipped does the opposite. Left in place, the 0.45.0 notes contradicted themselves one paragraph apart and would have told the next maintainer the wrong thing about how the default resolves.

Removed from both CHANGELOG.md and the worktree-create.sh comment block. The reachability constraint is still explained where it belongs — at the resolution block, and in the release entry above it. Swept for other survivors of that design; none left.

154 assertions pass, shellcheck and markdownlint clean.

@claude

claude Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @kyle-sexton's task in 1m 19s —— View job


Security review of PR #1853 (re-review at c20ec77)

  • Gather context (diff vs origin/main, prior findings)
  • Verify the P2 stale-rationale fix (c20ec77) actually removed the contradictions
  • Re-check the resolved P1 (CLAUDE_PLUGIN_DATA scoping) is still sound at current head
  • Review remaining diff for new security issues
  • Post findings

Security review

Scope: files changed in this PR relative to origin/main (git diff origin/main...HEAD), current head c20ec77.

What changed since my last security pass (8a758cf)

One new commit, c20ec77, touching only CHANGELOG.md (-10 lines) and worktree-create.sh (-13/+1 lines). It's the fix for the IMPORTANT finding I (and Codex, independently) raised on the prior head: both files carried a leftover paragraph from the discarded repository-derived design, asserting ${CLAUDE_PLUGIN_DATA} "cannot be substituted into skill markdown" and "unreachable from every caller" — directly contradicted by the --data-root-file mechanism that actually shipped a few lines away.

I verified the fix directly rather than trusting the commit message:

  • worktree-create.sh#L263-L287 is now the sole explanation of why the env var isn't read, and it matches the shipped mechanism exactly: not scoped in a Bash-tool subprocess (env read), but reachable via ${CLAUDE_PLUGIN_DATA} substitution in SKILL.md's own body, carried down through --data-root-file.
  • CHANGELOG.md#L16-L24 — the deleted "Not ${CLAUDE_PLUGIN_DATA}" paragraph is gone; the surviving "The data directory is supplied, not read from the environment" paragraph directly above it already carries the correct account and is now the only one.
  • Swept the whole plugin directory for surviving fragments of the old claim ("cannot be substituted", "unreachable from every caller", "only reachable root") — the only remaining hit is the still-correct explanatory comment at worktree-create.sh#L268, not contradicted anywhere else in the diff.

This closes both my own recurring finding and chatgpt-codex-connector's P2 on the same text.

Re-verified: the originally-flagged P1 (CLAUDE_PLUGIN_DATA scoping) remains resolved

Tracing the full current data flow end to end once more, now that the misleading comments are gone:

  • The helper (worktree-create.sh#L287-L321) never reads CLAUDE_PLUGIN_DATA from its process environment; the fallback root comes exclusively from --data-root-file, read via read_path_file — the same NUL/newline-guarded, byte-verbatim reader --root-file uses (shared code, not a parallel copy).
  • The value reaches that file via SKILL.md#L92 substituting ${CLAUDE_PLUGIN_DATA} in the skill's own body (the surface this repo's docs/extensibility-contract-smoke-tests.md Test D confirms renders per-plugin), then context/create.md#L81 writes the already-resolved value via the Write tool (JSON string parameter — no shell parsing) to a mktemp -d temp file, never re-deriving it from the environment.
  • Fail-closed: a literal, un-substituted ${CLAUDE_PLUGIN_DATA token is detected (worktree-create.sh#L297) and treated as absent rather than used as a relative path.
  • Whichever root wins is still independently proven by the unchanged containment guard (git rev-parse --show-toplevel/--is-inside-git-dir), so a bug anywhere upstream of it can't silently place a worktree inside a repository.

No new or open security issues

  • Injection / path handling: unchanged — --root, --root-file, --data-root-file all flow into git worktree add / cp / mkdir -p as literal argv values, never through eval or unquoted expansion; the Write-tool handoff for both the configured root and the data-root value avoids the shell entirely (documented explicitly at context/create.md#L71, covering the O'Connor-apostrophe/backtick/heredoc-delimiter injection class).
  • Temp-file handling: mktemp -d + rm -rf cleanup after capturing $? before the cleanup runs (create.md#L86-L89), so a helper refusal (exit 3) can't be masked by rm's own exit code.
  • Containment guard: unchanged logic; still independently verifies placement regardless of which root source wins.
  • No workflow files touched anywhere in this PR; no permission or trust-boundary changes in plugin.json, README.md, or evals.json beyond prose/description updates already reviewed as consistent with the shipped design.

Note: as in prior passes on this PR, I could not execute shellcheck or the test suite in this sandbox (command execution required approval unavailable in this lane) — verified by static tracing and direct diff/blob inspection instead.

Conclusion: no open security findings on this PR as of c20ec77. The previously-blocking CLAUDE_PLUGIN_DATA scoping issue remains resolved and regression-tested, and the stale/self-contradicting rationale I flagged on the prior head (also caught independently by chatgpt-codex-connector) is now fully removed with no surviving contradictions.

@kyle-sexton
kyle-sexton merged commit 2d4e276 into main Jul 31, 2026
1 check passed
@kyle-sexton
kyle-sexton deleted the fix/worktree-root-default branch July 31, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(source-control): unset worktree_root refuses every /worktree create instead of defaulting

1 participant