Skip to content

fix(source-control): route worktree create and remove through native tools under the sandbox - #18290

Merged
kyle-sexton merged 3 commits into
mainfrom
fix/worktree-sandbox-route-17901
Nov 23, 2026
Merged

kyle-sexton merged 3 commits into
mainfrom
fix/worktree-sandbox-route-17901

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Closes #17901

Summary

The sandbox refuses the worktree skill's Bash git worktree add and git worktree remove, and a commit run from the main checkout into a worktree (probe, Claude Code 2.1.330). The skill now states a route for sandboxed sessions.

Fix

  • New ## Sandboxed sessions section in plugins/source-control/skills/worktree/SKILL.md, the route the owner chose: inside a git repository, create uses EnterWorktree(name:) and removal of that worktree uses ExitWorktree(action: "remove"), with discard_changes: true when it holds commits. Outside a git repository the tools fail, so the skill reports that and stops instead of falling back to Bash git worktree. Unsandboxed sessions keep the helper and EnterWorktree(path:) route.
  • Placement is stated for both cases: this plugin's WorktreeCreate hook runs outside the sandbox and places the worktree at the external root through the shared helper; with that hook not running, Claude Code uses <repo>/.claude/worktrees/. Removal runs the read-only stranded-work and carried-file guards, then down, then ExitWorktree, whose WorktreeRemove hook reaps install records and keeps the branch. Other cleanup candidates are reported for an unsandboxed session.
  • Pointers to the sandboxing and hooks pages instead of restated behavior; the probe observation carries its as-of date and recheck trigger.
  • One-line pointers from context/create.md and context/cleanup.md Step 4a.
  • The edit adds text only (no rewording of existing instructions), so no eval run is required under docs/review/evals.md.

Verification

  • scripts/check-as-of-recheck.sh --check: pass.
  • scripts/check-changed-links-online.sh origin/main: 5 changed external links resolve.
  • scripts/check-skill-portability.sh origin/main, scripts/check-purged-em-dashes.sh: pass.
  • skills/worktree/nesting-invariant-ssot.test.sh: 22 cases, 0 failures.
  • scripts/check-affected.sh --base origin/main: 22 passed, 2 skipped.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits November 22, 2026 21:17
…tools under the sandbox

The sandbox refuses Bash git worktree add and remove, and a commit run
from the main checkout into a worktree. In a sandboxed session inside a
git repository, the worktree skill now creates with EnterWorktree(name:)
and removes that worktree with ExitWorktree(action: "remove"), passing
discard_changes when it holds commits. Outside a repository it stops
instead of falling back to Bash. Unsandboxed sessions keep the helper
route.

Refs: #17901

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Move the sandbox exception into the new section as an explicit override
instead of rewording the create invariants, Routing and Mutation gate
lines, so the change adds text only. Point at the sandboxing page to
tell whether commands run sandboxed, order the sandboxed removal as the
read-only guards, down, then ExitWorktree (whose hook reaps), and say
what happens with no hook and when the offered push fails.

Refs: #17901

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 23, 2026 02:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T02:29:35.282790Z 7eb4ae8 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 7eb4ae89a7

ℹ️ 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".

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 543352fbeb8cccad871c49dba0384a2e530364e3: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Security review (incremental, blocking only): no security issues found

This review covers only what changed since 7eb4ae89. I read every hunk of the three files in the incremental diff:

  • .changes/source-control/fix-worktree-sandbox-route-8d41c6a2.md
  • plugins/source-control/skills/worktree/SKILL.md
  • plugins/source-control/skills/worktree/context/cleanup.md

All three changes are instruction text. No code, hooks, manifests, workflows or trust controls change, and none of the files matches a trusted-path glob. Because this lane already reviewed an earlier head, the review was blocking only.

Instruction-surface lens. I checked each rule the push narrowed or reworded by what breaks when it is gone:

  • "Never fall back to Bash git worktree" became "Outside one, report and stop." The rule that stops the session is still there, so no path now reaches a refused Bash worktree command. Even if one did, the sandbox refuses those commands anyway.
  • The discard_changes: true wording and the "hook not running, remove deletes the branch" caveat were replaced with links to the live docs. Removal is still limited to the worktree this session created by name. The read-only stranded-work and carried-file guards still run first, and the WorktreeRemove hook still does the reap. At worst this is a data-loss question, not a leak, compromise or charge.
  • Cleanup now skips worktree-claim.sh stale for this session's own claim. Ownership is still enforced: the WorktreeRemove gate refuses a lock naming another session (plugins/source-control/hooks/worktree-remove-gate.sh, as the settled thread cites). No other session's worktree becomes removable. This change resolves this lane's earlier thread on cleanup.md:105, which is settled with lines unchanged.
  • New: sessions that need worktree.baseRef: head stop. This adds a check rather than removing one.

docs/contracts/instruction-exception-register/README.md was not consulted. I judged each change by its consequence instead.

PR context and settled threads. I found no embedded directives aimed at the review.

Owner threat model. This push touches no friction hold.

Spend: none beyond this review run.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 1 inline finding(s) on 7eb4ae89a72d8ff4b02d48dd1e56f5d4dc477662; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 543352fbeb8cccad871c49dba0384a2e530364e3: read 3 of 3 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #18290, incremental (7eb4ae8..543352f)

No blocking findings in this push. This lane already reviewed an earlier head, so this review covered blocking findings only and dropped advisory ones.

This push changes three files:

  • plugins/source-control/skills/worktree/SKILL.md (the ## Sandboxed sessions section)
  • plugins/source-control/skills/worktree/context/cleanup.md (the Step 4a sandboxed paragraph)
  • the changelog fragment

I read every hunk of all three in the incremental diff.

Both earlier findings are fixed.

  • worktree.baseRef on the sandboxed create. SKILL.md:170-176 now says the create hook uses the helper's fresh base for a new branch. It also tells the session to resolve worktree.baseRef first, and to stop and report when the session needs head. The owner settled this thread, and the new text matches the reply.
  • The stale proof blocking sandboxed removal. cleanup.md:105-110 now names guard 1 and guard 2's carried-file comparison and skips worktree-claim.sh stale for the session's own claim. It hands foreign-lock refusal to the WorktreeRemove gate. That matches SKILL.md's "stranded-work and carried-file guards". The relative link ../../../hooks/worktree-remove-gate.sh points to plugins/source-control/hooks/worktree-remove-gate.sh, which exists.

Other checks.

  • The changelog fragment describes what this head ships.
  • The context/create.md#base-branch anchor resolves to the ## Base branch heading.
  • The as-of date and recheck trigger on the probe observation are unchanged.

Closing issue #17901.

  • Done-when 2 (the skill states the chosen route for sandboxed sessions, with a pointer and recheck trigger) is still met.
  • Done-when 1 (the owner's route choice) is cited only by the author. I have not verified it.

Housekeeping.

  • The PR body still says removal passes discard_changes: true when the worktree holds commits. This push dropped that line from SKILL.md in favor of the live WorktreeRemove docs link. The description is now slightly out of date. This is not counted as a finding.
  • Loosened checks would be marked fail: that is the default, since the prompt has no loosened_check_verdict: or loosened_check_patterns: lines. Consumer patterns: 0. No changed line loosens a check. The prompt has no loosened_check_decision_record: line, so I did not check the citation requirement.
  • No plugin manifest changed.
  • The PR context, settled threads and prior findings contain no embedded instructions to the lane.

Verifier dropped 0 of 0 candidates.

…andbox worktree route

Native create states its fresh base and stops when worktree.baseRef is head; upstream behavior moves to section links; sandboxed cleanup skips the stale proof for the session's own claim.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 23, 2026
Merged via the queue into main with commit 502aa49 Nov 23, 2026
60 checks passed
@kyle-sexton
kyle-sexton deleted the fix/worktree-sandbox-route-17901 branch November 23, 2026 04:42
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

source-control: worktree skill's git worktree add/remove run through Bash, which the 2.1.323 sandbox refuses as read-only

1 participant