Skip to main content

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.

Before you begin

You need your Databricks workspace URL and access to the models, MCP services, and skills you want to use. For manual setup, install OpenCode 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, 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, then merge this configuration into ~/.config/opencode/opencode.json:

JSON
{
"$schema": "https://opencode.ai/config.json",
"model": "databricks-anthropic/system.ai.claude-sonnet-4-6",
"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-4-6": {
"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.

To cut per-token cost for routine tasks, select an open source model such as system.ai.glm-5-2 as your model. See Control spending.

Add MCP tools

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.

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.

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 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