Skip to content

About

GitHub Copilot's Auto model for opencode 1 and 2, routed like VS Code and Copilot CLI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

opencode-copilot-auto

CI Release npm License: MIT

GitHub Copilot's Auto model for opencode, working the way it does in VS Code and Copilot CLI: each conversation is routed through Copilot's POST /auto router, on the tier you pick, and billed through an Auto session (with the Auto discount).

One package serves both opencode lines: opencode 1 (≥ 1.18.29, plugin config key) and opencode 2 (plugins config key).

Based on m0wer/opencode-github-copilot-auto-model.

Models

The plugin adds three models to the github-copilot provider, one per tier of VS Code's Auto picker and Copilot CLI's /model:

Model Tier Routes for
github-copilot/auto balance cost, quality and latency (default)
github-copilot/auto-efficiency efficiency the most cost-efficient capable model
github-copilot/auto-intelligence intelligence the highest-quality response

Switching to another of the three mid-conversation switches the tier, as in VS Code. The tier only steers the router; the chosen model runs with its normal settings.

Install

opencode 2

~/.config/opencode/opencode.json(c):

{
  "plugins": ["@klconsultancy/opencode-copilot-auto"]
}

opencode 1 (≥ 1.18.29)

{
  "plugin": ["@klconsultancy/opencode-copilot-auto"]
}

Sign in to GitHub Copilot in opencode as usual; the plugin uses that connection.

Updating

opencode installs a plugin package once and keeps using the cached copy: it does not look for newer versions, not even for an unversioned name. Pin the version and bump it to update:

{ "plugin": ["@klconsultancy/opencode-copilot-auto@1.0.1"] }

opencode installs a new version on the next start. Start the TUI for that: a short-lived command such as opencode run or opencode models can exit before the install finishes, and then the plugin is missing for that run.

From a local checkout (bun install && bun run build), use the dist directory for opencode 2 (it only accepts a directory) and dist/index.js for opencode 1.

Options

// opencode 2
{ "plugins": [{ "package": "@klconsultancy/opencode-copilot-auto", "options": { "tier": "balance" } }] }

// opencode 1
{ "plugin": [["@klconsultancy/opencode-copilot-auto", { "tier": "balance" }]] }
Option Default Description
tier balance Tier of github-copilot/auto, like Copilot CLI's startup default: efficiency, balance or intelligence. The other two tiers get their own model. fast is not a picker tier (VS Code keeps it for inline chat, Copilot CLI dropped it) and falls back to balance.
preferredModels — Ordered model ids to anchor the autos on (see Anchor), e.g. ["gpt-6-luna"].

How it works

This follows VS Code's Copilot Auto (extensions/copilot/src/platform/endpoint in microsoft/vscode: automodeService.ts, autoV2Fetcher.ts, autoModeTiers.ts).

POST https://api.githubcopilot.com/auto
{ "prompt": "<your message>", "tier": "balance", "has_image": true? }
→ { "selected_model": { "id": "gpt-6-luna" }, "session_token": "…", "expires_at": …, "discounted_costs": { "gpt-6-luna": 0.1 } }
  • Routing once per conversation. The first prompt is sent to /auto, which picks a model and mints a 24-hour session token. The conversation stays on that model, so its prompt cache stays warm; every request carries Copilot-Session-Token, which bills it as Auto (10% discount on paid plans).
  • Across reloads. opencode reloads plugins when the config changes and recycles idle instances. The route survives that: it is kept, with its session token, in routes.json next to the plugin log (owner-only), until the token expires. A restored route the auto can no longer send (another anchor or catalog) is routed again.
  • Routing again happens, as in VS Code, on the next turn after compaction, when the token is within 5 minutes of expiring, when a turn attaches an image the model cannot read, and when you switch tier.
  • When /auto fails the conversation keeps its last route while that can still serve the turn; otherwise it uses the anchor model without an Auto session, and tries again on your next message.
  • Only what you typed goes to /auto, not file contents or other parts opencode adds.
  • No VS Code editor or integration headers are sent: the plugin does not pretend to be VS Code.

Anchor

opencode builds a model's requests with one SDK for one endpoint, so each auto is a clone of a real Copilot model, its anchor. The plugin swaps the routed model into each request, which works for every model on the same endpoint and wire API as the anchor (Copilot's Responses API for GPT-5+). By default the anchor is a GPT model on the Responses API, which is what /auto picks.

VS Code can send any pick through that model's own endpoint; this plugin cannot. If /auto picks a model the anchor cannot carry (for example a Claude model), the conversation runs on the anchor without an Auto session, and the log says so. The anchor is also the fallback model, so a cheap one keeps fallbacks cheap: "preferredModels": ["gpt-6-luna"].

Differences from VS Code and Copilot CLI

  • No tier suggestion (Copilot CLI 1.0.89) and no per-response model label: the plugin logs the route, and opencode 1 shows a toast when the model changes.
  • A pick outside the anchor's endpoint falls back to the anchor (see above); VS Code falls back to Copilot's utility model only when routing itself fails.

Logging

Routing decisions go to ~/.local/state/opencode-copilot-auto/plugin.log (%LOCALAPPDATA%\opencode-copilot-auto\plugin.log on Windows):

auto decision: selected_model=gpt-6-luna, tier=balance, prompt_chars=41, …
auto routed -> gpt-6-luna
request model gpt-5.4 -> gpt-6-luna

Development

CI and the devcontainer use bun 1.4.3.

Devcontainer

.devcontainer/ gives a container with bun and both opencode lines side by side, isolated from any opencode you use day to day:

Command Runs Loads the plugin from
oc1 opencode 1.19.2 dist/index.js
oc2 opencode 2.0.30 dist/ (opencode 2 only loads a directory)
plugin-log 1 / plugin-log 2 follows that version's plugin log

Each keeps its own config, login and logs under ~/.oc/1 or ~/.oc/2, on a volume that survives rebuilds. Sign in to Copilot once per version (oc1 auth login, oc2 auth login github-copilot); the device login prints a URL to open on the host. Plugin options go in ~/.oc/<1|2>/config/opencode/opencode.json. Run bun run dev to rebuild dist/ on every change.

Commands

bun install
bun run typecheck
bun run build       # dist/index.js, no runtime dependencies
bun test            # opencode 1 and 2 adapters, against stand-in plugin contexts

src/core.ts holds the routing; src/v1.ts (server) and src/v2.ts (setup) adapt it to each opencode plugin API, and src/index.ts exports both.

Releases

Releases run from GitHub Actions with release-please. Commit messages follow Conventional Commits: fix: makes a patch, feat: a minor, and feat!: or a BREAKING CHANGE: footer a major release. Each push to main updates a release PR with the next version and CHANGELOG.md; merging it tags the release, creates the GitHub release and stages the version on npm through trusted publishing (no token). A maintainer then approves it with 2FA under Staged Packages on npmjs.com, or with npm stage approve <stage-id>, before it goes live.

License

MIT. Copyright (c) 2026 m0wer, (c) 2026 Kristof Lemmens (KL Consultancy).

About

GitHub Copilot's Auto model for opencode 1 and 2, routed like VS Code and Copilot CLI

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages