-
Notifications
You must be signed in to change notification settings - Fork 181
Feature- add bun support and improve claude cli detection. note: anthropic now owns bun #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ahundt
wants to merge
2
commits into
slopus:main
Choose a base branch
from
ahundt:feature/bun-support-claude-cli-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature- add bun support and improve claude cli detection. note: anthropic now owns bun #91
ahundt
wants to merge
2
commits into
slopus:main
from
ahundt:feature/bun-support-claude-cli-detection
+971
−71
Conversation
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
DETECTION OUTPUT: - npm: 2.0.69 (via /Users/athundt/node_modules/@anthropic-ai/claude-code/cli.js) - Bun: 2.0.69 (via ~/.bun/bin/claude → resolved to same npm location) - Homebrew: 2.0.65 (via /opt/homebrew/bin/claude → .claude-code-2DTsDk1V) - Native: Windows/AppData/Unix ~/.local paths supported CRITICAL FIXES: - Broken bun detection (was looking in non-existent ~/.bun/install/global/modules/) - Homebrew hashed directories (.claude-code-[hash]) now properly handled - Platform-specific disambiguation: macOS /usr/local/bin/claude = Homebrew, Linux = native installer - Symlink context preservation (original PATH entry prioritized over resolved path) - Cross-platform path normalization with proper case sensitivity handling IMPLEMENTATION: - PATH-first detection using which/where commands (respects user preference) - Platform-specific logic using process.platform for accurate detection - Enhanced @ symbol support for scoped packages and Windows usernames - Comprehensive Windows detection for all drive letters and .exe files - 100% success rate on standard installation patterns (npm, bun, homebrew, native) STRATEGIC NOTE: Anthropic recently acquired Bun, making Bun-first-class support essential for Claude Code CLI detection as Claude is anticipated to run on Bun in the near future. This implementation ensures seamless support for the growing Bun ecosystem while maintaining full compatibility with existing npm, Homebrew, and native installations. FILES AFFECTED: - scripts/claude_version_utils.cjs: Core detection logic with platform-specific improvements - scripts/claude_version_utils.test.ts: 39 comprehensive test cases with platform mocking TESTABLE: - ✅ 100% success rate across Windows/macOS/Linux standard installations - ✅ Platform-specific behavior verified with process.platform mocking - ✅ Cross-platform compatibility with various path formats and special characters - ✅ Real-world edge cases: path normalization, @ symbols, symlink resolution - ✅ All 39 unit tests passing with complete package manager coverage TECHNICAL DETAILS: - Enhanced findClaudeInPath() with dual-source detection (original PATH + resolved path) - Platform-specific detectSourceFromPath() using path.normalize() for cross-platform handling - Fixed bun detection to check ~/.bun/bin/claude symlink instead of non-existent modules directory - Distinguished npm-through-Homebrew vs Homebrew cask installations via hashed directory detection - Added missing exports: findClaudeInPath, detectSourceFromPath for external usage
… and Node.js Previous behavior: happy-cli only worked reliably with Node.js and would crash when native addons failed to load in alternative runtimes like Bun. What changed: Added comprehensive runtime abstraction layer that provides seamless compatibility across Node.js, Bun, and future JavaScript runtimes. - src/utils/runtime.ts: Runtime detection with fallback chain (node/bun/deno/unknown) - scripts/ripgrep_launcher.cjs: Graceful fallback chain for ripgrep native addon Node.js: native addon -> system ripgrep -> packaged binary -> helpful mock Bun: system ripgrep -> packaged binary -> helpful mock (skips incompatible .node) - src/claude/sdk/utils.ts: Clean environment variables for cross-runtime compatibility - src/utils/spawnHappyCLI.ts: Runtime-appropriate executor selection - src/index.ts: Runtime-agnostic CLI execution without process.execPath dependency Why: Modern JavaScript ecosystem is evolving beyond Node.js with Bun gaining significant adoption. Users expect CLI tools to work seamlessly across runtimes without configuration or compatibility issues. Implementation follows KISS/SOLID/TDD principles: - Zero breaking changes - existing Node.js behavior preserved - Graceful degradation with helpful guidance when dependencies missing - Cross-platform support (Windows/macOS/Linux) with platform-specific guidance - Comprehensive test coverage (16 new tests, 100% passing) - Runtime detection cached for performance Files affected: - scripts/ripgrep_launcher.cjs: Native addon compatibility with graceful fallbacks - src/claude/sdk/utils.ts: Environment cleaning with Bun-specific variable removal - src/utils/spawnHappyCLI.ts: Runtime-aware process spawning (line 103) - src/index.ts: Direct CLI execution without Node.js path dependency (line 338) - src/utils/runtime.ts: New runtime detection utilities (40 lines) - Test files: Comprehensive cross-runtime test coverage Testable: - happy --version works with both Node.js and Bun runtimes - Ripgrep functionality preserved: Node.js uses native addon, Bun uses system binary - 16/16 new runtime tests passing - 39/39 existing version detection tests passing (no regression) - Backward compatibility verified - identical behavior for existing Node.js users Technical details: - Runtime detection using globalThis.Bun/Deno with process.versions fallback - Cross-platform ripgrep detection with execFileSync for security - Mock ripgrep implementation prevents crashes with helpful installation guidance - Environment variable cleaning removes conflicting BUN_* variables for Node.js processes - Process spawning uses appropriate runtime executor (node vs bun) This enables users to run happy-cli with Bun for improved performance while maintaining full compatibility with existing Node.js workflows and native addon accelerations.
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.
Why This Matters
Anthropic acquired Bun - Bun will likely become the preferred runtime for Claude Code. This PR ensures happy-cli works seamlessly on Bun today.
Additionally, this PR incorporates @tiann's PATH fallback from PR #83 and adds explicit path override via environment variable.
Problems Solved
.nodeaddons fail to load in Bun~/.bun/bin/claude)Solution
Runtime Compatibility Layer
Improved Claude CLI Detection
Detection priority (respects user preferences):
Incorporates PR #83 improvements (@tiann)
stdio: ['pipe', 'pipe', 'pipe']- Suppresses stderr noise fromwhichChanges
src/utils/runtime.tsscripts/ripgrep_launcher.cjsscripts/claude_version_utils.cjssrc/claude/sdk/utils.tsConfiguration
Testing
Why Merge This
Credits