Claude Code CLI Setup
Learn how to configure the Claude Code CLI to use CiYuanX's API. This guide covers installation and configuration on Windows, macOS, and Linux.
What is Claude Code?
Claude Code is Anthropic's official command-line interface (CLI), bringing the AI assistant directly into your terminal and code editor. By configuring it to use CiYuanX, you can access multiple AI models through one familiar interface.
Prerequisites
Before you begin, make sure you have:
- A CiYuanX account (sign up here)
- A CiYuanX API key (get a key)
- Terminal / command-prompt access on your computer
Installation
Because network access can be unstable, we recommend installing Node.js first, then installing @anthropic-ai/claude-code globally with npm.
macOS and Linux
1. Install Node.js
💡 Option 1: Use nvm (recommended)
This approach can use domestic mirrors throughout the installation and usage flow, which speeds up downloads and installation.
First, install nvm from the Gitee mirror to avoid network issues when accessing GitHub:
bash -c "$(curl -fsSL https://gitee.com/RubyMetric/nvm-cn/raw/main/install.sh)"After installation, configure nvm to use a domestic mirror for Node.js downloads:
# Set the Node.js download source to the npmmirror mirror
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/
# Apply the configuration
source ~/.bashrcNote
This installation script has built-in mirror support. It automatically configures .bashrc environment variables and sets the Node.js download source to the npmmirror mirror. source ~/.bashrc makes the environment variables take effect in the current terminal window immediately, so you do not need to restart the terminal. If you use Zsh, run source ~/.zshrc as appropriate.
Install the latest LTS (long-term support) version:
nvm install --ltsVerify that Node.js and npm were installed successfully:
node -v
npm -v2. Install Claude Code
Install Claude Code globally:
npm install -g @anthropic-ai/claude-codeIf you run into permission issues, use sudo:
sudo npm install -g @anthropic-ai/claude-codeVerify the installation:
claude --versionIf a version number is displayed, Claude Code has been installed successfully.
Windows
1. Install Node.js
We recommend using the MSI installer. The process is straightforward and mostly follows the installer prompts.
- Download the installer: choose the Windows installer (
.msi) for your system from the Node.js website. If the official download is slow, you can use a domestic mirror, such as the Huawei Cloud Node.js mirror. - Run the installer: double-click the downloaded
.msifile and click Next as prompted. - On the Destination Folder screen, consider changing the installation directory to a non-C-drive path, such as
D:\software\nodejs, to avoid long-term C-drive usage. - Continue to the next step and make sure Add to PATH is selected, so the installer adds the
nodeandnpmcommands to your system environment variables. - On the Tools for Native Modules screen, unless you explicitly need to compile C++ modules, we recommend clearing the checkbox and skipping the recommended toolchain to save time.
- Click Install and wait for the installation to finish.
After installation, open Command Prompt (cmd) or PowerShell and verify the installation:
node -v
npm -vIf version numbers are displayed, Node.js and npm have been installed successfully.
Optional: if you want globally installed packages and cache files to live under the directory you just chose, run:
npm config set prefix "D:\software\nodejs\node_global"
npm config set cache "D:\software\nodejs\node_cache"Then update your system environment variables and change the npm global path in Path to D:\software\nodejs\node_global.
2. Install Claude Code
Open Terminal, Command Prompt (cmd), or PowerShell, then run the following command to install Claude Code globally:
npm install -g @anthropic-ai/claude-codeVerify the installation:
claude --versionIf a version number is displayed, congratulations — Claude Code has been installed successfully.
Configuration
To use CiYuanX with Claude Code, set two environment variables:
| Variable | Description |
|---|---|
ANTHROPIC_AUTH_TOKEN | Your CiYuanX API key |
ANTHROPIC_BASE_URL | CiYuanX's API endpoint (https://ciyuanx.io) |
Choose one of the configuration methods below.
Method 1: Permanent configuration (recommended)
This method stores your API key securely and keeps it across sessions.
Tip
We recommend this method — configure it once and it keeps working.
macOS and Linux
Add these lines to your shell profile (~/.bashrc or ~/.bash_profile for Bash, ~/.zshrc for Zsh):
export ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
export ANTHROPIC_BASE_URL="https://ciyuanx.io"Apply the changes:
source ~/.zshrc # or source ~/.bashrcWindows
Using PowerShell (persistent) — open it as Administrator and run:
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-your-ciyuanx-api-key', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://ciyuanx.io', 'User')Or using Command Prompt (persistent):
setx ANTHROPIC_AUTH_TOKEN "sk-your-ciyuanx-api-key"
setx ANTHROPIC_BASE_URL "https://ciyuanx.io"Restart your terminal to apply the changes.
Method 2: Temporary configuration (current session only)
export ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
export ANTHROPIC_BASE_URL="https://ciyuanx.io"$env:ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
$env:ANTHROPIC_BASE_URL="https://ciyuanx.io"set ANTHROPIC_AUTH_TOKEN=sk-your-ciyuanx-api-key
set ANTHROPIC_BASE_URL=https://ciyuanx.ioMethod 3: Use Claude Code settings
Create or edit ~/.claude/settings.json:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "sk-your-ciyuanx-api-key",
"ANTHROPIC_BASE_URL": "https://ciyuanx.io"
}
}Method 4: Use CC Switch (GUI)
CC Switch is a Claude Code provider-switching tool with a graphical interface for managing multiple API provider configurations. See its repository for installation instructions.
Configure the CiYuanX provider:
- Run CC Switch to open the configuration interface
- Turn off the Live proxy toggle at the top (it routes requests through CC Switch's own proxy, which isn't needed)
- Add a new provider with the following details:
- Provider name: CiYuanX
- Note: CiYuanX
- Website:
https://ciyuanx.io - API Key: your CiYuanX API key
- Request URL:
https://ciyuanx.io(no trailing slash) - API format: Anthropic Messages (native)
- Primary model:
claude-opus-4-6 - Thinking model:
claude-opus-4-6-thinking - Default Haiku model:
claude-haiku-4-5-20251001 - Default Sonnet model:
claude-sonnet-4-5-20250929 - Default Opus model:
claude-opus-4-6
- Click “Save”
Using GPT models
Besides Claude models, you can have Claude Code call GPT-series models through CiYuanX. On top of the basic configuration above, set these additional environment variables:
| Variable | Description |
|---|---|
ANTHROPIC_MODEL | Primary model, e.g. code/gpt-5.5 |
ANTHROPIC_SMALL_FAST_MODEL | Small, fast model for lightweight tasks, e.g. code/gpt-5.4-mini |
ANTHROPIC_DEFAULT_SONNET_MODEL | Model the Sonnet tier maps to, e.g. code/gpt-5.5 |
ANTHROPIC_DEFAULT_OPUS_MODEL | Model the Opus tier maps to, e.g. code/gpt-5.5 |
ANTHROPIC_DEFAULT_HAIKU_MODEL | Model the Haiku tier maps to, e.g. code/gpt-5.4-mini |
ANTHROPIC_API_KEY | Leave empty to avoid conflicting with ANTHROPIC_AUTH_TOKEN |
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY | Set to 1 to enable gateway model discovery |
CLAUDE_CODE_ATTRIBUTION_HEADER | Set to 0 to disable the attribution header |
Tip
ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN are the same as in the basic configuration — no changes needed. Set ANTHROPIC_API_KEY explicitly to an empty string so it doesn't override ANTHROPIC_AUTH_TOKEN.
macOS and Linux
Add these lines to your shell profile (~/.bashrc or ~/.bash_profile for Bash, ~/.zshrc for Zsh):
export ANTHROPIC_BASE_URL="https://ciyuanx.io"
export ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
export ANTHROPIC_API_KEY=""
export ANTHROPIC_MODEL="code/gpt-5.5"
export ANTHROPIC_SMALL_FAST_MODEL="code/gpt-5.4-mini"
export ANTHROPIC_DEFAULT_SONNET_MODEL="code/gpt-5.5"
export ANTHROPIC_DEFAULT_OPUS_MODEL="code/gpt-5.5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="code/gpt-5.4-mini"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1
export CLAUDE_CODE_ATTRIBUTION_HEADER=0Apply the changes:
source ~/.zshrc # or source ~/.bashrcWindows
Using PowerShell (persistent) — open it as Administrator and run:
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_BASE_URL', 'https://ciyuanx.io', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_AUTH_TOKEN', 'sk-your-ciyuanx-api-key', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', '', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_MODEL', 'code/gpt-5.5', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_SMALL_FAST_MODEL', 'code/gpt-5.4-mini', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_DEFAULT_SONNET_MODEL', 'code/gpt-5.5', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_DEFAULT_OPUS_MODEL', 'code/gpt-5.5', 'User')
[System.Environment]::SetEnvironmentVariable('ANTHROPIC_DEFAULT_HAIKU_MODEL', 'code/gpt-5.4-mini', 'User')
[System.Environment]::SetEnvironmentVariable('CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY', '1', 'User')
[System.Environment]::SetEnvironmentVariable('CLAUDE_CODE_ATTRIBUTION_HEADER', '0', 'User')Or using Command Prompt (persistent):
setx ANTHROPIC_BASE_URL "https://ciyuanx.io"
setx ANTHROPIC_AUTH_TOKEN "sk-your-ciyuanx-api-key"
setx ANTHROPIC_API_KEY ""
setx ANTHROPIC_MODEL "code/gpt-5.5"
setx ANTHROPIC_SMALL_FAST_MODEL "code/gpt-5.4-mini"
setx ANTHROPIC_DEFAULT_SONNET_MODEL "code/gpt-5.5"
setx ANTHROPIC_DEFAULT_OPUS_MODEL "code/gpt-5.5"
setx ANTHROPIC_DEFAULT_HAIKU_MODEL "code/gpt-5.4-mini"
setx CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY "1"
setx CLAUDE_CODE_ATTRIBUTION_HEADER "0"Restart your terminal to apply the changes. For a temporary, current-session-only setup, use $env:NAME="value" in PowerShell or set NAME=value in Command Prompt.
Verify the configuration
After starting Claude Code, run the /status command to check the configuration. If you see the following, the setup succeeded:
Anthropic base URL: https://ciyuanx.ioYou can also send a test message:
claude "Hi"If everything is configured correctly, Claude Code should respond using CiYuanX's API.
Check the environment variables:
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKENecho $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKENTroubleshooting
“Invalid API key” error
- Verify your API key is correct: Console → API Tokens
- Make sure there are no extra spaces in the environment variables
- Check that
ANTHROPIC_BASE_URLis set tohttps://ciyuanx.io(without/v1)
“Connection refused” error
- Verify your internet connection
- Check that you can reach
https://ciyuanx.ioin a browser - Make sure your firewall allows outbound HTTPS connections
Claude Code not found
macOS / Linux
# Check whether Claude Code is on your PATH
which claude
# If not found, add it to your PATH in ~/.zshrc or ~/.bashrc:
export PATH="$HOME/.claude/bin:$PATH"Windows
Verify that the PATH environment variable includes C:\Users\YourUsername\.claude\bin, then restart your terminal after adding it.