feat: /model support for LM Studio and Ollama local model switching

Resolved 💬 2 comments Opened Apr 9, 2026 by beantownbytes Closed May 16, 2026

## Problem

When running Codex with --oss (LM Studio or Ollama provider), the /model command only shows the static cloud model
catalog from models.json, which contains no local models. This makes /model useless for OSS users who need to
switch between locally loaded models.

Additional pain points with the current --oss experience:

  1. Auto-download on startup: ensure_oss_ready downloads the default openai/gpt-oss-20b model even when the

user already has models loaded, forcing a 12GB download they didn't ask for

  1. No model persistence: Launching with --oss always defaults to openai/gpt-oss-20b regardless of what the

user previously selected -- if that model doesn't exist on the server, the first prompt fails with a stream disconnect
error

  1. No context window management: Local models don't report context window size via API, and Codex defaults unknown

models to 272K tokens, which causes compaction to never trigger and eventually hits context overflow errors from the
local server

## Proposed Solution

### Dynamic model listing in /model
When the active provider is lmstudio or ollama, /model fetches available models from the running local server
(LM Studio's /models endpoint or Ollama's /api/tags) and presents them in a searchable picker.

### Per-model context window configuration
On first selection of a local model, a context window picker appears (4K, 8K, 16K, 32K, 64K, 128K, 256K). The
selection is persisted per-model in config.toml:

``toml
[model_context_windows]
"qwen3.5-122b-a10b" = 32768
"llama-3.2-3b" = 8192
``

Subsequent selections of the same model switch directly without re-prompting. Tab reopens the picker to change a saved
value.

Startup improvements

  • Remove auto-download/pull from ensure_oss_ready -- require models to be pre-installed
  • Auto-select the first available model when the default isn't found on the server
  • Persist and restore the last selected model across sessions via config.toml

Reference Implementation

A working implementation is available here.
Changes:

  • tui/src/oss_model_fetch.rs -- thin async HTTP helpers for model listing
  • config_toml.rs, config/edit.rs -- model_context_windows HashMap with ConfigEditsBuilder persistence
  • models-manager/model_info.rs -- per-model context window resolution (per-model > global > catalog default)
  • chatwidget.rs -- OSS model picker, context window picker, chained popup flow
  • list_selection_view.rs -- secondary_action field on SelectionItem (Tab key)
  • lmstudio/lib.rs, ollama/lib.rs -- return resolved model from ensure_oss_ready, no auto-download
  • All 1503 codex-tui tests pass, clippy clean

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗