Using Claude Code with AI POOL

Claude Code is a powerful coding assistant launched by Anthropic. By default, you must log in to a Claude account to use it, requiring a monthly subscription purchase. Although Claude Code itself supports direct API calls, the official version doesn't expose this functionality. To enable all AI POOL users to use it, we have specially developed a script that allows direct use with an AI POOL API Key.

Prerequisites

Before getting started, please ensure you have:

  • An AI POOL account
  • An AI POOL API Key (you can find it in your account dashboard)
  • Node.js and npm installed

macOS/Linux User Configuration Guide

Step 1: Install Claude Code

Run the official Claude installation command:

curl -fsSL https://claude.ai/install.sh | bash

Alternative method: If you encounter network issues, you can also use npm (Node Package Manager) to globally install Claude Code on your system. Open your terminal and run the following command:

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

After installation, you can use the claude command from anywhere in your terminal.

Step 2: Configure AI POOL Access

Configure environment variables through ~/.claude/settings.json. This method is the most stable and reliable, requiring no system environment variable configuration and avoiding various environment variable conflicts.

1. Create Configuration Directory

mkdir -p ~/.claude

2. Edit settings.json

Open the ~/.claude/settings.json file in your preferred text editor and add the following content:

{
  "env": {
    "ANTHROPIC_API_KEY": "sk-xxxxxxxxxxxxxxxx",
    "ANTHROPIC_BASE_URL": "https://ai-gate.haozcloud.com"
  }
}

Configuration Instructions:

  • Set ANTHROPIC_API_KEY to your AI POOL API Key (be sure to replace sk-xxxxxxxxxxxxxxxx)
  • Set ANTHROPIC_BASE_URL to the AI POOL API address
WARNING

Do not add the apiKeyHelper field in the configuration file, as it will cause configuration conflicts

This configuration method will override system environment variables, ensuring 100% normal operation without requiring additional system environment variable configuration.

Step 3: Login-Free Configuration

When Claude Code starts for the first time, it will ask you to log in to the official Claude account. If you have a VPN enabled, a login prompt will appear; if not, it will directly report an error: Failed to connect to api.anthropic.com.

Since we have already configured environment variables in settings.json, Claude Code will automatically use these configurations without requiring additional login-free configuration.

Step 4: Start Using

Now you can start Claude Code in your terminal:

claude

After startup, Claude will ask if you want to use a custom key, select yes.

Windows User Configuration Guide

Important Note

Windows users must use Git Bash (or WSL/Docker) to run Claude Code. Using it in CMD or PowerShell may encounter various environment variable and compatibility issues.

Step 1: Install Necessary Software

1. Install Node.js

Visit https://nodejs.org/ to download and install the LTS version of Node.js.

2. Install Git for Windows (Required)

  • Visit https://git-scm.com/downloads/win
  • Download and install Git for Windows
  • Keep default settings during installation
  • After installation, you can find "Git Bash" in the Start menu or right-click menu

Why must you use Git Bash?

  • CMD and PowerShell handle environment variables differently, easily causing compatibility issues
  • Claude Code runs most stably in Git Bash
  • If you're familiar with WSL or Docker, you can also use these environments

Step 2: Install Claude Code

TIP

Please execute the following operations in Git Bash

Open Git Bash and run the following command:

curl -fsSL https://claude.ai/install.sh | bash

Alternative method: If you encounter network issues, you can also use npm (Node Package Manager) to globally install Claude Code on your system. Open your terminal and run the following command:

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

After installation, you can use the claude command from anywhere in your terminal.

Step 3: Configure AI POOL Access

Set environment variables through configuration files. This is the most stable method on Windows, requiring no system environment variable configuration and avoiding environment variable differences between CMD and PowerShell.

Create Configuration in Git Bash

  1. Create configuration directory:
mkdir -p ~/.claude
  1. Create and edit configuration file:
# Open configuration file with notepad
notepad ~/.claude/settings.json

In the opened Notepad, add the following content and save:

{
  "env": {
    "ANTHROPIC_API_KEY": "sk-xxxxxxxxxxxxxxxx",
    "ANTHROPIC_BASE_URL": "https://ai-gate.haozcloud.com"
  }
}

Configuration Instructions:

  • Set ANTHROPIC_API_KEY to your AI POOL API Key (be sure to replace sk-xxxxxxxxxxxxxxxx)
  • Set ANTHROPIC_BASE_URL to the AI POOL API address
WARNING

Do not add the apiKeyHelper field in the configuration file, as it will cause configuration conflicts

This configuration method will override system environment variables, ensuring 100% normal operation without requiring additional system environment variable configuration.

Step 4: Skip Login Prompt

When Claude Code starts for the first time, it will ask you to log in to the official Claude account. If you have a VPN enabled, a login prompt will appear; if not, it will directly report an error: Failed to connect to api.anthropic.com.

Since we have already configured environment variables in settings.json, Claude Code will automatically use these configurations without requiring additional login-free configuration.

Step 5: Start Using

Important

Must start Claude Code in Git Bash

# Navigate to your project directory
cd /path/to/your/project
# Start Claude Code
claude

After startup, Claude will ask if you want to use a custom key, select yes.

TIP

Do not use CMD or PowerShell, as this is the main reason many users encounter problems. If you must use other terminals, it's recommended to use WSL or Docker environment.

Alternative Solution: Configure Using apiKeyHelper Script

If the above settings.json env configuration method doesn't work, you can try using the apiKeyHelper script method. This method outputs the API Key through a script instead of directly configuring environment variables.

TIP

The alternative solution is an early exploration method. Initially, Claude did not support environment variables. Generally, the latest version of Claude doesn't have this issue. It's recommended to prioritize the primary solution.

macOS/Linux Using apiKeyHelper Configuration

1. Modify settings.json

Edit the ~/.claude/settings.json file:

{
  "apiKeyHelper": "~/.claude/ai_pool_api_key.sh"
}
WARNING

When using the apiKeyHelper method, do not configure the env field in settings.json, as the two methods will conflict.

2. Create API Key Script

Create the ~/.claude/ai_pool_api_key.sh file and fill in the following content:

#!/bin/sh
echo "sk-xxxxxxxxxxxxxxxx"

Be sure to replace sk-xxxxxxxxxxxxxxxx with your own AI POOL API Key.

3. Set Script Permissions

chmod +x ~/.claude/ai_pool_api_key.sh

4. Configure Environment Variables

Add the following command to your shell configuration file (e.g., ~/.zshrc, ~/.bashrc, or ~/.bash_profile):

export ANTHROPIC_BASE_URL="https://ai-gate.haozcloud.com"

Make the changes take effect immediately by running source ~/.zshrc (or the corresponding file).

Windows Using apiKeyHelper Configuration

1. Modify settings.json

Edit the configuration file in Git Bash:

notepad ~/.claude/settings.json

Modify to:

{
  "apiKeyHelper": "~/.claude/ai_pool_api_key.sh"
}
WARNING

When using the apiKeyHelper method, do not configure the env field in settings.json, as the two methods will conflict.

2. Create API Key Script

Execute in Git Bash:

# Create script file
cat > ~/.claude/ai_pool_api_key.sh << 'EOF'
#!/bin/sh
echo "sk-xxxxxxxxxxxxxxxx"
EOF

# Set permissions
chmod +x ~/.claude/ai_pool_api_key.sh

Be sure to replace sk-xxxxxxxxxxxxxxxx with your own AI POOL API Key.

3. Configure System Environment Variables

  1. Right-click "This PC" → "Properties" → "Advanced system settings"
  2. Click the "Environment Variables" button
  3. In "User variables", click "New" and add:
    • Variable name: ANTHROPIC_BASE_URL
    • Variable value: https://ai-gate.haozcloud.com
Important Reminder

After setting environment variables, please close and reopen Git Bash to ensure the environment variables take effect.

Troubleshooting

macOS/Linux Permission Issues

When executing the npm install -g @anthropic-ai/claude-code command, you may encounter EACCES permission errors. Solution:

sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin

Windows Common Issues

Must Use Git Bash

Most Important: Many Windows users report errors because they used CMD or PowerShell. These terminals handle environment variables differently, causing various compatibility issues.

Solution:

  • Always install and use Claude Code in Git Bash
  • Or use WSL (Windows Subsystem for Linux)
  • Or use Docker environment

"permission denied" Error During Installation

  • Run Git Bash as administrator
  • Or configure npm to use user directory: npm config set prefix ~/.npm-global

Environment Variables Don't Take Effect After Setting

  • Recommended to use the ~/.claude/settings.json configuration method, which can completely avoid this issue
  • If using system environment variables, you need to close and reopen Git Bash after setting

If you encounter various environment variable-related errors, it's strongly recommended to use the ~/.claude/settings.json configuration method:

{
  "env": {
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_AUTH_TOKEN": "sk-xxxxxxxxxxxxxxxx",
    "ANTHROPIC_BASE_URL": "https://ai-gate.haozcloud.com"
  }
}

This method can:

  • Override system environment variables, avoiding conflicts
  • Avoid environment variable differences between CMD/PowerShell and Git Bash
  • Ensure configuration is 100% effective

If you encounter authentication failures when using the system environment variable method, please check:

  • Whether running in Git Bash (Windows users)
  • Whether the API Key is copied correctly (be careful not to have extra spaces)
  • Whether the environment variable name is correct
  • Whether the API Key is valid and has sufficient quota

Start Using

Congratulations! All configurations are complete. Claude Code will start an interactive REPL session where you can directly start asking questions and interacting. Since we have configured the API endpoint and Key, it now runs entirely through the AI POOL platform.

Use Claude Code in your project directory:

# Navigate to your project directory
cd /path/to/your/project
# Start Claude Code
claude

Enjoy the powerful coding experience powered by AI POOL!