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.
Before getting started, please ensure you have:
Run the official Claude installation command:
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:
After installation, you can use the claude command from anywhere in your terminal.
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.
Open the ~/.claude/settings.json file in your preferred text editor and add the following content:
Configuration Instructions:
ANTHROPIC_API_KEY to your AI POOL API Key (be sure to replace sk-xxxxxxxxxxxxxxxx)ANTHROPIC_BASE_URL to the AI POOL API addressDo 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.
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.
Now you can start Claude Code in your terminal:
After startup, Claude will ask if you want to use a custom key, select yes.
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.
Visit https://nodejs.org/ to download and install the LTS version of Node.js.
Why must you use Git Bash?
Please execute the following operations in Git Bash
Open Git Bash and run the following command:
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:
After installation, you can use the claude command from anywhere in your terminal.
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.
In the opened Notepad, add the following content and save:
Configuration Instructions:
ANTHROPIC_API_KEY to your AI POOL API Key (be sure to replace sk-xxxxxxxxxxxxxxxx)ANTHROPIC_BASE_URL to the AI POOL API addressDo 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.
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.
Must start Claude Code in Git Bash
After startup, Claude will ask if you want to use a custom key, select yes.
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.
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.
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.
Edit the ~/.claude/settings.json file:
When using the apiKeyHelper method, do not configure the env field in settings.json, as the two methods will conflict.
Create the ~/.claude/ai_pool_api_key.sh file and fill in the following content:
Be sure to replace sk-xxxxxxxxxxxxxxxx with your own AI POOL API Key.
Add the following command to your shell configuration file (e.g., ~/.zshrc, ~/.bashrc, or ~/.bash_profile):
Make the changes take effect immediately by running source ~/.zshrc (or the corresponding file).
Edit the configuration file in Git Bash:
Modify to:
When using the apiKeyHelper method, do not configure the env field in settings.json, as the two methods will conflict.
Execute in Git Bash:
Be sure to replace sk-xxxxxxxxxxxxxxxx with your own AI POOL API Key.
ANTHROPIC_BASE_URLhttps://ai-gate.haozcloud.comAfter setting environment variables, please close and reopen Git Bash to ensure the environment variables take effect.
When executing the npm install -g @anthropic-ai/claude-code command, you may encounter EACCES permission errors. Solution:
Most Important: Many Windows users report errors because they used CMD or PowerShell. These terminals handle environment variables differently, causing various compatibility issues.
Solution:
npm config set prefix ~/.npm-global~/.claude/settings.json configuration method, which can completely avoid this issueIf you encounter various environment variable-related errors, it's strongly recommended to use the ~/.claude/settings.json configuration method:
This method can:
If you encounter authentication failures when using the system environment variable method, please check:
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:
Enjoy the powerful coding experience powered by AI POOL!