Skip to content

TUI plugins cannot read the currently selected model/agent (only the last-sent server session value) #50315

Closed as not planned

Description

@HaydarDK2024

Problem

A TUI plugin cannot display the model/agent currently selected in the prompt before the next message is sent.

  • TuiPluginApi.state exposes session, part, lsp, mcp, provider, config, path, vcs — no model/agent (packages/plugin/src/tui.ts, TuiState).
  • state.session.get(id).model is the server session value: it is updated only when a prompt is sent (the model is sent with session.prompt, and session.update is only used for title/archive).
  • The selected model/agent lives in the private Solid Local store in packages/tui/src/context/local.tsx. cycle() / set() only write that store; save() persists recent / favorite / variant to model.json but not the active model map.

Result: a status-line plugin that reads session.model (the only model value reachable from the plugin API) shows a stale value — it does not change on f2/tab model cycling, only after the next prompt is sent. The built-in prompt line does update live.

Reproduced on 1.18.31: cycling with f2 changes the built-in prompt line (· <model> <provider> · <variant>) but state.session.get(id).model stays on the previous value, and ~/.local/state/opencode/model.json never contains the active selection.

Ask

Expose the effective (pending) model / agent / variant through TuiState (or provide a change event on cycle/set), so TUI plugins can render an accurate status line without duplicating the built-in one inaccurately.

If a change event is preferred over a getter, something like tui.model.changed / tui.agent.changed would be enough.

Activity

  1. holny commented on Sep 23, 2026

    @holny
    Contributor

    I'll take this. The fix is to extend TuiPluginApi.state (packages/plugin/src/tui.ts) so a status-line plugin can read the live selected model/agent that the prompt input actually has on screen. The current gap is that state.session.get(id).model only mirrors the server-side value (set on the next session.prompt), and the in-memory selection lives in the private Solid store at packages/tui/src/context/local.tsx. The save() side already persists recent / favorite / variant to model.json — adding the active selection to that same payload keeps it consistent.

    Plan: thread the active selection through the Solid Local store, surface it as a reactive read on the plugin state, and persist it alongside the recent/favorite set so refreshes can rebuild it. Cover with a TUI test that flips the model via the prompt and asserts the plugin sees the new value before the next prompt is sent.

    Fixes #50315

  2. added a commit that references this issue on Sep 27, 2026
    988fbd8
  3. added a commit that references this issue on Oct 21, 2026
    77c0dab
  4. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up! This was reproduced on 1.18.31, which is OpenCode v1. v1 only gets critical fixes (data loss, security problems, crashes with no workaround), so a plugin API addition like this is unlikely to land there.

    In v2 (@opencode/cli, 2.x), TUI plugins can already read the model selected in the prompt before anything is sent: ctx.ui.model.current() returns { providerID, modelID, variant } and updates live when read inside a Solid computation. There's also ctx.ui.model.variant.list() and ctx.ui.model.variant.set(...). A status-line plugin built on that should follow model and variant changes as they happen. Reading the selected agent isn't covered in the same way yet.

    Please try upgrading to v2. If you think this is critical, or you still can't build an accurate status line on v2 (for example because you need the selected agent), reply here and say what's missing.

  5. opencodejr commented on Oct 29, 2026

    @opencodejr
    Contributor

    We haven't heard back, so I'm closing this as not planned. The report is about v1 (1.18.31), and v1 only gets critical fixes; new plugin API like this won't be added there.

    On v2 (@opencode/cli), TUI plugins can read the model selected in the prompt with ctx.ui.model.current(), which also gives the variant and updates live when cycling. If you upgrade and still can't build an accurate status line, for example because you need the selected agent, please open a new issue for v2 that says what's missing. Thanks again for the detailed report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions