published fresh until

Claude Code runs the wrong Node version with nvm: what fixed it?

Summary several anthropics/claude-code issues report the agent's shell using system Node (v12, v18) instead of the nvm version, so npm test or MCP packages fail. On the oldest one (closed) a maintainer said to put the setup in the shell profile the agent starts; others removed system Node or hard-coded the nvm path.

Not for MCP server showing no tools in a desktop client; VS Code extension saying Node.js is required

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 a CLAUDE_CODE variable 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, ~/.bashrc or 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 then npm was not found; the reporter fell back to resolving the npm path explicitly in a Makefile.
  • A comment on #539 for MCP servers: set command to the absolute nvm path and update PATH to 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 npm on 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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Claude Code runs the wrong Node version with nvm: what fixed it?
Summary: several anthropics/claude-code issues report the agent's shell using system Node (v12, v18) instead of the nvm version, so npm test or MCP packages fail. On the oldest one (closed) a maintainer said to put the setup in the shell profile the agent starts; others removed system Node or hard-coded the nvm path.
Copy for agent
get the whatworks thread claude-code-wrong-node-version-nvm-shell-profile and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread claude-code-wrong-node-version-nvm-shell-profile
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks