Skip to content

Instantly share code, notes, and snippets.

@ben-vargas
Created February 26, 2026 08:37
Show Gist options
  • Select an option

  • Save ben-vargas/18f234d398fc6789d7ccdc2bb2dc6e8e to your computer and use it in GitHub Desktop.

Select an option

Save ben-vargas/18f234d398fc6789d7ccdc2bb2dc6e8e to your computer and use it in GitHub Desktop.

Overriding Context Size for Opus 4.6 on GH Copilot OpenCode

Pi Harness Approach (current)

In ~/.pi/agent/models.json, models are defined with explicit contextWindow and maxTokens fields, plus a modelOverrides block for the github-copilot provider:

"modelOverrides": {
  "claude-opus-4.6": {
    "contextWindow": 192000,
    "cost": {
      "input": 5,
      "output": 25,
      "cacheRead": 0.5,
      "cacheWrite": 6.25
    }
  }
}

OpenCode Equivalent

In OpenCode's config (opencode.json or ~/.config/opencode/opencode.json), the providermodels configuration supports the same kind of override. The relevant schema fields are:

limit: {
  context: number,   // ← context window size
  input: number,     // optional
  output: number
}

For Opus 4.6 via GitHub Copilot, add this to opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "github-copilot": {
      "models": {
        "claude-opus-4.6": {
          "limit": {
            "context": 192000,
            "output": 64000
          },
          "cost": {
            "input": 5,
            "output": 25,
            "cache_read": 0.5,
            "cache_write": 6.25
          }
        }
      }
    }
  }
}

Why This Works (code proof)

In packages/opencode/src/provider/provider.ts, when config-defined models are processed inside the state() function, existing models from models.dev are merged with config overrides:

limit: {
  context: model.limit?.context ?? existingModel?.limit?.context ?? 0,
  output: model.limit?.output ?? existingModel?.limit?.output ?? 0,
},

The config value for limit.context takes precedence over whatever models.dev reports. The Config.Provider schema uses ModelsDev.Model.partial(), meaning every field is optional — only the fields you want to override need to be specified.

Other Per-Model Overrides Available

Besides limit and cost, you can also override:

  • options — model-specific options like thinking.budgetTokens
  • variants — custom variant configurations
  • reasoning — whether the model supports reasoning
  • headers — custom headers per model
  • attachment, temperature, tool_call — capability flags

Reference

  • OpenCode docs: https://opencode.ai/docs/models/
  • Config schema: packages/opencode/src/config/config.ts
  • Provider/model resolution: packages/opencode/src/provider/provider.ts
  • Models.dev schema: packages/opencode/src/provider/models.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment