fix(worktree): link main checkout's .env into fresh worktrees on setup - #125
Merged
Conversation
Isolated implementer/reviewer worktrees are fresh checkouts, and .env is gitignored — so it never appears in them, and any gate or script that needs its credentials (GH_BOT_TOKEN, RPC URLs, ...) fails for lack of setup rather than a real defect. worktree.sh setup now symlinks the main checkout's .env into the worktree (same pattern prepare-pr.sh already uses for test-pr worktrees): resolved from the caller's cwd so it works in both the repo-tracked and plugin-cache layouts, best-effort, and skip-if-present so a worktree-local .env always wins. Runs before the adapter checks so unconfigured repos get it too. Ships in the plugin's scripts/ — consumers pick it up on plugin update with no adapter (gates.json) change needed. Adds worktree.test.sh (auto-discovered by checks.sh test): 11 checks covering fresh-worktree link, local-.env precedence, main-checkout no-op, missing-.env no-op, teardown no-op, and gitignore coverage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
robercano
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Subagents working in isolated worktrees (implementers, reviewers, test-runners) can't run tasks that need credentials:
.envis gitignored, so a freshgit worktree addcheckout never contains it, and gates/scripts fail for lack ofGH_BOT_TOKEN/ RPC URLs rather than real defects.Fix
worktree.sh setupnow symlinks the main checkout's.envinto the worktree — the same patternprepare-pr.shalready uses for test-pr worktrees.git rev-parse --show-toplevel+--git-common-dir), not$root, so it works in both the repo-tracked and plugin-cache layouts (issue scripts break when run from the plugin install cache (CLAUDE_PLUGIN_ROOT): root derived as ../.. conflates plugin root with consumer project root #63 territory).gates.jsonworktree.setupget it too..envalways wins; no main.env→ clean no-op; main checkout → no self-link.scripts/, so consumers get it on plugin update with no adapter change — deliberately NOT in the user-ownedgates.json(created once, never re-stamped).Tests
New
worktree.test.sh(auto-discovered bychecks.sh test): 11 checks — fresh-worktree link + content, local-.envprecedence, main-checkout no-op, missing-.envno-op, teardown no-op, andcheck-ignoreconfirming the link stays gitignored.Gates run locally:
build✅lint✅test(all script smokes incl. new one) ✅smoke-fanout✅Supersedes #123 (same branch — recreated bot-authored so the owner can approve).
🤖 Generated with Claude Code