CoreCodeDocs

Connect

OpenCode

Last updated: October 28, 2026

OpenCode is an open-source coding agent for the terminal that works with any OpenAI-compatible provider. Add a CoreCode provider to its configuration and switch between Claude, GPT, Grok and Gemini in one OpenCode. The settings come from OpenCode's provider documentation.

The easier wayWith Magpie installed, choose a corecode/… model for OpenCode on Magpie's Agents page; you do not need the configuration below.

Install

npm install -g opencode-ai

Run opencode --version afterwards; a version number means it is installed.

Create a key

Create a key on the API Keys page in the auto group. OpenCode is not Claude Code, so the 仅限CC group rejects its requests; for Claude only, 「Claude 满血(可外接)」 also works.

Configure

Edit ~/.config/opencode/opencode.json, creating it if needed (or put it in a project directory to apply to that project only):

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "corecode": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "CoreCode",
      "options": {
        "baseURL": "https://corecode.live/v1",
        "apiKey": "{env:CORECODE_API_KEY}"
      },
      "models": {
        "claude-sonnet-5-5": { "name": "Claude Sonnet 5.5" },
        "claude-opus-5-5": { "name": "Claude Opus 5.5" },
        "gpt-6.1-sol": { "name": "GPT-6.1 Sol" },
        "grok-4.7": { "name": "Grok 4.7" },
        "gemini-3.8-flash-high": { "name": "Gemini 3.8 Flash" }
      }
    }
  }
}

The names under models must match the Pricing page; add or remove as you like. Then put the key in an environment variable:

export CORECODE_API_KEY=sk-your-key

To keep it, add the line to ~/.zshrc or ~/.bashrc; on Windows run setx CORECODE_API_KEY sk-your-key and open a new terminal.

Check that it works

opencode run -m corecode/claude-sonnet-5-5 "reply ok"

If it prints ok, you are connected. Type /models in OpenCode to see CoreCode's models and switch between them.

FAQ

CoreCode is missing from /models

Check that the JSON is valid and that the file is in ~/.config/opencode/ or the current project directory.

401 or 403

401 means the key was not read: check that the terminal running opencode has CORECODE_API_KEY. For 403, check the balance first, then that the key is not in 仅限CC.