> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yelu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code

> Configure Claude Code to use Yelu AI API on macOS, native Windows, and WSL 2 through the Anthropic Messages API.

Claude Code can route Anthropic Messages requests through Yelu. The configuration uses the gateway root URL `https://api.yelu.ai`; Claude Code appends `/v1/messages` itself.

<Info>
  Use a model returned by [`GET /v1/models`](/en/api-reference/models). The commands below use `claude-sonnet-4-6`, which is supported by the Yelu gateway but may need to be enabled for your key.
</Info>

## Configuration at a glance

| Setting                    | Value                       |
| -------------------------- | --------------------------- |
| Base URL                   | `https://api.yelu.ai`       |
| Credential variable        | `ANTHROPIC_AUTH_TOKEN`      |
| Header sent by Claude Code | `Authorization: Bearer ...` |
| API format                 | Anthropic Messages          |
| Example model              | `claude-sonnet-4-6`         |

Do not add `/v1` to `ANTHROPIC_BASE_URL`. Doing so would produce an invalid `/v1/v1/messages` path.

## macOS

### 1. Install Claude Code

The native installer is the recommended installation method:

```bash macOS theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -fsSL https://claude.ai/install.sh | bash
claude --version
```

Homebrew is also supported:

```bash macOS theme={"theme":{"light":"github-light","dark":"github-dark"}}
brew install --cask claude-code
```

### 2. Configure the current terminal

Copy a key from the Yelu Console, then run:

```bash macOS theme={"theme":{"light":"github-light","dark":"github-dark"}}
read -s "YELU_API_KEY?Yelu API key: "
echo
export YELU_API_KEY
export ANTHROPIC_AUTH_TOKEN="$YELU_API_KEY"
export ANTHROPIC_BASE_URL="https://api.yelu.ai"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
```

This keeps the key out of shell history. These variables last until the terminal closes.

### 3. Persist non-secret settings

Add the following lines to `~/.zshrc`:

```bash ~/.zshrc theme={"theme":{"light":"github-light","dark":"github-dark"}}
export ANTHROPIC_BASE_URL="https://api.yelu.ai"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
```

Then reload the profile:

```bash macOS theme={"theme":{"light":"github-light","dark":"github-dark"}}
source ~/.zshrc
```

Load `YELU_API_KEY` from your secret manager at login and set `ANTHROPIC_AUTH_TOKEN="$YELU_API_KEY"`. Do not commit keys to a repository or store them in a shared shell profile.

## Windows

### Native PowerShell

Install without opening PowerShell as Administrator:

```powershell Windows PowerShell theme={"theme":{"light":"github-light","dark":"github-dark"}}
irm https://claude.ai/install.ps1 | iex
claude --version
```

Configure the current PowerShell session without echoing the key:

```powershell Windows PowerShell theme={"theme":{"light":"github-light","dark":"github-dark"}}
$secret = Read-Host "Yelu API key" -AsSecureString
$env:YELU_API_KEY = [System.Net.NetworkCredential]::new("", $secret).Password
$env:ANTHROPIC_AUTH_TOKEN = $env:YELU_API_KEY
$env:ANTHROPIC_BASE_URL = "https://api.yelu.ai"
$env:CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY = "1"
```

Persist the non-secret settings for future terminals:

```powershell Windows PowerShell theme={"theme":{"light":"github-light","dark":"github-dark"}}
[Environment]::SetEnvironmentVariable("ANTHROPIC_BASE_URL", "https://api.yelu.ai", "User")
[Environment]::SetEnvironmentVariable("CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY", "1", "User")
```

Open a new terminal after changing user-level variables. Load the key from your Windows credential manager or enter it at the start of each session. A user environment variable is convenient but is not a secret store.

Git for Windows is optional. If installed but Claude Code cannot locate Git Bash, add this to `%USERPROFILE%\.claude\settings.json`:

```json Claude settings theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "env": {
    "CLAUDE_CODE_GIT_BASH_PATH": "C:\\Program Files\\Git\\bin\\bash.exe"
  }
}
```

### WSL 2

Use WSL 2 when the repository and toolchain live in Linux or when you need Claude Code sandboxing. Install and configure Claude Code inside the WSL terminal, not in PowerShell:

```bash WSL 2 theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -fsSL https://claude.ai/install.sh | bash
read -rsp "Yelu API key: " YELU_API_KEY; echo
export YELU_API_KEY
export ANTHROPIC_AUTH_TOKEN="$YELU_API_KEY"
export ANTHROPIC_BASE_URL="https://api.yelu.ai"
export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY="1"
claude --version
```

For WSL, persistent shell settings belong in `~/.bashrc` or `~/.zshrc` inside the Linux distribution. Windows user environment variables are not a reliable substitute for WSL shell variables.

## Optional settings file

Claude Code reads `~/.claude/settings.json` on macOS and `%USERPROFILE%\.claude\settings.json` on Windows. This safe global configuration persists the URL and model discovery without storing a key:

```json Claude settings theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.yelu.ai",
    "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1"
  }
}
```

Use `.claude/settings.local.json` for project-local secrets and ensure it is ignored by Git. Never put a key in the shared `.claude/settings.json` inside a repository.

## Verify the gateway

Test the API before starting Claude Code:

<CodeGroup>
  ```bash macOS / WSL theme={"theme":{"light":"github-light","dark":"github-dark"}}
  curl -sS "$ANTHROPIC_BASE_URL/v1/messages" \
    -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
    -H "anthropic-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d '{
      "model": "claude-sonnet-4-6",
      "max_tokens": 16,
      "messages": [{"role": "user", "content": "Reply with: ready"}]
    }'
  ```

  ```powershell Windows PowerShell theme={"theme":{"light":"github-light","dark":"github-dark"}}
  $body = @{
    model = "claude-sonnet-4-6"
    max_tokens = 16
    messages = @(@{ role = "user"; content = "Reply with: ready" })
  } | ConvertTo-Json -Depth 4

  Invoke-RestMethod -Method Post `
    -Uri "$env:ANTHROPIC_BASE_URL/v1/messages" `
    -Headers @{
      Authorization = "Bearer $env:ANTHROPIC_AUTH_TOKEN"
      "anthropic-version" = "2023-06-01"
    } `
    -ContentType "application/json" `
    -Body $body
  ```
</CodeGroup>

Then start Claude Code from the same terminal:

```bash Terminal theme={"theme":{"light":"github-light","dark":"github-dark"}}
claude --model claude-sonnet-4-6
```

Run `/status` inside Claude Code. `Anthropic base URL` should show `https://api.yelu.ai`, and the credential source should be `ANTHROPIC_AUTH_TOKEN`. Run `/model` to select another model exposed by your Yelu account.

## Update and diagnose

```bash Terminal theme={"theme":{"light":"github-light","dark":"github-dark"}}
claude update
claude doctor
claude --debug
```

| Symptom                                | Fix                                                                                                         |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| `401 Unauthorized`                     | Confirm `ANTHROPIC_AUTH_TOKEN` is set in the same terminal and contains a valid Yelu key.                   |
| Request goes to Anthropic              | Run `/status`; correct `ANTHROPIC_BASE_URL` and restart Claude Code from the configured shell.              |
| `/v1/v1/messages` or `404`             | Remove `/v1` from the base URL.                                                                             |
| Unknown model                          | Use `/model` or [`GET /v1/models`](/en/api-reference/models) and select a Claude model enabled for the key. |
| Models do not appear                   | Update Claude Code and run `claude --debug` to inspect `[gatewayDiscovery]` messages.                       |
| Windows terminal cannot see new values | Close and reopen the terminal after setting user environment variables.                                     |

## Next step

Continue with the [Claude Code examples](/en/examples/claude-code) for repository exploration, implementation, review, and automation workflows.

## Official references

* [Claude Code advanced setup](https://code.claude.com/docs/en/getting-started)
* [Connect Claude Code to an LLM gateway](https://code.claude.com/docs/en/llm-gateway-connect)
* [Claude Code gateway protocol](https://code.claude.com/docs/en/llm-gateway-protocol)
