fix(cli): resolve native-installer Claude binary instead of falling back to a stale install#1394
Open
AlexiFeng wants to merge 1 commit into
Open
fix(cli): resolve native-installer Claude binary instead of falling back to a stale install#1394AlexiFeng wants to merge 1 commit into
AlexiFeng wants to merge 1 commit into
Conversation
…ack to a stale install findClaudeInPath() treated any `which claude` result whose resolved path did not end in .js/.cjs/.exe as a Windows npm shim: it looked for an adjacent node_modules/@anthropic-ai/claude-code and returned null when none was found. On macOS/Linux that assumption is wrong. The native installer (>= 2.1.113) ships a self-contained, extensionless compiled binary at ~/.local/share/claude/versions/<ver>. It was therefore rejected, and findGlobalClaudeCliPath() silently fell back to a different — often older — installation (e.g. a stale Homebrew copy) even when `which claude` already pointed at the newer native binary. Gate the shim-redirect logic to win32, where extensionless npm shims actually exist. On other platforms the extensionless binary is used directly; runClaudeCli() already spawns non-JS entrypoints as binaries. Add regression tests covering native-binary resolution on macOS/Linux and unchanged npm cli.js resolution.
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
On macOS/Linux,
happycan launch an older Claude Code than the onewhich clauderesolves to.findClaudeInPath()inpackages/happy-cli/scripts/claude_version_utils.cjstakes the firstwhich clauderesult, resolves the symlink, and — if the resolved path doesn't end in.js/.cjs/.exe— assumes it's a Windows npm shim, looks for an adjacentnode_modules/@anthropic-ai/claude-code, and returnsnullwhen none is found.But the native installer (Claude Code ≥ 2.1.113) ships a self-contained, extensionless compiled binary at
~/.local/share/claude/versions/<ver>. That path is therefore wrongly rejected, andfindGlobalClaudeCliPath()silently falls through to the next finder — frequently a stale Homebrew copy.Repro
Native installer on
PATH(~/.local/bin/claude→~/.local/share/claude/versions/2.1.175) plus an oldbrew-installed@anthropic-ai/claude-code:findClaudeInPath()returnsnull, so resolution falls back to/opt/homebrew/.../cli.js(v1.0.102).Fix
Gate the shim-redirect branch to
win32, where extensionless npm shims actually exist. On every other platform an extensionless binary is the native installer and is used directly —runClaudeCli()already spawns non-JS entrypoints as binaries.After the change:
findClaudeInPath()→{ path: '~/.local/share/claude/versions/2.1.175', source: 'native installer' }.Tests
New
claude_version_utils.path.test.ts:null)~/.local/bin→versions/<ver>)cli.jsresolution unchangedWindows behaviour is unchanged — the shim path is preserved, just guarded behind
process.platform === 'win32'.