# Claude Code tutorial

Configure Claude Code with KaiyunCode, including the API key, base URL, and common errors.

Canonical: https://kaiyuncode.com/tutorials/claude-code
Markdown: https://kaiyuncode.com/tutorials/claude-code.en.md

## Setup

Claude Code uses the Anthropic-compatible route. Set its base URL to https://kaiyuncode.com. Do not append /v1.

Put the KaiyunCode API key in ANTHROPIC_AUTH_TOKEN and leave ANTHROPIC_API_KEY empty, so Claude Code does not prefer the wrong variable.

- Config directory: %USERPROFILE%\.claude on Windows, ~/.claude on macOS and Linux.
- settings.json goes inside .claude and stores ANTHROPIC_AUTH_TOKEN, ANTHROPIC_API_KEY, and ANTHROPIC_BASE_URL.
- .claude.json goes in the user home directory and marks onboarding complete so the first login is skipped.
- Check it by running claude, allowing the current folder, and sending a short message.

## Install Claude Code

Install Node.js 18 or newer, then install the Claude Code CLI. Use an administrator PowerShell on Windows, and a terminal on macOS or Linux.

### Windows PowerShell

```powershell
node --version
npm install -g @anthropic-ai/claude-code
```

### macOS

```bash
brew install node
node --version
npm install -g @anthropic-ai/claude-code
```

### Linux

```bash
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
node --version
npm install -g @anthropic-ai/claude-code
```

## Verify Claude Code

Open a new terminal or IDE and run claude. Choose yes when it asks to access the current folder, then send a short message.

### settings.json

```json
{
  "env": {
    "ANTHROPIC_AUTH_TOKEN": "REPLACE_WITH_YOUR_API_KEY",
    "ANTHROPIC_API_KEY": "",
    "ANTHROPIC_BASE_URL": "https://kaiyuncode.com"
  }
}
```

## Claude Code troubleshooting

- 401 or /login usually means the API key or environment variable was not saved. Check settings.json.
- ANTHROPIC_BASE_URL must be https://kaiyuncode.com, not https://kaiyuncode.com/v1.
- .claude.json belongs in the user home directory. settings.json belongs in .claude. Do not swap those paths.
- If Windows blocks the script, adjust ExecutionPolicy from an administrator PowerShell and try again.
