---
title: Connect OpenCode
description: Connect OpenCode to Unity Gateway to route requests through governed Databricks models, MCP tools, and skills, with the Unity Gateway CLI or manual setup.
canonical_url: https://docs.databricks.com/aws/en/ai-gateway/coding-agent-opencode
---

# Connect OpenCode

Use OpenCode with models, MCP tools, and skills through Unity Gateway. The Unity Gateway CLI (`ug`) handles workspace sign-in and configuration, or you can configure the connection manually.

## Prerequisites

You need your Databricks workspace URL and access to the models, MCP services, and skills you want to use. For manual setup, install [OpenCode](https://opencode.ai/docs/) and have a Databricks personal access token.

For manual configuration, replace `<workspace-hostname>` with your Databricks workspace hostname and `<databricks-pat>` with your token. Use full model names available in your workspace, and merge configuration entries into existing files, keeping unrelated settings.

If your admin has already configured your device, follow your organization's setup instructions.

## Use the Unity Gateway CLI

[Install `ug`](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-quickstart.md), then run this command from your project directory:

```bash
ug opencode
```

Select your workspace and sign in when prompted. The command opens OpenCode with your gateway models configured. Start coding, or enter `/models` to choose another configured model.

## Configure models manually

Install [OpenCode](https://opencode.ai/docs/), then merge this configuration into `~/.config/opencode/opencode.json`:

```json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "databricks-anthropic/system.ai.claude-sonnet-5-5",
  "provider": {
    "databricks-anthropic": {
      "npm": "@ai-sdk/anthropic",
      "options": {
        "baseURL": "https://<workspace-hostname>/ai-gateway/anthropic/v1",
        "apiKey": "<databricks-pat>",
        "headers": {
          "Authorization": "Bearer <databricks-pat>"
        }
      },
      "models": {
        "system.ai.claude-sonnet-5-5": {
          "options": {
            "toolStreaming": false
          }
        }
      }
    }
  }
}
```

Replace the model name in both locations if you choose another Claude model. Keep `toolStreaming: false` for gateway compatibility. Start OpenCode with `opencode`.

For Gemini models, add a separate provider using `@ai-sdk/google`, base URL `https://<workspace-hostname>/ai-gateway/gemini/v1beta`, the same authentication fields, and your Gemini model names. See [OpenCode's provider documentation](https://opencode.ai/docs/providers/).

To cut per-token cost for routine tasks, select an open source model such as `system.ai.glm-5-3` as your model. See [Control spending](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-costs.md#open-models).

## Add MCP tools

`system.ai.dbsql`, `system.ai.sandbox`, and `system.ai.web_search` are in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md). To use them, an account admin must enable the **Enhanced Unity Gateway** preview from the account console **Previews** page. Unity Gateway itself is generally available. See [Manage account previews](https://docs.databricks.com/aws/en/admin/workspace-settings/manage-previews.md#account).

### Use the Unity Gateway CLI

Run:

```bash
ug mcp add --agents opencode
```

Select your services, then restart with `ug opencode`.

### Configure MCP services manually

Merge this entry into `~/.config/opencode/opencode.json`:

```json
{
  "mcp": {
    "dbsql": {
      "type": "remote",
      "url": "https://<workspace-hostname>/ai-gateway/mcp-services/system.ai.dbsql",
      "oauth": false,
      "headers": {
        "Authorization": "Bearer <databricks-pat>"
      }
    }
  }
}
```

For another service, change the server name and replace `system.ai.dbsql` with its three-part Unity Catalog name. Restart OpenCode and ask it to use a connected tool. See [OpenCode's MCP documentation](https://opencode.ai/docs/mcp-servers/).

`ug opencode` uses `~/.ucode/opencode-xdg/opencode/opencode.json`. Use that file for manual MCP entries when launching through `ug`.

## Add skills

### Use the Unity Gateway CLI

Download published skills:

```bash
ug skills add
```

Choose your skills, then restart OpenCode. It reads the downloads from `~/.agents/skills/` and loads relevant skills as you work.

### Configure skills manually

For files you already have, place each complete skill folder in `~/.agents/skills/` or your project's `.opencode/skills/`. See [OpenCode's skills documentation](https://opencode.ai/docs/skills/).

To access the published skill registry through MCP, add a second server using the MCP example above, name it `databricks-skill-registry`, and set `url` to `https://<workspace-hostname>/ai-gateway/skills/`. Keep the trailing slash, bearer header, and `oauth: false`. Ask the agent to use a skill by its full name.

Unity Gateway skills are in Beta. See [Govern skills](https://docs.databricks.com/aws/en/ai-gateway/govern-skills.md) for enablement and permissions.

## Troubleshooting

**A model request fails:** Check the gateway URL, token expiration, model name, and permissions.

**An MCP server is missing:** Restart the agent. If you configured it with `ug`, launch it with `ug opencode` so it uses the same settings. For manual setup, check `~/.config/opencode/opencode.json` and the bearer token.

**A downloaded skill is missing:** Check that its complete folder contains `SKILL.md` in a supported directory. Re-run `ug skills add` with the same options to refresh downloaded skills.

For workspace sign-in or `ug` setup problems, run `ug doctor`.

## Next steps

* [ug CLI reference](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-ug-cli.md)
* [Add tools and skills](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-mcp-skills.md)
* [Supported coding and work agents](https://docs.databricks.com/aws/en/ai-gateway/coding-agent-supported-agents.md)
