Skip to content

fix(cli): detect Claude Code native binary (2.1.113+)#1140

Merged
bra1nDump merged 1 commit intoslopus:mainfrom
PavelPotapov:fix/1139-claude-native-binary-detection
Apr 20, 2026
Merged

fix(cli): detect Claude Code native binary (2.1.113+)#1140
bra1nDump merged 1 commit intoslopus:mainfrom
PavelPotapov:fix/1139-claude-native-binary-detection

Conversation

@PavelPotapov
Copy link
Copy Markdown
Contributor

Summary

Fixes #1139happy reports Claude Code is not installed even when a working claude CLI is installed via npm install -g @anthropic-ai/claude-code.

Root cause

Starting with @anthropic-ai/claude-code@2.1.113 the npm package no longer ships a JS entrypoint (cli.js). It now ships a platform-specific native binary declared via package.json's bin field (e.g. bin/claude.exe on Windows, bin/claude elsewhere).

The detector in claude_version_utils.cjs hard-coded cli.js at the package root in two places, so the package was invisible to it:

  1. findNpmGlobalCliPath() — primary npm-global lookup.
  2. findClaudeInPath() — shim-fallback branch that resolves shell shims back to cli.js inside the adjacent node_modules.

Fix

Adds a single helper, resolveClaudeEntrypoint(pkgDir), that tries both shapes in order:

  1. <pkgDir>/cli.js — legacy (< 2.1.113).
  2. <pkgDir>/<bin.claude> read from <pkgDir>/package.json — current (>= 2.1.113). Supports both object ({ claude: "..." }) and string forms of bin.

Both affected call sites now delegate to this helper. runClaudeCli() already knows how to spawn() 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.

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
@bra1nDump bra1nDump merged commit 1708d13 into slopus:main Apr 20, 2026
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.

npm-global Claude Code ≥ 2.1.113 not detected (ships as bin/claude.exe, no cli.js)

2 participants