Setting Up and Switching Between Multiple AI Models for Claude Code: A Practical Guide
A step-by-step guide for developers who want to use Claude Code in the terminal and switch between different AI model services. Learn how to install Node.js and Git safely, install Claude Code without admin rights, configure multiple model gateways with environment variables, keep API keys secure, and verify that model switching actually works.
Who This Guide Is For
This guide is for developers who want to use AI coding assistants in the terminal and need to switch between different model services. Before you start, make sure you have:
- A working network connection that can reach the npm registry and your chosen model service.
- An account with the model provider, or a gateway address and API key supplied by your gateway vendor.
- Permission to install software on your machine. If your company laptop restricts installations, contact your IT administrator first.
Installing the base dependencies and the coding assistant typically takes about 10 minutes, depending on your network speed and permission setup.
Step 1: Check the Base Dependencies
Claude Code runs on Node.js. Node.js 18 or later is recommended, preferably an LTS release. Git is also required for repository management and by many assistant features.
Open a terminal and run:
node --versionnpm --versiongit --version
If a command is not found, or the version is too low, install the tools for your platform.
Windows (PowerShell)
winget install OpenJS.NodeJS.LTSwinget install --id Git.Git -e
macOS (with Homebrew installed)
brew install node git
After installation, open a new terminal window and re-run the version checks. Newly installed programs are usually only recognized in a fresh session.
Step 2: Avoid Global Installs That Require Admin Rights
By default, npm writes global installs to a system directory. On Windows this requires running as administrator; on macOS and Linux it requires sudo. This creates two problems: install scripts run with excessive privileges, and later upgrades can cause file ownership conflicts.
A safer approach is to point npm’s global directory at your user folder.
macOS / Linux
mkdir -p "$HOME/.npm-global"npm config set prefix "$HOME/.npm-global"echo 'export PATH="$HOME/.npm-global/bin:$PATH"' >> ~/.zshrcsource ~/.zshrc
If you use bash, replace ~/.zshrc with ~/.bashrc.
Windows (PowerShell, standard user)
New-Item -ItemType Directory -Force "$env:USERPROFILE\.npm-global" | Out-Nullnpm config set prefix "$env:USERPROFILE\.npm-global"[Environment]::SetEnvironmentVariable("Path", "$env:USERPROFILE\.npm-global;" + [Environment]::GetEnvironmentVariable("Path", "User"), "User")
Reopen your terminal after making these changes. If you need to manage multiple Node.js versions, use nvm (macOS/Linux) or nvm-windows — neither requires admin rights.
Step 3: Install Claude Code
Claude Code is Anthropic’s command-line coding assistant. Once installed, it can be invoked from any directory. The command below installs it via npm; for the latest recommended installation method, refer to Anthropic’s official documentation.
npm install -g @anthropic-ai/claude-codeclaude --version
Installation usually takes one to two minutes. If claude --version returns “command not found,” verify that npm’s global bin directory is in your PATH and reopen the terminal.
Once verified, navigate to your project and launch it:
cd ~/your-projectclaude
On first launch, the program walks you through login authentication and asks whether to allow reading and modifying files in the current directory. Only grant these permissions for trusted projects, and review the authorized scope regularly.
Step 4: Configure Multiple Model Services
The key to switching models is having Claude Code read different service addresses and credentials. Claude Code supports specifying a gateway address via environment variables, or setting the same variables in the env field of its configuration file.
To connect through a compatible gateway, the commonly used variables are:
ANTHROPIC_BASE_URL: the gateway’s access address.ANTHROPIC_AUTH_TOKENorANTHROPIC_API_KEY: the credential. Which one to use depends on your gateway vendor’s documentation.
Gateway addresses can go into a configuration file, but keys should never be stored in plaintext files. The following example shows how to keep one address profile per provider:
mkdir -p ~/.config/ai-profilescat > ~/.config/ai-profiles/gateway-a.env <<'EOF'export ANTHROPIC_BASE_URL="https://gateway-a.example.com"EOF
The domain in the example is a placeholder — replace it with the real address from your provider.
Store keys in your system’s keychain instead. On macOS, use Keychain Access and read the key when switching:
security add-generic-password -a "$USER" -s ai-gateway-a -wexport ANTHROPIC_AUTH_TOKEN="$(security find-generic-password -a "$USER" -s ai-gateway-a -w)"
The first command prompts for the key interactively; the input is never echoed to the terminal or saved in shell history. On Windows, use Credential Manager or another trusted password manager to do the same.
Step 5: Two Ways to Switch Models
Option 1: Switch within a session
After starting Claude Code, type /model to view and select the model for the current session. This only affects the current session, making it ideal for quickly comparing outputs from different models.
Option 2: Switch via environment configuration
Load the target provider’s profile before launching:
source ~/.config/ai-profiles/gateway-a.envexport ANTHROPIC_AUTH_TOKEN="$(security find-generic-password -a "$USER" -s ai-gateway-a -w)"claude
To switch to another provider, close the current session and re-run the loading commands. Note that environment variables already set in the shell override values from the configuration file. If switching seems to have no effect, run env | grep ANTHROPIC to check which variables are actually active.
Step 6: Choosing a GUI Switching Tool
Some developers use graphical tools to manage multiple configurations. These tools reduce the chance of manual errors when editing variables, but they also touch your keys, so choose carefully. Use these criteria when evaluating options:
- Trusted source: download from the official website or official code repository — never from unknown mirrors or redirect links.
- Verification data: the release page should provide SHA256 checksums or digital signatures that you can verify after downloading.
- Auditable: source code is public, or there is at least a clear privacy policy and security statement.
- Local storage: configurations and keys stay on your machine, using the system keychain or encrypted storage.
- Backup support: configurations can be exported for migration and recovery.
After downloading, always verify the checksum. On Windows:
Get-FileHash -Algorithm SHA256 "$env:USERPROFILE\Downloads\installer-filename"
On macOS:
shasum -a 256 ~/Downloads/installer-filename
The result must match the value on the official release page exactly. If it doesn’t, delete the file and download again from the official source.
If you can’t find a trustworthy GUI tool, environment variables and configuration files alone are entirely sufficient. This approach has no third-party dependencies and is easier to audit.
Step 7: Security Best Practices
- Never commit keys: Do not put
ANTHROPIC_AUTH_TOKENor other keys into code repositories, scripts, or screenshots. If a key is accidentally committed, revoke it immediately in the provider’s console and generate a new one. - Restrict file permissions: If you must store a plaintext configuration, run
chmod 600 filenameso only your user can read it. - Use sudo sparingly: Only use admin rights when truly necessary. For npm global installs, prefer the user-directory approach from Step 2.
- Don’t disable system security: If macOS warns that a developer “cannot be verified,” first check the package’s source and checksum. Only after confirming it’s legitimate, approve it via the “Privacy & Security” page in System Settings. Avoid disabling Gatekeeper or running unknown un-quarantine commands.
- Mind permission grants: Claude Code can read and write files in authorized directories. When working with sensitive projects, confirm the authorized scope first.
Step 8: Troubleshooting
1. Permission denied (EACCES) errors
This usually means the global install directory is not writable. Configure a user-level npm prefix as described in Step 2, then reinstall. Don’t fall back to sudo to work around this.
2. The claude command is not found
Check whether the bin directory under the path returned by npm config get prefix is in your PATH. You must reopen the terminal after changing PATH.
3. Startup failures or “version too old” errors
Run node --version to confirm your Node.js version. If it’s below 18, upgrade Node.js, then reinstall Claude Code to ensure dependency compatibility.
4. Model switching doesn’t take effect
First verify that the environment variables in the current session are correct, then fully exit and restart Claude Code. If the problem persists, check the request logs in your model provider’s console to confirm traffic is actually going to the target address.
5. Don’t rely on the model’s self-introduction to verify switching
A model’s answer about its own identity is unreliable and may not match the service actually being called. To verify a switch, rely on the configuration shown by /model, your environment variables, and the call logs in the provider’s console.
Step 9: Upgrading, Backing Up, and Uninstalling
Before upgrading Claude Code, back up your configuration directory:
cp -r ~/.config/ai-profiles ~/ai-profiles-backupnpm update -g @anthropic-ai/claude-code
To uninstall:
npm uninstall -g @anthropic-ai/claude-code
Uninstalling does not automatically remove your configuration files or keys. Once you’re sure you no longer need them, delete the relevant directories manually and revoke unused keys in your provider’s console.
Conclusion
Following these steps, the base dependencies and coding assistant are typically installed in about 10 minutes, though timing varies with network and permission conditions. The core of multi-model switching is keeping addresses and keys separate, and verifying the result in a checkable way after every switch. With configurations and keys stored securely, a multi-model environment will reliably serve your daily development workflow.
