简繁EN
← ToolsTools · Guide

Installing Claude Code from Scratch (with cc-switch for API Setup)

Install Claude Code, then use cc-switch to set up and switch API providers in a few clicks. Includes common problems and fixes.

Date
Reading3 min read
Tags#Claude Code#cc-switch

This guide uses cc-switch to manage API settings. Instead of setting environment variables such as your API key by hand, you add and switch providers with a few clicks in cc-switch.

cc-switch is free and open source. Its only official sources are ccswitch.io and farion1231/cc-switch on GitHub. Fake sites have been asking for money lately; don’t pay anyone for it.

What you need

  • A computer running macOS 13+, Windows 10+ or a recent Linux
  • A working API key: Claude’s own, or a compatible service such as DeepSeek, Zhipu, Kimi or OpenRouter

1. Install Claude Code

The officially recommended installer doesn’t need Node.js and keeps Claude Code updated in the background.

macOS and Linux:

curl -fsSL https://claude.ai/install.sh | bash

Windows (PowerShell):

irm https://claude.ai/install.ps1 | iex

When it finishes, open a new terminal window and check the install (it prints a version number):

claude --version

Alternative: install with npm

If you prefer npm, you need Node.js 22 or later first. On macOS you can get Node.js from Homebrew:

brew install node
node --version

Then install Claude Code:

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

Don’t use sudo npm install -g; it tends to cause permission problems.

2. Install cc-switch

macOS (Homebrew recommended):

brew install --cask cc-switch

To update later:

brew upgrade --cask cc-switch

You can also download the .dmg from the Releases page. It is signed and notarized by Apple; double-click to install.

Windows: download the .msi (installer) or -Portable.zip (no install) from the Releases page.

Linux: download the .deb, .rpm or .AppImage from the Releases page. On Arch you can use paru:

paru -S cc-switch-bin

3. Set up your API in cc-switch

  1. Open cc-switch. On first launch it asks whether to import an existing configuration; skip it if you have none.
  2. Click the + button in the toolbar to add a provider.
  3. Choose Claude Code as the app.
  4. Pick your provider from the presets (Claude, DeepSeek, Zhipu GLM, Kimi, OpenRouter and others). The name and endpoint fill in automatically.
  5. Enter your API key and save.
  6. Back on the main screen, select the new card and click Enable.

Provider not in the presets? Create a custom configuration and fill in ANTHROPIC_API_KEY (required) and ANTHROPIC_BASE_URL (the endpoint). If the service doesn’t speak Anthropic’s native format, set Upstream Format under Advanced Options to OpenAI Chat Completions or OpenAI Responses API, then go to Settings → Routing → Local Routing, turn on the master switch and enable Claude Code. Without routing you’ll usually get a 404 or 405 error.

4. Check that it works

You usually don’t need to restart Claude Code after enabling a provider. Open a new terminal and run:

claude -p "hello"

If you get an answer, the install and API setup are done.

5. Start using it

Open your project folder and start an interactive session:

cd your-project
claude

Ask a single question without entering interactive mode:

claude -p "explain the structure of this project"

Start with a specific model (opus, sonnet and haiku always point to the latest of each family):

claude --model opus

Inside Claude Code, the commands you’ll use most are /model (switch model), /clear (start over) and /help. For more, see A Claude Code Command Cheat Sheet.

6. Switching providers

When one provider runs out of credit, pick another card in cc-switch’s main window or menu bar icon and click Enable. No config files to edit.

Common problems

Problem Fix
command not found: claude The install folder isn’t on your PATH. Open a new terminal first; if that doesn’t help, run claude doctor or see the official troubleshooting guide
npm complains that Node is too old Upgrade to Node.js 22 or later
Still using the old settings after enabling Environment variables you set yourself override cc-switch. Run echo $ANTHROPIC_API_KEY; if it prints something, delete the matching export line from ~/.zshrc and reopen the terminal
Can’t connect from mainland China Set a proxy: export HTTPS_PROXY=http://your-proxy-address