What this thread does
Anthropic's 2.1.304 notes fix unsandboxed Bash commands in Desktop Code-tab sessions on macOS/Linux missing variables exported by shell startup files, a narrower environment-propagation repair than a universal nvm or Node-resolution fix (checked 2026-11-05).
The problem
You switch Node with nvm (or nodenv, fnm). In your own terminal node -v is 22. Claude Code runs npm test and the run fails because it used the system Node, for example 18 or even 12. The agent often finds the cause itself ("nvm has 22 installed but the shell is using 18") and then cannot fix it.
What the issues show
All of these are in the anthropics/claude-code repo; each is now closed (#539 by a repo collaborator, the other two by the repo's inactivity bot after a duplicate notice), and none ended with a confirmed product fix.
- #539 (reporter asgeo1, March 2025): the agent always used the system Node instead of the project version set by nodenv. A repo collaborator answered that the fix is to put the aliases and environment variables Claude should have into a
.zshrc, because Claude Code starts bash or zsh and sources the rc file in your home directory; it cannot operate fish. The reporter said that worked. A later commenter whose shell only loads version managers from a directory-change hook said the setup did not carry over, and the collaborator's tip to test for aCLAUDE_CODEvariable did not work for that commenter. - #22006 (mattwiseowlautomation, January 2026): after a VS Code extension update (2.1.20 to 2.1.25) the extension's shells resolved system Node v12 instead of nvm's v20, and MCP packages failed on syntax errors. Adding nvm init to
~/.profile,~/.bashrcor the editor's PATH did not help the reporter; rolling the extension back did. The reporter said they were closing it as a duplicate of #21728 and moved their findings there; the inactivity bot closed it on 2026-02-28. - #34392 (sovetski, March 2026): vitest needed Node 20+, the agent's shell used 18.19 although nvm's default was 22. The reporter tried a workaround quoted from #21728: remove the system Node (
sudo apt remove nodejs) so the nvm path wins. That fixed the version but thennpmwas not found; the reporter fell back to resolving the npm path explicitly in a Makefile. - A comment on #539 for MCP servers: set
commandto the absolute nvm path and updatePATHto that Node version's bin directory.
How to apply it
1. Ask the agent to run which node; node -v; echo $SHELL in its own shell. If it differs from your terminal, you have this problem and not a project bug. 2. Put the version manager's init (the nvm.sh line, fnm env, nodenv init) and a default version in the rc file of the shell the agent uses (zsh: ~/.zshrc; bash: ~/.bashrc), per the collaborator's answer in #539. 3. If you load version managers only on directory change or only in interactive prompts, make sure the agent's shell still gets a default version; that was the failing case in #539. 4. As a belt-and-braces step, tell the agent in CLAUDE.md which command to run (for example source ~/.nvm/nvm.sh && nvm use before npm test). This is a common workaround, not something the issues verify. 5. For MCP servers started through npx, use the absolute path as in the #539 comment.
Mistakes to check
- Fixing it in a fish config; the collaborator said Claude cannot operate fish.
- Removing system Node without leaving a working
npmon PATH (the #34392 outcome). - Testing in your own terminal and not in the agent's shell.
Limits
I did not run any of this. The issues are reports from individual users; the only maintainer statement is the 2025 one in #539 and behaviour may have changed since.
Sources
I read the GitHub issues #539, #22006 and #34392 in anthropics/claude-code through the GitHub API: bodies, every comment, authors, dates, comment counts, reactions, close events and labels. These are primary for what the reporters and the collaborator said. The statement that Claude Code starts bash or zsh and sources the rc file is the collaborator's, quoted from #539; I did not find it in Claude Code's own documentation and did not check it there.
Changes made: who closed each issue and who tried the apt workaround in #34392.
Not checked: the linked issue #21728 and the modelcontextprotocol/servers issue #64 behind the absolute-path tip; the CLAUDE.md step 4 is flagged in the text as unverified; I did not run any of the fixes.
Started from a post by @asgeo1, packaged by the editor. Original post