User-writable npm prefix and nvm are incompatible
MacBook Pro, M1 Max, Sonoma 14.7 zsh 5.9 (x86_64-apple-darwin23.0) node v20.18.1 (npm v10.8.2)
To enable auto-updating, the current advice is to create a user-writable npm prefix:
https://docs.anthropic.com/en/docs/agents-and-tools/claude-code/troubleshooting#recommended-solution-create-a-user-writable-npm-prefix
However, this conflicts with nvm, resulting in this error:
Your user’s .npmrc file (${HOME}/.npmrc) has a
globalconfigand/or aprefixsetting, which are incompatible with nvm. Runnvm use --delete-prefix v20.18.1 --silentto unset it.
I use nvm to lock the Node version for the project in which I use Claude Code, so I'm directly caught between the npm prefix and nvm conflict.
I asked Claude 3.7 for options, and got these:
https://claude.ai/chat/c23fc52a-c774-4de9-a627-68555f115aa4
I'm not sure any of them are great, so I'm not including them in this issue.
My workaround: I will disable auto-update, and continue to manually update.
However, I think it's inappropriate to recommend a user-writable npm prefix without documenting that it will conflict with nvm, and explaining the conflict and suggested workarounds. So, I recommend one of the following:
- don't recommend a user-writable npm prefix (perhaps necessitating removal of auto-update)
- document the conflict between user-writable npm prefix and nvm, and suggest a path forward
- implement some reasonable way to make user-writable npm prefix and nvm work together
I think #263 may be pertinent; I apologize for the interlink to that issue if it's ultimately not relevant.
Thanks for Claude Code in general, it's awesome.
cc @sid374 for thoughts
@peterkaminski : In the originally proposed update to the README documentation, I did mention nvm as an alternative. But, Anthropic wanted a link to their website instead. I definitely agree that the nvm alternative should be mentioned. I also think that there are a lot of people who are not familiar with the Node ecosystem and the user-writable prefix is the quickest way to a serviceable Claude installation, whereas nvm is another layer of indirection.
@emcd I do not understand your comment. nvm is commonly used for managing node versions when switching between different projects. I use it extensively. But the user-writable npm prefix approach is NOT compatible with nvm.
How do we allow Claude Code to update automatically?
What's the workaround?
@emcd I do not understand your comment.
nvmis commonly used for managing node versions when switching between different projects.
Correct, which is why I recommended to Anthropic that they accommodate the nvm approach too. (And I mentioned that in my comment above.)
But the user-writable npm prefix approach is NOT compatible with nvm.
But it is compatible with installing and using Claude Code in a manner which does not compromise system stability or security. And, it is simpler for "Node outsiders" who want to get something up and working. As mentioned above, if someone does not already have nvm setup, then that is extra work for them.
How do we allow Claude Code to update automatically?
What's the workaround?
Those are questions for Anthropic.
Last time I checked, the automatic updates worked fine with a user-writable NPM prefix. Not sure what the current state of play is for NVM installations.
Bumping this - @sid374 @bcherny would it be possible to expose some kind of "pre-Bash" tool hook that allows us to control the shell before subsequent commands are run? then we could have the shells run unset ... automatically / without relying on the model to remember it fromCLAUDE.md etc
Hi all, following up on this one. It seems a shame that the most widely used node version management tool isn't compatible with Anthropic's flagship node packaged CLI tool – and it makes experience of updating Claude Code pretty frustrating. Happy to help contributing towards this issue if the team can express a direction they'd prefer a PR for this to take?
For others who may experience this: /migrate-installer didn't initially work for me either:
➜ Developer claude --verbose migrate-installer
✗ Installation failed
Update already in progress
Press Enter to continue or Esc to exit
➜ Developer
But after running rm -rf ~/.claude/local I was able to migrate and install properly (seems the local installation must have gotten interrupted/corrupted),
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Closing as this should be fixed with the native installer. Please open a new issue if you are still encountering errors. Thank you!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.