fix(cli): detect Claude Code native binary (2.1.113+)#1140
Merged
bra1nDump merged 1 commit intoslopus:mainfrom Apr 20, 2026
Merged
Conversation
Starting with @anthropic-ai/claude-code@2.1.113 the package no longer
ships cli.js — it ships a platform-specific native binary declared in
package.json's `bin` field (e.g. bin/claude.exe on Windows). The detector
was hard-coded to look for cli.js and reported "Claude Code is not
installed" even when claude worked fine from the shell.
Introduces resolveClaudeEntrypoint(pkgDir) that:
1. returns cli.js if present (legacy, < 2.1.113), and
2. otherwise reads `bin.claude` (or string-form `bin`) from
package.json and returns that binary path.
Applied to both findNpmGlobalCliPath() and the shim-resolution branch of
findClaudeInPath() — both had the same cli.js-only assumption.
Closes slopus#1139
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.
Summary
Fixes #1139 —
happyreportsClaude Code is not installedeven when a workingclaudeCLI is installed vianpm install -g @anthropic-ai/claude-code.Root cause
Starting with
@anthropic-ai/claude-code@2.1.113the npm package no longer ships a JS entrypoint (cli.js). It now ships a platform-specific native binary declared viapackage.json'sbinfield (e.g.bin/claude.exeon Windows,bin/claudeelsewhere).The detector in
claude_version_utils.cjshard-codedcli.jsat the package root in two places, so the package was invisible to it:findNpmGlobalCliPath()— primary npm-global lookup.findClaudeInPath()— shim-fallback branch that resolves shell shims back tocli.jsinside the adjacentnode_modules.Fix
Adds a single helper,
resolveClaudeEntrypoint(pkgDir), that tries both shapes in order:<pkgDir>/cli.js— legacy (< 2.1.113).<pkgDir>/<bin.claude>read from<pkgDir>/package.json— current (>= 2.1.113). Supports both object ({ claude: "..." }) and string forms ofbin.Both affected call sites now delegate to this helper.
runClaudeCli()already knows how tospawn()a non-JS entrypoint, so no changes were needed there.Repro
```bash
npm install -g @anthropic-ai/claude-code@2.1.114
npm install -g happy
claude -v # works: "2.1.114 (Claude Code)"
happy # before: "Claude Code is not installed"; after: launches normally
```
Reproduced and verified on Windows 11 with npm-global install.
Known limitation (out of scope)
`getVersion(cliPath)` reads `package.json` from `path.dirname(cliPath)`. For the native binary (`/bin/claude.exe`) that resolves to `/bin/`, where no `package.json` exists — so the version line prints as `Using Claude Code from npm` without the version suffix. The CLI still launches correctly. Happy to address in a follow-up PR if desired; left out here to keep the fix minimal and focused on the "not installed" regression.
Tests
The existing test file (`claude_version_utils.test.ts`) covers `detectSourceFromPath` via string assertions but does not mock `fs`/`execSync` for the finder functions, so an integration-style test for this path would require broader test scaffolding. Manual repro above confirms the fix.