Skip to content

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:

sh
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:

sh
# Set the Node.js download source to the npmmirror mirror
export NVM_NODEJS_ORG_MIRROR=https://npmmirror.com/mirrors/node/
# Apply the configuration
source ~/.bashrc

Note

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:

sh
nvm install --lts

Verify that Node.js and npm were installed successfully:

sh
node -v
npm -v

2. Install Claude Code

Install Claude Code globally:

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

If you run into permission issues, use sudo:

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

Verify the installation:

sh
claude --version

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

  1. 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.
  2. Run the installer: double-click the downloaded .msi file and click Next as prompted.
  3. 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.
  4. Continue to the next step and make sure Add to PATH is selected, so the installer adds the node and npm commands to your system environment variables.
  5. 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.
  6. Click Install and wait for the installation to finish.

After installation, open Command Prompt (cmd) or PowerShell and verify the installation:

powershell
node -v
npm -v

If 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:

powershell
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:

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

Verify the installation:

powershell
claude --version

If a version number is displayed, congratulations — Claude Code has been installed successfully.

Configuration

To use CiYuanX with Claude Code, set two environment variables:

VariableDescription
ANTHROPIC_AUTH_TOKENYour CiYuanX API key
ANTHROPIC_BASE_URLCiYuanX's API endpoint (https://ciyuanx.io)

Choose one of the configuration methods below.

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):

sh
export ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
export ANTHROPIC_BASE_URL="https://ciyuanx.io"

Apply the changes:

sh
source ~/.zshrc  # or source ~/.bashrc

Windows

Using PowerShell (persistent) — open it as Administrator and run:

powershell
[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):

bat
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)

sh
export ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
export ANTHROPIC_BASE_URL="https://ciyuanx.io"
powershell
$env:ANTHROPIC_AUTH_TOKEN="sk-your-ciyuanx-api-key"
$env:ANTHROPIC_BASE_URL="https://ciyuanx.io"
bat
set ANTHROPIC_AUTH_TOKEN=sk-your-ciyuanx-api-key
set ANTHROPIC_BASE_URL=https://ciyuanx.io

Method 3: Use Claude Code settings

Create or edit ~/.claude/settings.json:

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:

  1. Run CC Switch to open the configuration interface
  2. Turn off the Live proxy toggle at the top (it routes requests through CC Switch's own proxy, which isn't needed)
  3. 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
  4. 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:

VariableDescription
ANTHROPIC_MODELPrimary model, e.g. code/gpt-5.5
ANTHROPIC_SMALL_FAST_MODELSmall, fast model for lightweight tasks, e.g. code/gpt-5.4-mini
ANTHROPIC_DEFAULT_SONNET_MODELModel the Sonnet tier maps to, e.g. code/gpt-5.5
ANTHROPIC_DEFAULT_OPUS_MODELModel the Opus tier maps to, e.g. code/gpt-5.5
ANTHROPIC_DEFAULT_HAIKU_MODELModel the Haiku tier maps to, e.g. code/gpt-5.4-mini
ANTHROPIC_API_KEYLeave empty to avoid conflicting with ANTHROPIC_AUTH_TOKEN
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERYSet to 1 to enable gateway model discovery
CLAUDE_CODE_ATTRIBUTION_HEADERSet 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):

sh
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=0

Apply the changes:

sh
source ~/.zshrc  # or source ~/.bashrc

Windows

Using PowerShell (persistent) — open it as Administrator and run:

powershell
[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):

bat
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.io

You can also send a test message:

sh
claude "Hi"

If everything is configured correctly, Claude Code should respond using CiYuanX's API.

Check the environment variables:

sh
echo $ANTHROPIC_BASE_URL
echo $ANTHROPIC_AUTH_TOKEN
powershell
echo $env:ANTHROPIC_BASE_URL
echo $env:ANTHROPIC_AUTH_TOKEN

Troubleshooting

“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_URL is set to https://ciyuanx.io (without /v1)

“Connection refused” error

  • Verify your internet connection
  • Check that you can reach https://ciyuanx.io in a browser
  • Make sure your firewall allows outbound HTTPS connections

Claude Code not found

macOS / Linux

sh
# 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.