A guide for macOS developers who want to use Claude CLI without installing Node.js globally. The post demonstrates how to set up a local Claude CLI installation using mise for Node version management, configure a shell function in .zshrc for easy access, and solve the common issue where Claude CLI loses the current working directory context. This approach keeps your global system clean while making Claude CLI available from any project directory.
๐ฆ Setup Claude locally with miseโ
mkdir -p ~/tools/claude
cd ~/tools/claude
mise use node@22 # pin Node here only
mise install
npm init -y
npm install @anthropic-ai/claude-code
๐ Add function in ~/.zshrc
โ
claude() {
mise exec -C "$HOME/tools/claude" -- sh -c "cd '$PWD' && npx claude \"\$@\"" sh "$@"
}
What each part does:
-
claude()
- Creates a shell function namedclaude
that you can call from anywhere -
mise exec -C "$HOME/tools/claude"
- Tells mise to execute a command using the Node version configured in~/tools/claude
(via the.mise.toml
or.tool-versions
file there) -
--
- Separates mise's options from the command you want to run -
sh -c "cd '$PWD' && npx claude \"\$@\""
- Runs a new shell that:cd '$PWD'
- Changes to your current working directory (the one where you invokedclaude
)&&
- Only continues if thecd
succeedsnpx claude \"\$@\"
- Runs the Claude CLI, passing through all arguments
-
sh "$@"
- Passes your original arguments ("$@"
) through the shell chain so they reach the actualclaude
command
Why this specific approach:
- Problem:
mise exec -C
changes the working directory context to~/tools/claude
, so Claude CLI thinks you're running it from there, not your project - Solution: We use
sh -c
to create a subshell where we explicitlycd
back to'$PWD'
(your actual location) before runningnpx claude
- Result: Claude CLI sees your project directory as the working directory while still using the Node version from
~/tools/claude
In simple terms: We're tricking the system - let mise think we're in ~/tools/claude
to get the right Node version, but then immediately jump back to where you actually are before running Claude.
Reload shell:
source ~/.zshrc
โถ๏ธ Usageโ
Now you can run from anywhere:
claude --version
claude chat "Hello!"
This:
- Drops into
~/tools/claude
- Uses the pinned Node (via mise)
- Runs
npx claude
with your local install - Leaves other projects untouched
๐ Updateโ
cd ~/tools/claude
npm update @anthropic-ai/claude-code
With Geminiโ
gemini() {
mise exec -C "$HOME/tools/gemini" -- sh -c "cd '$PWD' && '$HOME/tools/gemini/node_modules/.bin/gemini' \"\$@\"" sh "$@"
}
๐ You get Claude isolated, no global Node, no clashes.