Claude Code
Anthropic's official terminal AI coding assistant · Manual setup guide
Claude Code is Anthropic's official command-line coding tool that lets you interact with codebases via natural language directly in your terminal — analyzing code, fixing bugs, writing new features, and handling Git workflows.
If you would rather not edit environment variables by hand, use CC Switch to switch Claude Code between HAI Gateway and other providers from a graphical UI — it sets ANTHROPIC_API_KEY / ANTHROPIC_BASE_URL for you.
Prerequisites
Claude Code runs on Node.js. You must install Node.js and npm before proceeding. Git is recommended for version control.
| Dependency | Version | Required | Download |
|---|---|---|---|
| Node.js | v18+ | Yes | nodejs.org |
| npm | Included with Node.js | Yes | - |
| Git | v2.23+ | Recommended | git-scm.com |
macOS Setup
Step 1: Install dependencies
# Install Node.js and Git via Homebrew (recommended)
brew install node git
# Or install Node.js via nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
source ~/.zshrc
nvm install --ltsVerify installation: node --version and npm --version
Step 2: Install Claude Code
npm install -g @anthropic-ai/claude-codeStep 3: Configure environment variables
Add the following to your ~/.zshrc (or ~/.bashrc for bash):
export ANTHROPIC_API_KEY="sk-pat-YOUR_ACCESS_TOKEN"
export ANTHROPIC_BASE_URL="https://api.hai.network/anthropic"
export API_TIMEOUT_MS="600000"Replace the highlighted values with your own actual values.
Apply the configuration:
source ~/.zshrcStep 4: Skip login
Create ~/.claude.json to skip the official login flow:
cat > ~/.claude.json << 'EOF'
{
"hasCompletedOnboarding": true
}
EOFStep 5: Verify installation
claude --versionIf you see a version number, the installation was successful. You can now run claude in any project directory to start the AI coding assistant.
Windows Setup
Step 1: Install dependencies
- Download and install Node.js LTS (check "Add to PATH" during installation; npm is included automatically)
- Download and install Git for Windows (recommended)
Verify installation (open a new PowerShell window):
node --version
npm --versionStep 2: Install Claude Code
Open PowerShell as administrator and run:
npm install -g @anthropic-ai/claude-codeStep 3: Configure environment variables
Run the following commands in PowerShell (permanent, for the current user):
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-pat-YOUR_ACCESS_TOKEN", "User")
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.hai.network/anthropic", "User")
[System.Environment]::SetEnvironmentVariable("API_TIMEOUT_MS", "600000", "User")After setting environment variables, you must close and reopen your PowerShell / CMD window for the changes to take effect.
Step 4: Skip login
Run the following command in CMD to create the login skip config file:
echo {"hasCompletedOnboarding": true} > %USERPROFILE%\.claude.jsonStep 5: Verify installation
claude --versionConfiguration Reference
| Setting | Value | Description |
|---|---|---|
| ANTHROPIC_API_KEY | sk-pat-xxx | Your Access Token created on the HAI Gateway platform |
| ANTHROPIC_BASE_URL | https://api.hai.network/anthropic | HAI Gateway's Anthropic API proxy address |
| API_TIMEOUT_MS | 600000 | Request timeout (10 minutes) to prevent complex task timeouts |
| ~/.claude.json | hasCompletedOnboarding: true | Skip the official Anthropic login flow |
Troubleshooting
| Issue | Solution |
|---|---|
command not found: claude | Restart terminal; on macOS/Linux run source ~/.zshrc |
| Still prompted to log in / redirected to Anthropic | Check that ~/.claude.json exists and has correct content |
| npm permission error (EACCES) | On macOS/Linux use sudo npm install -g ...; on Windows run as administrator |
| PowerShell "script execution disabled" | Run Set-ExecutionPolicy RemoteSigned -Scope CurrentUser |
| npm global path not in PATH | Run npm config get prefix and add that path/bin to PATH |
| API connection timeout | Verify that ANTHROPIC_BASE_URL is set correctly and check your network connection |
Uninstall & Reset
Uninstall Claude Code
npm uninstall -g @anthropic-ai/claude-codeReset login configuration
macOS / Linux:
rm ~/.claude.jsonWindows (CMD):
del %USERPROFILE%\.claude.json