Chapter 4013 min read
Connect Claude Code
Install Claude Code, connect it to CCHP with a configuration manager or by editing its config file manually, and verify the connection.
Claude Code is Anthropic’s command-line coding assistant. After installation, use a configuration manager or configure it manually to use the CCHP gateway, an LLM key, and models your organization provides.
What you need#
- LLM key: A full key whose status is Active (not the masked key in the list). If you don’t have one yet, see Create an LLM key.
- Gateway URL: In the console sidebar, click API Keys, then copy the URL in the Claude row of the API base URLs card at the top of the page, for example
https://api.cchp.example.com. This URL has no/v1at the end, because Claude Code adds the request path itself. If the page doesn’t show this card, ask your admin for the gateway URL.
Already installed Claude Code? Skip to configuration.
Step 1: Install Claude Code#
Select your operating system and use any one of the installation methods. The first method in each tab is the officially recommended one. Don’t run claude right after you install it: until the gateway is configured, Claude Code asks you to sign in to a claude.ai account on first launch. Start it after you finish configuring CCHP.
macOS
System requirements: macOS 13.0 or later, Apple silicon or Intel, and at least 4 GB of RAM.
Official install script (recommended)
Open Terminal and run:
curl -fsSL https://claude.ai/install.sh | bashThe install script shows no progress while it downloads. It installs the program to ~/.local/bin/claude, and the program then updates automatically in the background. You can also run claude update at any time to update right away.
If running claude prints command not found: claude, the install directory isn’t on your PATH. macOS uses Zsh by default. Run the two lines below to add the directory to your PATH:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcIf you use Bash, replace ~/.zshrc in both lines with ~/.bash_profile.
Homebrew
If you have Homebrew installed, run:
brew install --cask claude-codeclaude-code follows the stable channel and is usually about a week behind the latest version. To use the latest version, install claude-code@latest instead:
brew install --cask claude-code@latestHomebrew installations don’t update automatically, so run brew upgrade claude-code regularly. If you installed claude-code@latest, run brew upgrade claude-code@latest. If the installation prints No Cask with this name exists, run brew update first and try again.
npm
Requires Node.js 22 or later. Run:
npm install -g @anthropic-ai/claude-codeDon’t use sudo npm install -g, to avoid permission issues. npm installs the same program as the official install script. To upgrade right away, run npm install -g @anthropic-ai/claude-code@latest, not npm update -g.
Linux
System requirements: Ubuntu 20.04 or later, Debian 10 or later, or Alpine Linux 3.19 or later; an x64 or ARM64 processor; and at least 4 GB of RAM. On Fedora and RHEL, you can install from the official dnf repository.
Official install script (recommended)
Works on all distributions. In a terminal, run:
curl -fsSL https://claude.ai/install.sh | bashThe install script shows no progress while it downloads. It installs the program to ~/.local/bin/claude, and the program then updates automatically in the background. You can also run claude update at any time to update right away.
If running claude prints claude: command not found, the install directory isn’t on your PATH. If you use Bash, run the two lines below to add the directory to your PATH. If you use Zsh, replace ~/.bashrc in both lines with ~/.zshrc:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcTo use the install script on Alpine Linux, first install, as the root user, the packages that the install script and Claude Code need to run:
apk add bash curl libgcc libstdc++ ripgrepIf apk can’t find ripgrep, add the community repository and retry apk add. Replace v3.22 with your Alpine version:
echo "https://dl-cdn.alpinelinux.org/alpine/v3.22/community" >> /etc/apk/repositories
apk updateAfter the installation finishes, add "USE_BUILTIN_RIPGREP": "0" to env in the settings file from step 3.
Linux package managers
Anthropic provides signed apt, dnf, and apk repositories. All of the commands below use the stable channel (stable), which is usually about a week behind the latest version. To use the latest version, replace every stable in the repository URLs with latest. Claude Code installed with a package manager doesn’t update automatically, so update it with your system’s upgrade command.
apt (Debian, Ubuntu): If your system doesn’t have curl or gpg, first run sudo apt install curl gnupg. Then download the signing key and check its fingerprint:
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSL https://downloads.claude.ai/keys/claude-code.asc \
-o /etc/apt/keyrings/claude-code.asc
gpg --show-keys /etc/apt/keyrings/claude-code.ascAfter you confirm that the printed fingerprint is 31DDDE24DDFAB679F42D7BD2BAA929FF1A7ECACE, add the repository and install:
echo "deb [signed-by=/etc/apt/keyrings/claude-code.asc] https://downloads.claude.ai/claude-code/apt/stable stable main" \
| sudo tee /etc/apt/sources.list.d/claude-code.list
sudo apt update
sudo apt install claude-codeTo upgrade later, run sudo apt update && sudo apt upgrade claude-code.
dnf (Fedora, RHEL):
sudo tee /etc/yum.repos.d/claude-code.repo <<'EOF'
[claude-code]
name=Claude Code
baseurl=https://downloads.claude.ai/claude-code/rpm/stable
enabled=1
gpgcheck=1
gpgkey=https://downloads.claude.ai/keys/claude-code.asc
EOF
sudo dnf install claude-codeOn the first installation, dnf asks you to confirm the key fingerprint. Accept it only after you confirm that it is 31DD DE24 DDFA B679 F42D 7BD2 BAA9 29FF 1A7E CACE. To upgrade later, run sudo dnf upgrade claude-code.
apk (Alpine Linux), run as the root user:
wget -O /etc/apk/keys/claude-code.rsa.pub \
https://downloads.claude.ai/keys/claude-code.rsa.pub
echo "https://downloads.claude.ai/claude-code/apk/stable" >> /etc/apk/repositories
apk add claude-codeRun sha256sum /etc/apk/keys/claude-code.rsa.pub to verify the key. The result should be 395759c1f7449ef4cdef305a42e820f3c766d6090d142634ebdb049f113168b6. To upgrade later, run apk update && apk upgrade claude-code.
npm
Requires Node.js 22 or later. Run:
npm install -g @anthropic-ai/claude-codeDon’t use sudo npm install -g, to avoid permission issues. npm installs the same program as the official install script. To upgrade right away, run npm install -g @anthropic-ai/claude-code@latest, not npm update -g.
Windows
System requirements: 64-bit Windows 10 1809 or later, or Windows Server 2019 or later, and at least 4 GB of RAM. The installation doesn’t require administrator rights.
We recommend that you install Git for Windows first and choose to add Git to PATH during setup. When Git for Windows is installed, Claude Code runs commands in Git Bash. When it isn’t, Claude Code runs commands in PowerShell instead.
If Git for Windows is installed but Claude Code says it can’t find Git Bash, add CLAUDE_CODE_GIT_BASH_PATH to env in the settings file from step 3, with the full path of bash.exe as the value, for example "C:\\Program Files\\Git\\bin\\bash.exe" (backslashes must be doubled in JSON).
PowerShell install script (recommended)
Open PowerShell (the prompt starts with PS C:\) and run:
irm https://claude.ai/install.ps1 | iexCMD install script
Open Command Prompt (the prompt starts with C:\, with no PS before it) and run:
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmdIf you see The token '&&' is not a valid statement separator, you ran the CMD command in PowerShell. If you see 'irm' is not recognized, you ran the PowerShell command in CMD. Use the matching command instead.
Both install scripts install the program to %USERPROFILE%\.local\bin\claude.exe and show no progress while they download. Claude Code then updates automatically in the background. You can also run claude update at any time to update right away.
If running claude prints 'claude' is not recognized, the install directory isn’t on your PATH. Run the two lines below in PowerShell to add the directory to your user PATH, then reopen the terminal:
$currentPath = [Environment]::GetEnvironmentVariable('PATH', 'User')
[Environment]::SetEnvironmentVariable('PATH', "$currentPath;$env:USERPROFILE\.local\bin", 'User')WinGet
In PowerShell or Command Prompt, run:
winget install Anthropic.ClaudeCodeWinGet installations don’t update automatically, so run winget upgrade Anthropic.ClaudeCode regularly.
npm
Requires Node.js 22 or later. Run:
npm install -g @anthropic-ai/claude-codeIf PowerShell says running scripts is disabled on this system, run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser and try again, or use the PowerShell install script instead. To upgrade right away, run npm install -g @anthropic-ai/claude-code@latest.
WSL
To use Claude Code in WSL, open a terminal for your WSL distribution and run the Linux install script:
curl -fsSL https://claude.ai/install.sh | bashFrom then on, always run claude in the WSL terminal, not in PowerShell or Command Prompt. WSL doesn’t need Git for Windows. For the other Linux installation methods and PATH setup, see the Linux tab.
After the installation finishes, open a new terminal window and run:
claude --versionResult: The terminal prints a version number followed by (Claude Code). If claude can’t be found, add the install directory to your PATH as described in the tab for your system above. To check the installation and the settings files further, run claude doctor. This command only runs checks and doesn’t start a session.
After installation: Configure CCHP#
Recommended: Use Magpie or CC Switch to configure CCHP through a graphical interface. Once you verify the connection in that guide, you can start using the client without following the manual steps on this page.
Edit the config file manually: Start at step 2 to check the key and models, then edit the config file in step 3. You can also set environment variables for the current terminal only. The status check in step 4 is for the manual configuration.
Step 2: Check that your key works and list available models#
Run the command below in a terminal. Replace the URL with your gateway URL, and replace cch_llm_live_xxxxxxxx with your full key. This request doesn’t call a model and doesn’t incur any cost.
macOS / Linux
curl "https://api.cchp.example.com/v1/models?limit=1000" \
-H "Authorization: Bearer cch_llm_live_xxxxxxxx" \
-H "anthropic-version: 2023-06-01"In the returned data, the id of each item is a model ID.
Windows PowerShell
$headers = @{ "Authorization" = "Bearer cch_llm_live_xxxxxxxx"; "anthropic-version" = "2023-06-01" }
(Invoke-RestMethod -Uri "https://api.cchp.example.com/v1/models?limit=1000" -Headers $headers).data.idEach line of output is one model ID.
Result: The response lists the models that this key can call in Claude Code. Note the models you want to use, because you enter their model IDs in step 3. If you get 401, check that you copied the whole key and that the key is still valid. If the connection fails, check the gateway URL.
The list may also include models from other vendors. Claude Code is designed for Claude models, so enter Claude model IDs in step 3. For the price of each model, see View available models.
Step 3: Write the Claude Code settings#
Write the settings to Claude Code’s user settings file so that they apply to all your projects and terminals. Open the settings file, or create it if it doesn’t exist:
- macOS, Linux, and WSL:
~/.claude/settings.json - Windows:
%USERPROFILE%\.claude\settings.json
Add the following content, and replace the URL, key, and models with your own values. If the file already has other settings, merge only these keys into the existing env.
{
"env": {
"ANTHROPIC_BASE_URL": "https://api.cchp.example.com",
"ANTHROPIC_AUTH_TOKEN": "cch_llm_live_xxxxxxxx",
"ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-5-5",
"ANTHROPIC_DEFAULT_SONNET_MODEL": "claude-sonnet-5-5",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "claude-haiku-5-5"
}
}ANTHROPIC_BASE_URL: The gateway URL. Don’t add/v1at the end. Otherwise, the gateway returns404with a message that starts withno API endpoint matches.ANTHROPIC_AUTH_TOKEN: Your LLM key. Claude Code sends it in theAuthorization: Bearerheader. You can useANTHROPIC_API_KEYinstead (sent in thex-api-keyheader), which the gateway also accepts, but Claude Code asks you to confirm the key the first time you use it.ANTHROPIC_DEFAULT_OPUS_MODEL,ANTHROPIC_DEFAULT_SONNET_MODEL,ANTHROPIC_DEFAULT_HAIKU_MODEL: The models that Claude Code’s Opus, Sonnet, and Haiku tiers call. Enter model IDs from the list in step 2. By default, Claude Code requests its built-in model names, which your organization may not provide, so requests may return404if you don’t set these variables. If only a few models are available, you can set all three variables to the same model. WhenANTHROPIC_DEFAULT_HAIKU_MODELis set, background tasks such as generating session titles also use that model.
Warning: Don’t put your key in the .claude/settings.json file in your project directory. That file is usually committed to the code repository, so everyone with access to the repository can see your key.
Use in the current terminal only#
If you don’t want to edit the settings file, set the same environment variables in a terminal, then run claude in that terminal:
macOS / Linux
export ANTHROPIC_BASE_URL="https://api.cchp.example.com"
export ANTHROPIC_AUTH_TOKEN="cch_llm_live_xxxxxxxx"
export ANTHROPIC_DEFAULT_OPUS_MODEL="claude-opus-5-5"
export ANTHROPIC_DEFAULT_SONNET_MODEL="claude-sonnet-5-5"
export ANTHROPIC_DEFAULT_HAIKU_MODEL="claude-haiku-5-5"Windows PowerShell
$env:ANTHROPIC_BASE_URL = "https://api.cchp.example.com"
$env:ANTHROPIC_AUTH_TOKEN = "cch_llm_live_xxxxxxxx"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL = "claude-opus-5-5"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL = "claude-sonnet-5-5"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL = "claude-haiku-5-5"These variables apply only to the current terminal and the programs started from it. To make them apply in new terminals too, add these lines to ~/.zshrc, ~/.bashrc, or your PowerShell profile $PROFILE. If the same variable is set in both the settings file and the terminal, the settings file takes precedence.
Step 4: Start Claude Code and check the connection#
Check the connection status#
Open a new terminal, go to your project directory, and run claude. The first time Claude Code starts in a folder, it asks whether you trust the folder. Confirm to enter the session. Then enter /status.
Result: On the Status tab, the Anthropic base URL line shows your gateway URL, and the Auth token line shows ANTHROPIC_AUTH_TOKEN. If there is no Anthropic base URL line, Claude Code didn’t read your settings. Check the location of the settings file and its JSON syntax.
Send a message#
Press Esc to close the status screen, then send any message, for example Hello.
Result: Claude replies normally.
View the request in Call Records#
In the console sidebar, click Call Records (a platform super admin’s sidebar shows Usage Records instead) to open the Request Logs page.
Result: In the latest record, the Model column shows the model you used, the Key column shows the name of this key, and the Status column shows 200. To see only the requests of this key, in API Keys, click the View request logs icon in the Actions column of the key’s row (when the table is narrow, the actions are collapsed into the menu at the end of the row).
Switch models#
- In Claude Code, enter
/modeland select Opus, Sonnet, or Haiku. The model that is actually called is the one you set for that tier in step 3. - To use a model outside the three tiers, enter
/modelfollowed by the model ID, for example/model claude-fable-5-1, or start Claude Code withclaude --model claude-fable-5-1. - To see the models that the gateway provides directly in the
/modellist, add"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"toenvin the settings file. When Claude Code starts, it reads the gateway’s model list and adds only the models whose IDs containclaudeoranthropic.
Frequently asked questions#
How do I troubleshoot Claude Code errors?#
Look up the status code and message from the error in the table below:
Why does Claude Code still ask me to sign in after it starts?#
Claude Code didn’t read your key. Make sure that ANTHROPIC_AUTH_TOKEN is in env in the user settings file ~/.claude/settings.json (%USERPROFILE%\.claude\settings.json on Windows), that the variable name is spelled correctly, and that the file is valid JSON. You can also set it in the terminal as described in “Use in the current terminal only” in step 3. If the key is only in a settings file in your project directory, Claude Code can’t read it during the sign-in step on first launch.
What do I do if Claude Code says there are two credential sources at startup?#
You signed in to Claude Code with a claude.ai account before. When ANTHROPIC_AUTH_TOKEN is set, requests go to the gateway with your LLM key, and the saved sign-in is no longer used. To remove this message, run /logout in Claude Code to clear the saved sign-in.
How do I configure the VS Code extension?#
The Claude Code extension for VS Code checks for sign-in credentials before it starts, and this check doesn’t read ~/.claude/settings.json. In the VS Code Command Palette, run Preferences: Open User Settings (JSON) and add the following content. Replace the URL and the key with your own values:
{
"claudeCode.environmentVariables": [
{ "name": "ANTHROPIC_BASE_URL", "value": "https://api.cchp.example.com" },
{ "name": "ANTHROPIC_AUTH_TOKEN", "value": "cch_llm_live_xxxxxxxx" }
]
}The extension also uses the model settings from the settings file in step 3.