fix: export PATH in hooks so node resolves on nvm systems#1
Open
frank-ih wants to merge 2 commits into
Open
Conversation
…#1598) Hooks run via /bin/sh which does not inherit the user shell PATH. On nvm setups node lives outside standard system paths, causing every hook to fail with: /bin/sh: node: command not found The fix dynamically resolves the nvm node bin directory at runtime and prepends it to PATH along with common node locations (homebrew, /usr/local/bin). Falls back gracefully on systems where node is already on PATH.
Addresses CodeRabbit review: the previous fix always prepended the nvm path even when node was already resolvable, which could silently switch Node versions. Now wraps the export in `command -v node >/dev/null 2>&1 || ...` so PATH is only augmented when node cannot already be found — a true no-op on systems where node is on PATH.
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.
Closes thedotmack#1598
🔴 Failing scenario (the bug)
On any system where Node is installed via nvm (not in a system path), every claude-mem hook fails silently:
Why: Claude Code executes hooks via
/bin/sh, which launches a minimal non-interactive shell. It does not source.bashrc/.zshrcand does not inherit the user's$PATH. When nvm is used, node lives at~/.nvm/versions/node/<version>/bin/— a path that/bin/shknows nothing about.🟢 Expected behavior (after this fix)
All hooks resolve
nodecorrectly regardless of whether it was installed via nvm, Homebrew (/opt/homebrew/bin), or a system package (/usr/local/bin). No errors on session startup, compact, or stop.✅ The fix
Each hook command now opens with a dynamic
export PATHthat:~/.nvm/versions/nodeexistssort -V | tail -1and prepends itsbin/to PATH/opt/homebrew/binand/usr/local/binfor Homebrew and system installsThis pattern was already present in the cached version of
hooks.jsongenerated post-install, but was missing from the marketplace version that Claude Code actually reads at runtime.🔁 Files changed
plugin/hooks/hooks.json— addedexport PATHprefix to all 6 hook commands (SessionStart ×3, UserPromptSubmit, PostToolUse, Stop, SessionEnd)