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

# OpenCode

> Connect OpenCode's terminal TUI AI assistant to ClearMaas via JSON config with 75+ model providers.

[OpenCode](https://open-code.ai) is a terminal-based AI coding assistant that supports 75+ LLM providers through the AI SDK. Connect it to ClearMaas by configuring a custom provider in your JSON config file.

## Prerequisites

* OpenCode installed (`npm install -g opencode` or via [installer](https://open-code.ai))
* A ClearMaas API key starting with `sk-`

## Config file locations

OpenCode merges configuration from multiple sources (later overrides earlier):

1. Remote config (`.well-known/opencode`) �?organizational defaults
2. Global config (`~/.config/opencode/opencode.json`) �?user preferences
3. `OPENCODE_CONFIG` env var �?custom overrides
4. Project config (`opencode.json` in project root) �?project-specific
5. `OPENCODE_CONFIG_CONTENT` env var �?runtime overrides

## Setup via global config

Add to `~/.config/opencode/opencode.json`:

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "provider": {
    "anthropic": {
      "options": {
        "apiKey": "sk-...",
        "baseURL": "https://api.clearmaas.com/v1"
      }
    }
  }
}
```

## Setup via environment variable

For temporary or CI usage, use `OPENCODE_CONFIG_CONTENT`:

```bash theme={null}
export OPENAI_API_KEY="sk-..."
export OPENCODE_CONFIG_CONTENT='{
  "model": "openai/gpt-4o",
  "provider": {
    "openai": {
      "options": {
        "baseURL": "https://api.clearmaas.com/v1"
      }
    }
  }
}'
opencode "Explain this code"
```

## Using environment variables in config

Reference API keys via env vars to avoid hardcoding:

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-4o-mini",
  "provider": {
    "openai": {
      "options": {
        "apiKey": "{env:OPENAI_API_KEY}",
        "baseURL": "https://api.clearmaas.com/v1"
      }
    }
  }
}
```

```bash theme={null}
export OPENAI_API_KEY="sk-..."
opencode
```

## Choosing models

Set the default model in config:

```json theme={null}
{
  "model": "anthropic/claude-sonnet-4-5"
}
```

Override with the `/models` command in the TUI:

```bash theme={null}
/model openai/gpt-4o-mini
```

## Using a separate small model

OpenCode can use a cheaper model for lightweight tasks (title generation, etc.):

```json theme={null}
{
  "model": "anthropic/claude-opus-4-5",
  "small_model": "anthropic/claude-haiku-4-5"
}
```

## Verifying the setup

```bash theme={null}
opencode
# In the TUI, type: /models
# You should see ClearMaas models listed
# Or type: /connect and verify the endpoint
```

Check your ClearMaas dashboard to confirm requests are being routed.

## Config example with all options

```json theme={null}
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-5",
  "small_model": "anthropic/claude-haiku-4-5",
  "autoupdate": true,
  "provider": {
    "anthropic": {
      "options": {
        "apiKey": "{env:OPENAI_API_KEY}",
        "baseURL": "https://api.clearmaas.com/v1",
        "timeout": 300000,
        "setCacheKey": true
      }
    }
  }
}
```

Available provider options:

* `timeout` �?Request timeout in milliseconds (default: 300000)
* `setCacheKey` �?Always set a cache key for designated provider
* `baseURL` �?Override the default API endpoint

## See also

* [API key setup](/getting-started/get-api-key)
* [Model reference](/getting-started/models)
* [OpenCode docs](https://open-code.ai/en/docs)
