HAI Gateway Docs

Claude Code

Anthropic's official terminal AI coding assistant · Manual setup guide

What is Claude Code?

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.

Recommended: configure via CC Switch

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

Please confirm the following dependencies are ready before installation

Claude Code runs on Node.js. You must install Node.js and npm before proceeding. Git is recommended for version control.

DependencyVersionRequiredDownload
Node.jsv18+Yesnodejs.org
npmIncluded with Node.jsYes-
Gitv2.23+Recommendedgit-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 --lts

Verify installation: node --version and npm --version

Step 2: Install Claude Code

npm install -g @anthropic-ai/claude-code

Step 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"
Note

Replace the highlighted values with your own actual values.

Apply the configuration:

source ~/.zshrc

Step 4: Skip login

Create ~/.claude.json to skip the official login flow:

cat > ~/.claude.json << 'EOF'
{
  "hasCompletedOnboarding": true
}
EOF

Step 5: Verify installation

claude --version
Setup complete

If 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

  1. Download and install Node.js LTS (check "Add to PATH" during installation; npm is included automatically)
  2. Download and install Git for Windows (recommended)

Verify installation (open a new PowerShell window):

node --version
npm --version

Step 2: Install Claude Code

Open PowerShell as administrator and run:

npm install -g @anthropic-ai/claude-code

Step 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")
Restart terminal required

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.json

Step 5: Verify installation

claude --version

Configuration Reference

SettingValueDescription
ANTHROPIC_API_KEYsk-pat-xxxYour Access Token created on the HAI Gateway platform
ANTHROPIC_BASE_URLhttps://api.hai.network/anthropicHAI Gateway's Anthropic API proxy address
API_TIMEOUT_MS600000Request timeout (10 minutes) to prevent complex task timeouts
~/.claude.jsonhasCompletedOnboarding: trueSkip the official Anthropic login flow

Troubleshooting

IssueSolution
command not found: claudeRestart terminal; on macOS/Linux run source ~/.zshrc
Still prompted to log in / redirected to AnthropicCheck 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 PATHRun npm config get prefix and add that path/bin to PATH
API connection timeoutVerify that ANTHROPIC_BASE_URL is set correctly and check your network connection

Uninstall & Reset

Uninstall Claude Code
npm uninstall -g @anthropic-ai/claude-code
Reset login configuration

macOS / Linux:

rm ~/.claude.json

Windows (CMD):

del %USERPROFILE%\.claude.json