# Claude Code

**An easier way**
- Use [magpie](https://docs.2api.dev/en/magpie/) to switch with one click. You don't touch any config files.
- Or, in the API Keys (API 密钥) list in the console, click Use Key (使用密钥) next to your key and copy the Claude Code configuration the console generates.

Before you start, create a key in the **`CC-Max` group** in the console. Claude Code can't use a key from a GPT group.

## Install

Use the official installer. In a terminal, run the one for your system:

```bash
  curl -fsSL https://claude.ai/install.sh | bash
  ```
  ```powershell
  irm https://claude.ai/install.ps1 | iex
  ```
  ```batch
  curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
  ```
  ```bash
  brew install --cask claude-code
  winget install Anthropic.ClaudeCode
  npm install -g @anthropic-ai/claude-code
  ```
  The npm method needs Node.js 22 or later. Don't use `sudo`.
  After installing, **reopen your terminal** and run `claude --version`. If it prints a version number, you are set.

## Configure

1. Open `~/.claude/settings.json` (on Windows, `%USERPROFILE%\.claude\settings.json`). Create it if it doesn't exist, and write:

   ```json title="~/.claude/settings.json"
   {
     "env": {
       "ANTHROPIC_BASE_URL": "https://2api.dev",
       "ANTHROPIC_AUTH_TOKEN": "sk-your-key",
       "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1"
     }
   }
   ```

   - The address is the root address. **Do not add `/v1`.** Claude Code adds `/v1/messages` itself.
   - If the file already has other settings, merge these lines into `env`. Don't overwrite the whole file.
   - JSON doesn't allow comments, and the last item can't be followed by a comma.

2. Configure first, then start. If you finish step 1 before you run `claude` for the first time, the login screen usually doesn't appear. If it still asks you to sign in:

1. Press `Ctrl + C` to quit Claude Code.
2. Open `.claude.json` in your user folder. It sits next to the `.claude` folder. Note that this is not `settings.json`.
3. Under the `{` on the first line, add the line `"hasCompletedOnboarding": true,`. Don't leave out the comma at the end.
4. Save the file, then run `claude` again.

   This setting isn't in the official documentation, but tools such as CC Switch use it the same way to skip the first-run setup. To restore the official login later, delete this line.

3. Go to your project directory and start it. In the terminal, type `cd` followed by a space, drag your project folder into the terminal window and press Enter. Then run `claude`:

   ```bash
   cd your-project
   claude
   ```

   In Claude Code, type `/status`. If the Anthropic base URL shows `https://2api.dev`, the configuration is in effect. Use `/model` to switch models.

**Update it manually**
`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` also turns off automatic updates. Run `claude update` every so often. A version that is too old can have a low cache hit rate and charge you more than it should.

## Try it temporarily

Don't change any files. Set the environment variables in the current terminal. They stop working when you close the window.

```bash
  export ANTHROPIC_BASE_URL="https://2api.dev"
  export ANTHROPIC_AUTH_TOKEN="sk-your-key"
  export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
  claude
  ```
  ```powershell
  $env:ANTHROPIC_BASE_URL="https://2api.dev"
  $env:ANTHROPIC_AUTH_TOKEN="sk-your-key"
  $env:CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
  claude
  ```
  ```batch
  set ANTHROPIC_BASE_URL=https://2api.dev
  set ANTHROPIC_AUTH_TOKEN=sk-your-key
  set CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
  claude
  ```
  In CMD, **don't use quotes** after the equals sign. The quotes become part of the value.
  **Set only one key variable**
Don't set `ANTHROPIC_AUTH_TOKEN` and `ANTHROPIC_API_KEY` at the same time. If you do, Claude Code reports an authentication conflict. If your system environment variables or `~/.zshrc` still contain an old `ANTHROPIC_API_KEY`, delete it first.

## Model not found in background tasks

Claude Code uses a smaller model for background tasks. If the error shows a model name you haven't used (such as haiku), also set the background models to a model your group has:

```json title="~/.claude/settings.json" ins={6-7}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://2api.dev",
    "ANTHROPIC_AUTH_TOKEN": "sk-your-key",
    "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1",
    "ANTHROPIC_DEFAULT_HAIKU_MODEL": "a-model-in-your-group",
    "CLAUDE_CODE_SUBAGENT_MODEL": "a-model-in-your-group"
  }
}
```

Look up model names with [`/v1/models`](https://docs.2api.dev/en/start/endpoints/#model-names).

## Next steps

- To use it in VS Code or Cursor: [Claude Code extension](https://docs.2api.dev/en/clients/claude-code-ide/)
- If you get an error: [Claude Code FAQ](https://docs.2api.dev/en/faq/claude-code/)