Skip to content

Claude Code Installation and Configuration

Claude Code Installation and Configuration

Section titled “Claude Code Installation and Configuration”

Overview

🔧 Claude Code Installation and 4All API Configuration Guide

Section titled “🔧 Claude Code Installation and 4All API Configuration Guide”

Claude Code is a powerful command-line AI coding assistant officially released by Anthropic. By following the steps below, you can quickly connect it to the 4All API aggregation platform. 4All API provides dedicated high-speed nodes for Claude Code and fully supports the following latest models:

📌 Supported model versions

  • claude-opus-4-6 - Mainstream Sonnet version
  • claude-opus-4-5-20251101 - Mainstream Sonnet version
  • claude-sonnet-4-5-20250929 - Latest Sonnet version
  • claude-haiku-4-5-20251001 - Haiku 4.5 version (lightweight)

  • Install Node.js: Make sure your system environment is ready.
  • Install Claude Code CLI: Install the command-line tool globally via npm.
  • Configure 4All API: Create a configuration file and enter your dedicated API key and our service endpoint.
  • Launch and use: Start Claude Code in your project directory and begin coding with AI.

Step 1: Install Node.js

  • Recommended: Visit the Node.js official website and download the Windows installer (.msi) for the LTS (Long-Term Support) version.
  • Alternative: Use a package manager such as winget and run winget install OpenJS.NodeJS.LTS from the command line.
  • Verify the installation: After installation, open a new command prompt window (CMD or PowerShell) and run node —version and npm —version.

Step 2: Install Claude Code CLI Run the command prompt as Administrator and execute the following command to install globally:

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

After installation, verify success with claude —version.

Step 3: Configure 4All API

  • Get an API key: Visit the 4All API console, log in, create a new token, and copy the generated key.
  • Create the configuration file: Find or create the configuration file at %USERPROFILE%.claude\settings.json.
  • Fill in the configuration: Put the following content into the settings.json file:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "Paste the key you obtained from 4All API here",
"ANTHROPIC_BASE_URL": "https://sg.4All API.com"
}
}

⚠️ Important: * Be sure to replace the value of ANTHROPIC_AUTH_TOKEN with your own real key.

Step 4: Launch and use Open the command line, use the cd command to enter your project folder, and run claude to start the tool. Follow the prompts shown on first launch to complete the initial setup.

Step 5: Switching models

  • By default, Claude Code starts with Claude Sonnet 4.6 (model ID: claude-sonnet-4-6)

  • To switch models in Claude Code: specify the model when launching from the command line, for example claude —model claude-opus-4-6, claude —model claude-haiku-4-5-20251001 Current mainstream models ┌────────────────────┬───────────────────────────┐ │ Model │ ID │ ├────────────────────┼───────────────────────────┤ │ Opus 4.6 (strongest)│ claude-opus-4-6 │ ├────────────────────┼───────────────────────────┤ │ Sonnet 4.6 (current)│ claude-sonnet-4-6 │ ├────────────────────┼───────────────────────────┤ │ Haiku 4.5 (fastest) │ claude-haiku-4-5-20251001 │ └────────────────────┴───────────────────────────┘ To switch within the current session: you can enter /model claude-opus-4-6 in the current terminal to switch.


Step 1: Install Node.js

  • Recommended: Use Homebrew to install. Open Terminal and run the following commands:
Terminal window
# If Homebrew is not installed, install it first
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Node.js
brew install node
  • Verify the installation: Run node —version and npm —version.

Step 2: Install Claude Code CLI Open Terminal and run:

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

Step 3: Configure 4All API

  • Get an API key: Visit the 4All API console, create a token, and copy the key.
  • Create the configuration file: Find or create the configuration file in your home directory: ~/.claude/settings.json.
  • Fill in the following content:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "Paste the key you obtained from 4All API here",
"ANTHROPIC_BASE_URL": "https://sg.4All API.com"
}
}

Step 4: Launch and use Open Terminal, cd to your project directory, and run claude to get started.


Step 1: Install Node.js Install it using your distribution’s package manager. Using Ubuntu/Debian as an example:

Terminal window
# Recommended: use NodeSource for a newer version
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
  • Verify the installation: Run node —version and npm —version.

Step 2: Install Claude Code CLI Open Terminal and run:

Terminal window
sudo npm install -g @anthropic-ai/claude-code

Step 3: Configure 4All API

  • Get an API key: Visit the 4All API console, create a token, and copy the key.
  • Create the configuration file: Find or create the configuration file in your home directory: ~/.claude/settings.json.
  • Fill in the following content:
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "Paste the key you obtained from 4All API here",
"ANTHROPIC_BASE_URL": "https://sg.4All API.com"
}
}

Step 4: Launch and use Open Terminal, cd to your project directory, and run claude to start coding.


I’ve prepared one-click setup scripts for both platforms:

Section titled “I’ve prepared one-click setup scripts for both platforms:”

🪟 Windows one-click setup script (.bat)

Section titled “🪟 Windows one-click setup script (.bat)”
  • Create a new text file on your computer.
  • Copy the following code into it:
Terminal window
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ========================================
echo Claude Code - 4All API Windows 一键配置工具
echo ========================================
echo.
REM 设置 .claude 文件夹路径
set "CLAUDE_PATH=%USERPROFILE%\.claude"
REM 检查并创建目录
if not exist "%CLAUDE_PATH%" (
mkdir "%CLAUDE_PATH%"
echo [√] 已自动创建文件夹: %CLAUDE_PATH%
) else (
echo [*] 文件夹已存在: %CLAUDE_PATH%
)
echo.
echo ========================================
REM 提示用户输入密钥
set /p API_KEY="请输入您在 4All API 控制台获取的 API 密钥 (sk-开头): "
REM 创建并写入 settings.json
(
echo {
echo "env": {
echo "ANTHROPIC_AUTH_TOKEN": "%API_KEY%",
echo "ANTHROPIC_BASE_URL": "https://sg.4All API.com"
echo }
echo }
) > "%CLAUDE_PATH%\settings.json"
echo.
echo [√] 已成功创建并写入配置文件: %CLAUDE_PATH%\settings.json
echo.
echo ========================================
echo 🎉 恭喜!配置已全部自动完成!
echo.
echo.
echo 您现在可以打开新的命令行窗口,输入 claude 开始体验了。
echo ========================================
echo.
pause
  • Save the file and rename it to 4All API_Claude_Windows.bat. Then double-click it in Windows to run.

🍎/🐧 macOS and Linux one-click setup script (.sh)

Section titled “🍎/🐧 macOS and Linux one-click setup script (.sh)”

Mac and Linux users are often more accustomed to running scripts directly in the terminal.

  • Create a new text file and copy the following code into it:
#!/bin/bash
echo "========================================"
echo " Claude Code - 4All API Mac/Linux 一键配置工具"
echo "========================================"
echo ""
CLAUDE_PATH="$HOME/.claude"
# 检查并创建目录
if [ ! -d "$CLAUDE_PATH" ]; then
mkdir -p "$CLAUDE_PATH"
echo "[√] 已自动创建文件夹: $CLAUDE_PATH"
else
echo "[*] 文件夹已存在: $CLAUDE_PATH"
fi
echo ""
# 提示用户输入密钥
read -p "请输入您在 4All API 控制台获取的 API 密钥 (sk-开头): " API_KEY
# 写入配置文件
cat > "$CLAUDE_PATH/settings.json" << EOF
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "$API_KEY",
"ANTHROPIC_BASE_URL": "https://sg.4All API.com"
}
}
EOF
echo ""
echo "[√] 已成功创建并写入配置文件: $CLAUDE_PATH/settings.json"
echo ""
echo "========================================"
echo "🎉 恭喜!配置已全部自动完成!"
echo ""
echo ""
echo "您现在可以直接在终端输入 claude 开始体验了。"
echo "========================================"
echo ""
  • Save it as 4All API_Claude_MacLinux.sh.