# OpenCode: Claude and Codex configuration

> Register ScaleMax as an OpenAI-compatible OpenCode provider and choose the model family that belongs to the key.

## Automatic configuration

**macOS / Linux**

```bash
npm install -g scalemax@latest
scalemax
```

**Windows PowerShell**

```powershell
npm.cmd install -g scalemax@latest
scalemax.cmd
```

Windows PowerShell blocks npm’s .ps1 launchers by default (“running scripts is disabled on this system”), so these commands use the .cmd launcher: npx.cmd, npm.cmd, scalemax.cmd. In Command Prompt you can leave out .cmd.

Select **OpenCode**. The CLI detects the key's provider and billing mode, backs up `~/.config/opencode/opencode.json`, stores the credential in a user-only file, and adds only models returned for that key. A Claude-only key is configured through the same OpenAI-compatible chat adapter with the Claude model IDs. Run `scalemax doctor` to recheck the result.

## Shared secure key setup

For manual setup, store the key outside JSON. Running this again replaces the OpenCode ScaleMax key, so do not switch between unrelated API-credit and token-pack accounts without also changing the URL:

**macOS / Linux**

```bash
umask 077
mkdir -p "$HOME/.config/opencode"
printf "ScaleMax API key: "
IFS= read -r -s SCALEMAX_API_KEY
printf "\n"
printf "%s\n" "$SCALEMAX_API_KEY" > "$HOME/.config/opencode/scalemax.key"
unset SCALEMAX_API_KEY
chmod 600 "$HOME/.config/opencode/scalemax.key"
```

**Windows PowerShell**

```powershell
New-Item -ItemType Directory -Force -Path "$HOME\.config\opencode" | Out-Null
$secret = Read-Host "ScaleMax API key" -AsSecureString
[IO.File]::WriteAllText("$HOME\.config\opencode\scalemax.key", [System.Net.NetworkCredential]::new("", $secret).Password + "`n")
Remove-Variable secret
```

## Manual configuration for Codex models in OpenCode

Merge this provider into `~/.config/opencode/opencode.json` (Windows: `%USERPROFILE%\.config\opencode\opencode.json`). Preserve unrelated providers. For an OpenAI token-pack key, change only `baseURL` to `https://api.scalemax.pro/token/v1`.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "scalemax/gpt-5.6-terra",
  "small_model": "scalemax/gpt-5.6-luna",
  "provider": {
    "scalemax": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ScaleMax Codex",
      "options": {
        "baseURL": "https://api.scalemax.pro/v1",
        "apiKey": "{file:~/.config/opencode/scalemax.key}"
      },
      "models": {
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
        "gpt-6-sol": { "name": "GPT-6 Sol" },
        "gpt-6-luna": { "name": "GPT-6 Luna" },
        "gpt-6-astra": { "name": "GPT-6 Astra" },
        "gpt-5.6-terra": { "name": "GPT-5.6 Terra" },
        "gpt-5.6-sol": { "name": "GPT-5.6 Sol" },
        "gpt-5.6-luna": { "name": "GPT-5.6 Luna" }
      }
    }
  }
}
```

OpenCode sends these through its OpenAI-compatible adapter. It does not become the native Codex CLI, and some Responses-only behavior may not exist in this client.

**macOS / Linux**

```bash
opencode run --pure --model scalemax/gpt-5.6-luna --format json "K"
```

**Windows PowerShell**

```powershell
opencode run --pure --model scalemax/gpt-5.6-luna --format json "K"
```

## Manual configuration for Claude models in OpenCode

Use this version for a key that exposes Claude models. For a Claude token-pack key, change only `baseURL` to `https://api.scalemax.pro/token/v1`.

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "scalemax/claude-opus-5",
  "small_model": "scalemax/claude-haiku-4-5-20251001",
  "provider": {
    "scalemax": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "ScaleMax Claude",
      "options": {
        "baseURL": "https://api.scalemax.pro/v1",
        "apiKey": "{file:~/.config/opencode/scalemax.key}"
      },
      "models": {
        "fable-5": { "name": "Fable 5", "limit": { "context": 1050000, "output": 4096 } },
        "claude-haiku-4-5-20251001": { "name": "Claude Haiku 4.5", "limit": { "context": 200000, "output": 4096 } },
        "claude-haiku-5-5": { "name": "Claude Haiku 5.5", "limit": { "context": 1000000, "output": 128000 } },
        "claude-opus-4-6": { "name": "Claude Opus 4.6", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-4-7": { "name": "Claude Opus 4.7", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-4-8": { "name": "Claude Opus 4.8", "limit": { "context": 200000, "output": 4096 } },
        "claude-opus-5": { "name": "Claude Opus 5", "limit": { "context": 1000000, "output": 128000 } },
        "claude-opus-5-5": { "name": "Claude Opus 5.5", "limit": { "context": 1000000, "output": 128000 } },
        "claude-sonnet-5": { "name": "Claude Sonnet 5", "limit": { "context": 200000, "output": 4096 } },
        "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5", "limit": { "context": 1000000, "output": 128000 } }
      }
    }
  }
}
```

Claude Opus 5 advertises its native `128000`-token output limit. The older entries keep a conservative `4096`-token client cap. Lower the Opus 5 value if you want a smaller per-response budget. This is Claude through OpenCode's OpenAI-compatible adapter, not Claude Code's native Anthropic Messages setup.

**macOS / Linux**

```bash
opencode run --pure \
  --model scalemax/claude-haiku-4-5-20251001 \
  --format json \
  "K"
```

**Windows PowerShell**

```powershell
opencode run --pure `
  --model scalemax/claude-haiku-4-5-20251001 `
  --format json `
  "K"
```

## Key and model boundaries

> Use only models returned for the authenticated key. Never paste the key into committed JSON. The `scalemax/` prefix selects OpenCode's provider; ScaleMax receives the exact ID after the slash.

See [OpenCode's custom-provider reference](https://opencode.ai/docs/providers#custom-provider).
