Skip to main content

Running Claude CLI Without Global Node on macOS

· 3 min read
Pere Pages
Software Engineer

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:

  1. claude() - Creates a shell function named claude that you can call from anywhere

  2. 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)

  3. -- - Separates mise's options from the command you want to run

  4. sh -c "cd '$PWD' && npx claude \"\$@\"" - Runs a new shell that:

    • cd '$PWD' - Changes to your current working directory (the one where you invoked claude)
    • && - Only continues if the cd succeeds
    • npx claude \"\$@\" - Runs the Claude CLI, passing through all arguments
  5. sh "$@" - Passes your original arguments ("$@") through the shell chain so they reach the actual claude 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 explicitly cd back to '$PWD' (your actual location) before running npx 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

in ~/.zshrc
gemini() {
mise exec -C "$HOME/tools/gemini" -- sh -c "cd '$PWD' && '$HOME/tools/gemini/node_modules/.bin/gemini' \"\$@\"" sh "$@"
}

Another way

in /usr/local/bin/claude
#!/bin/bash
mise exec -C "$HOME/tools/claude" -- sh -c "cd '$PWD' && npx claude \"\$@\"" sh "$@"
sudo chmod +x /usr/local/bin/claude

👉 You get Claude isolated, no global Node, no clashes.