Claude Code Setup
Install and configure Anthropic's official Claude Code CLI with an API key
Overview
Claude Code is Anthropic's official command-line AI coding tool. This guide covers Windows, Mac, and Linux.
Install Node.js and Git first — see Node.js and Git Setup. For one-click channel management, see CC-Switch Setup.
Install Claude Code
Install
All three platforms share the same npm command:
npm install -g @anthropic-ai/claude-codeVerify:
claude -vA version number means the install succeeded.
Common issues
Q: permission denied / EACCES (Mac / Linux)
Don't use sudo. Move the npm global prefix to your home directory:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc # zsh users: ~/.zshrc
source ~/.bashrcQ: permission denied (Windows)
Run PowerShell as Administrator:
npm config set prefix "$env:APPDATA\npm"
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserQ: command not found: claude
The npm global bin directory is not on PATH. Run npm config get prefix to see the location, then append its /bin directory to the system PATH.
Configure the API Key
CC-Switch (recommended)
A GUI tool with one-click channel switching that writes the Claude Code plugin config automatically — no manual environment variables.
See CC-Switch Setup.
Manual environment variables
Windows
Open PowerShell as Administrator and run:
setx ANTHROPIC_BASE_URL "your-api-url"
setx ANTHROPIC_AUTH_TOKEN "your-key"Close and reopen the terminal, then verify:
# PowerShell
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKEN
# cmd
echo %ANTHROPIC_BASE_URL%
echo %ANTHROPIC_AUTH_TOKEN%Mac / Linux
Edit your shell config (zsh → ~/.zshrc, bash → ~/.bashrc, macOS bash → ~/.bash_profile):
vim ~/.zshrcAppend:
export ANTHROPIC_BASE_URL="your-api-url"
export ANTHROPIC_AUTH_TOKEN="your-key"Save, reload, and verify:
source ~/.zshrc
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKENGet Started
Open a terminal in any project directory (on Windows, right-click → Open in Terminal or Git Bash Here) and run claude:
cd your/project
claudeThe first launch prompts for theme, directory trust, and login method (skipped if you enabled "skip first-run prompts" in CC-Switch).
Once the > prompt appears, describe what you want in plain English (or Chinese), for example:
Create a hello.py in the current directory that prints "Hello World"Handy shortcuts:
/help— list all commands/clear— wipe the current conversation/exitor pressCtrl + Ctwice — exit