[FEATURE]: Add a "Set as default" action to /models to persist the current model
Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before. (searched: "set default model", "persist model", "save selected model", "remember model selection"; the closest matches, #11209 and #28110, are related but different — see Additional context)
Summary
The /models selection is session-scoped by design — the models guide states "The selection applies to the current session and does not change your configuration" and "Switching a session's model does not rewrite the config file". So when the configured default is model A and I switch to model B in the TUI, there is no first-class way to make B the default for future sessions — the only option is to hand-edit opencode.json(c).
Describe the enhancement
Add a quick, discoverable way to persist the current model selection as the default, for example:
- A "Set as default" action in the
/modelsdialog, and/or - A command-palette command (e.g.
model.set_default) that can be keybound, writing the selectedprovider/modelto the user's globalopencode.json(global rather than project-level, so personal model preferences don't get committed to shared repos)
Current behavior
- Set
"model": "provider/a"in the globalopencode.json - Start the TUI, press
/models, selectprovider/b - Work, then quit OpenCode
- Start OpenCode again — new sessions fall back to
provider/aagain (occasionally a session instead resumes the last-used model, see Additional context), and there is no built-in shortcut to makeprovider/bthe default
Expected behavior
A supported way to persist the current model as the default without manually editing the config file.
Environment
- opencode version: 2.0.7 (channel: latest)
- OS: Windows 11 Home (build 26200)
- Terminal: mintty (xterm-256color, truecolor)
- Shell: Git Bash (
usr/bin/bash.exe) - Active plugins: none configured
Additional context
- This is an explicit, opt-in "write it to config" action, not automatic remembering. #28110 (per-agent model remembering in the desktop app) and #11209 (per-agent defaults in
opencode.json) both aim to change which model is picked automatically; this request is about letting the user commit their current selection as the default at a moment of their choosing. - Observed locally: some new sessions start with the last-used model (different from the configured default), which suggests the TUI keeps internal per-agent model state (also referenced in #28110). Explicit "Set as default" semantics would make the precedence between the config default and the remembered selection predictable.
I'll take this.
Backing this with the exact precedence chain from the TUI source — the "some new sessions start with the last-used model" observation in the description has a concrete cause.
packages/tui/src/context/local.tsx resolves the effective model in this order:
// currentModel() — :236-245
getFirstValidModel(
() => a && modelStore.model[a.name], // in-memory, per-agent, never persisted
() => a && a.model, // agent's configured model
fallbackModel, // ↓
)
// fallbackModel() — :197-234
if (args.model) ... // :198 --model CLI flag
if (sync.data.config.model) ... // :208 root "model" from opencode.json
for (const item of modelStore.recent) // :218 most-recently-used list
sync.data.provider_default[provider.id] // :226 provider-wide default
Two things make the current behavior unpredictable:
-
config.modeloutranks the last-used model.model.json'srecent[0]is the most recently selected model —recentModels()prepends on every/modelsselection (local.tsx:35-48, written fromdialog-model.tsx:143). But theconfig.modelbranch at:208returns first, sorecent[0]is never reached while a rootmodelis set. -
The per-agent slots are never persisted.
save()atlocal.tsx:169-180writes onlyrecent,favorite, andvariant— themodelStore.modelrecord is dropped. Confirmed on a real install:~/.local/state/opencode/model.jsonhas nomodelkey.
Together: set root model to A, pick B via /models, cycle agents with Tab — and the model resolves to A whenever the current agent has no in-memory slot. Removing the root model makes recent[0] win, which is what people expect, but it's an emergent side effect rather than a supported contract.
An explicit "Set as default" would make this precedence intentional rather than emergent. Prior art that was auto-closed as stale before anyone looked: #21351, #23369, #18359, #28110.
I'm the reporter. I dug through the source while preparing an implementation, and wanted to leave notes here in case they help whoever picks this up (I saw @snhsish claimed it — happy to hand these over, or to submit the PR myself if preferred).
The server side already has most of the plumbing, so this is a fairly contained change:
- Schema —
Config.Patch(packages/schema/src/config.ts) currently only acceptsshell. Adding an optionalmodel: ConfigModel.Selection | nullis straightforward;ConfigModel.Selectionalready accepts the shortprovider/model[#variant]string form used in config files. - Core —
Config.update(packages/core/src/config.ts) already patches the highest-precedence global config document, preserves JSONC comments viajsonc-parser'smodify/applyEdits, and triggers a config reload afterwards. Extending it to also writemodel(encoding the decoded selection back to the short string;nulldeletes the key) is small and self-contained. This matches the "global rather than project-level" requirement from the original report. - Client — regenerate the generated clients; the endpoint (
PATCH /api/experimental/config) is already exposed. - TUI —
dialog-model.tsxalready has the exact pattern to copy: theFavoriteaction (model.dialog.favorite,ctrl+f). ASet as defaultaction (model.dialog.default, e.g.ctrl+s) next to it would call the endpoint with the highlighted model and show a success toast. One caveat:DialogSelectonly renders footer actions that have a bound key, so the new command needs a default keybind. - Docs/tests — a row in
cli/keybinds.mdx, a sentence inmodels.mdx, and a server test alongside the existing "updates the global shell without replacing unrelated JSONC" case.
One design detail worth deciding: whether the action should also offer "clear default" (the endpoint can already express it by patching model: null).
Thanks for the detailed request, @BingWuJ!
To restate it: you'd like an explicit, opt-in way to save the model you've picked in /models as your default. That could be a "Set as default" action in the dialog and/or a command you can bind to a key. It would write the provider/model to your global opencode.json, so you don't have to edit the file by hand.
In v2, switching models in /models only affects the current session. The TUI also remembers recent models, favourites and variants in a separate preferences file, but nothing writes the model key back to your config today. That is why the configured default comes back. Maintainers will consider this.
Related issues (not the same request, as you noted):
- #28110: automatic per-agent model memory in the desktop app
- #11209: per-agent default models in
opencode.json
A plugin can't do this cleanly yet. A TUI plugin can register a command and read the current model, but there is no plugin or client API for updating the model setting in your config.
yes please