Repository navigation
fix(source-control): default an unset worktree_root instead of refusing - #1853
Conversation
`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.)
There was a problem hiding this comment.
💡 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 finished @kyle-sexton's task in 2m 24s —— View job Reviewing PR #1853
ReviewThis 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 ( 1.
|
|
Claude finished @kyle-sexton's task in 3m 12s —— View job Claude is reviewing this PR
Security reviewScope: only the files changed in this PR ( IMPORTANT — unset-
|
|
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 finished @kyle-sexton's task in 1m 38s —— View job Security review of PR #1853
Security reviewScope: files changed in this PR relative to IMPORTANT — unset-
|
|
Claude finished @kyle-sexton's task in 2m 20s —— View job Reviewing PR #1853 (code-review lane)
ReviewScope: files changed vs On correctness, error handling, test coverage, and maintainability, this change is solid:
Two minor/non-blocking items:
Nothing here blocks merge from a correctness/maintainability standpoint; the one item that does block (per the security lane) is the |
…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 finished @kyle-sexton's task in 2m 36s —— View job Reviewing PR #1853 (code-review lane, re-review at
|
|
Claude finished @kyle-sexton's task in 1m 37s —— View job Security review of PR #1853
Security reviewScope: files changed in this PR relative to Previously-flagged finding: RESOLVEDMy last two passes on this PR (and Commit
This also fully addresses Remaining diff (doc/config/eval files) — no issues
No new security issues found
Conclusion: the previously blocking finding is resolved and independently regression-tested. No open security findings on this PR as of |
|
Fixed in b9cb956 — the P1 was correct, and worse than described. I checked the repo's own probe: The suggested remedy — substitute the token into skill markdown and hand it over via the non-shell channel — does not work either: The default now derives from the repository instead: a Regression guard added, and it reproduces the reported defect: with a stray |
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 finished @kyle-sexton's task in 1m 14s —— View job Reviewing PR #1853 (code-review lane, re-review at
|
|
Claude finished @kyle-sexton's task in 52s —— View job Security review of PR #1853 (re-review at
|
… 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 finished @kyle-sexton's task in 3m 48s —— View job Security review of PR #1853 (re-review at
|
|
Claude finished @kyle-sexton's task in 4m 51s —— View job Reviewing PR #1853 (code-review lane, re-review at
|
|
Reworked in ce25fb5 — the P1 stands, and my first fix for it was also wrong. What I got wrong twice. The original draft read
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 The repository-derived default is gone for an independent reason. Under a discovery layout like ghq's Also folded in: the two file channels share one reader, so 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 finished @kyle-sexton's task in 1m 26s —— View job Security review of PR #1853 (re-review at
|
|
@codex review The P1 on the What changed since your finding:
Both file channels now share one reader, so 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 |
There was a problem hiding this comment.
💡 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".
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.
|
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 Removed from both 154 assertions pass, shellcheck and markdownlint clean. |
|
Claude finished @kyle-sexton's task in 1m 19s —— View job Security review of PR #1853 (re-review at
|
Closes #1852
Summary
worktree_rootships unset and the helper refused outright when it was, so/worktree createwas 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 alreadybabysit_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-driftrecord (claim, basis including how to reproduce theInstructionsLoadedtrace, as-of date, recheck trigger) so the invariant can be re-derived rather than trusted.worktree_rootwas also missing from the README configuration table while every sibling key was listed.Verification
--rootand--root-file. The skill always writes a file, so a fallback reaching only--rootwould have left the common case broken; the empty-content and unexpanded-token file cases both assert the fallback now.CLAUDE_PLUGIN_DATAexplicitly cleared so the no-safe-root branch is exercised rather than skipped.shellcheck -xclean on both changed shell files.evals.jsonre-parsed as valid JSON after the contract update (2-line diff, no reformatting).One thing I did NOT do:
shfmtreports formatting drift onworktree-create.sh, but it does so on the unmodified file too — the repo does not runshfmton this plugin, and reformatting it would bury this change in noise.Related
babysit_worktree_root, defaulting to the plugin data dirdocs/conventions/upstream-drift/README.md— the record shape the corrected rationale takesUpdate 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:72records 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$toplevelis always reachable, and the parent of a checkout is outside the repository by construction. A regression guard pins it — a strayCLAUDE_PLUGIN_DATAmust not steer placement, and that assertion reproduces the reported defect against the old code.