fix(preview): make the worktree preview launcher work from a linked worktree#1503
Merged
Conversation
…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>
Coverage Report
File CoverageNo changed files found. |
Contributor
There was a problem hiding this comment.
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.
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>
cb1kenobi
reviewed
Jul 14, 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>
cb1kenobi
approved these changes
Jul 14, 2026
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
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>
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.
What
Three fixes to
.claude/preview-worktree.sh(thestudio (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:
node_modulessymlink →ELOOP. The helper symlinksnode_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 ownnode_modulesand pnpm crashed withELOOP: too many symbolic links. Now derives the real main checkout fromgit rev-parse --git-common-dir.>=22.13); a v20 default crashed pnpm at import (node:util … styleText). Now prepends the repo's pinned.nvmrcNode (or the newest installed nvm Node>=22) toPATHwhen the active node is too old.node_modules. pnpm's pre-run deps check saw a workspace-state mismatch (the symlink points at the main checkout) and tried to reinstall/purgenode_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-checkoutnode_modules.Testing
bash -nclean;git rev-parse --git-common-dirresolves the main checkout correctly from a worktree.Notes
.claude/preview-worktree.sh(dev tooling; no product/runtime code).🤖 Generated with Claude Code