Skip to content

fix(preview): make the worktree preview launcher work from a linked worktree#1503

Merged
dawsontoth merged 3 commits into
stagefrom
fix/preview-worktree-node
Jul 14, 2026
Merged

fix(preview): make the worktree preview launcher work from a linked worktree#1503
dawsontoth merged 3 commits into
stagefrom
fix/preview-worktree-node

Conversation

@dawsontoth

Copy link
Copy Markdown
Contributor

What

Three fixes to .claude/preview-worktree.sh (the studio (worktree) preview launch helper) so the dev server actually starts when launched from a linked worktree on port 5173.

Each bug independently prevented the preview from starting from a fresh worktree this session:

  1. Self-referential node_modules symlink → ELOOP. The helper symlinks node_modules/.env.local "from the main checkout," but it used $root = CLAUDE_PROJECT_DIR, which is the current checkout — i.e. the worktree itself. So the link pointed a worktree at its own node_modules and pnpm crashed with ELOOP: too many symbolic links. Now derives the real main checkout from git rev-parse --git-common-dir.
  2. Old default Node vs pnpm 11. The launcher can inherit an older default Node than pnpm 11 requires (>=22.13); a v20 default crashed pnpm at import (node:util … styleText). Now prepends the repo's pinned .nvmrc Node (or the newest installed nvm Node >=22) to PATH when the active node is too old.
  3. pnpm purging the shared node_modules. pnpm's pre-run deps check saw a workspace-state mismatch (the symlink points at the main checkout) and tried to reinstall/purge node_modules — which would mutate the shared main checkout. Now skipped via --config.verify-deps-before-run=false.

Why

Discovered while using preview_start "studio (worktree)" to review another PR — the launcher failed on all three in sequence from a clean worktree, and #3 risked mutating the shared main-checkout node_modules.

Testing

  • bash -n clean; git rev-parse --git-common-dir resolves the main checkout correctly from a worktree.
  • The pre-commit hook suite ran green on this tree (218 files / 1482 tests, oxlint, dprint, commitlint).
  • Verified live earlier: with all three fixes the worktree preview comes up on :5173 and backend auth carries over.

Notes

  • Touches only .claude/preview-worktree.sh (dev tooling; no product/runtime code).
  • The commit is unsigned — GPG couldn't prompt for a passphrase in the non-interactive session it was created in.

🤖 Generated with Claude Code

…orktree

The "studio (worktree)" launch helper (.claude/preview-worktree.sh) failed to
start when run from a linked worktree:

- node_modules/.env.local were symlinked from $root (CLAUDE_PROJECT_DIR), which
  is the worktree itself — so the link pointed a worktree at its own node_modules
  and pnpm hit ELOOP. Derive the real main checkout from
  `git rev-parse --git-common-dir` instead.
- The launcher can inherit an older default Node than pnpm 11 requires (>=22.13);
  prepend the repo's pinned .nvmrc Node (or newest installed >=22) to PATH when
  the current node is too old.
- pnpm's pre-run deps check tried to reinstall/purge the symlinked node_modules
  (workspace-state mismatch), which would mutate the shared main checkout; skip it
  with --config.verify-deps-before-run=false.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dawsontoth
dawsontoth requested a review from a team as a code owner July 14, 2026 16:12
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 49.1% 4922 / 10024
🔵 Statements 49.52% 5246 / 10593
🔵 Functions 40.97% 1188 / 2899
🔵 Branches 42.22% 3231 / 7652
File CoverageNo changed files found.
Generated in workflow #1492 for commit baf5d61 by the Vitest Coverage Report Action

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the .claude/preview-worktree.sh script to correctly resolve the main git checkout when launched from a worktree, preventing symlink loops. It also ensures a compatible Node.js version (>=22) is used from NVM if the default version is too old, and configures pnpm to skip dependency verification to avoid mutating the shared node_modules. Feedback points out a portability issue on macOS where sort -V is unsupported and will cause a crash, and a bug where a leading 'v' in .nvmrc would break the NVM directory lookup.

Comment thread .claude/preview-worktree.sh Outdated
Comment thread .claude/preview-worktree.sh
Addresses review feedback on #1503:
- Replace `sort -Vr` (a GNU / newer-BSD extension that stock `sort` on older
  macOS lacks) with a portable numeric sort, so the newest-installed-Node
  fallback can't crash under `set -e`.
- Strip a leading `v` from the parsed `.nvmrc` value (`${want#v}`), so a
  `vX.Y.Z`-style pin resolves to the correct nvm directory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread .claude/preview-worktree.sh Outdated
…ppened

Addresses review nit on #1503: the "Adjusted PATH to Node …" message printed
unconditionally inside the <22 block, even when neither the .nvmrc dir nor the
nvm fallback matched — falsely claiming success in the one case an operator
most needs accurate output. Track whether PATH actually changed (`adjusted`)
and gate the message on it, warning clearly otherwise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dawsontoth
dawsontoth added this pull request to the merge queue Jul 14, 2026
Merged via the queue into stage with commit 15aac8c Jul 14, 2026
2 checks passed
github-merge-queue Bot pushed a commit that referenced this pull request Jul 14, 2026
Addresses review feedback on #1503:
- Replace `sort -Vr` (a GNU / newer-BSD extension that stock `sort` on older
  macOS lacks) with a portable numeric sort, so the newest-installed-Node
  fallback can't crash under `set -e`.
- Strip a leading `v` from the parsed `.nvmrc` value (`${want#v}`), so a
  `vX.Y.Z`-style pin resolves to the correct nvm directory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dawsontoth
dawsontoth deleted the fix/preview-worktree-node branch July 14, 2026 21:43
dawsontoth added a commit that referenced this pull request Jul 22, 2026
Addresses review feedback on #1503:
- Replace `sort -Vr` (a GNU / newer-BSD extension that stock `sort` on older
  macOS lacks) with a portable numeric sort, so the newest-installed-Node
  fallback can't crash under `set -e`.
- Strip a leading `v` from the parsed `.nvmrc` value (`${want#v}`), so a
  `vX.Y.Z`-style pin resolves to the correct nvm directory.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
dawsontoth added a commit that referenced this pull request Jul 22, 2026
…ppened

Addresses review nit on #1503: the "Adjusted PATH to Node …" message printed
unconditionally inside the <22 block, even when neither the .nvmrc dir nor the
nvm fallback matched — falsely claiming success in the one case an operator
most needs accurate output. Track whether PATH actually changed (`adjusted`)
and gate the message on it, warning clearly otherwise.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants