Quick Start • Why? • Features • CLI Usage • Architecture • Installation • Contributing
ocs — A model selector for OpenCode's global default and agent models, with a Bubbletea TUI. It is not a generic configuration editor. (The repo/module is
opencode-model-selector; the binary isocs.)
┌─────────────────────────────────────────────────────────────┐
│ ocs │
├─────────────────────────────────────────────────────────────┤
│ │
│ opencode models ──► Parse ──► Model Selection │
│ (fuzzy filter) │
│ │ │
│ temporary loopback `opencode serve` ── GET /agent │
│ │ │
│ ▼ │
│ Runtime Agent Catalog │
│ Primary / Subagent / All │
│ │ │
│ ▼ │
│ Save Model Override │
│ (backup → JSON write) │
│ │
└─────────────────────────────────────────────────────────────┘
Manually editing opencode.json to assign models to agents is error-prone. You don't know which models are available without running opencode models separately, and one wrong edit can corrupt the JSON or leak API keys.
| Manual JSON Editing | ocs | |
|---|---|---|
| See available models | ❌ Run opencode models separately |
✅ Listed in TUI with fuzzy filter |
| Model validation | ❌ No validation | ✅ Strict validation against opencode models |
| Safe editing | ❌ Risk of JSON corruption | ✅ Atomic writes + timestamped backups |
| API key safety | ✅ Never logged, 0o600 perms | |
| Cross-platform | ❌ Manual path resolution | ✅ Windows, macOS, Linux |
| Focused changes | ✅ Writes only model assignments |
# Install
go install github.com/lleontor705/opencode-model-selector/cmd/ocs@latest
# The installed binary is named `ocs`.
# Run
ocs # interactive TUI
ocs --list-models # list available models
ocs --list-agents # list the agent catalogPrerequisites: OpenCode CLI on your $PATH for model discovery and the full runtime agent catalog; Go 1.26+ when installing from source. If runtime discovery is unavailable, agent listing falls back to the static configuration catalog with a degraded warning.
For detailed installation instructions, see INSTALLATION.md.
- Model-Only Editing — changes only the global
modelor anagent.<name>.modelassignment - Model Detection — automatically discovers all available models from
opencode models - Runtime Agent Catalog — starts a short-lived
opencode servebound to loopback and readsGET /agent, including native, custom, and plugin-provided runtime agents while excluding hidden native agents - Role Sections — presents agents as Primary, Subagent, or All
- Degraded Fallback — if runtime discovery fails (including when the OpenCode binary is missing), uses static JSON, global agent Markdown, and project agent Markdown sources and displays a degraded warning
- Interactive TUI — Bubbletea-based terminal UI with fuzzy-filter model selection
- JSONC Support — loads
opencode.jsonandopencode.jsonc(comments and trailing commas allowed on load) - Backup & Restore — automatic JSON backups before every write (configurable retention)
- Cross-Platform — single Go binary for Linux, macOS, and Windows
- CLI Flags — non-interactive modes for scripting:
--list-models,--list-agents
Configuration writes:
ocswrites only the top-levelmodeloragent.<name>.modelto JSON/JSONC. Agent Markdown files are discovery inputs and remain immutable. JSONC comments are supported on load but are not preserved on save because the file is rewritten as standard JSON.
Startup: runtime discovery starts a temporary local OpenCode server, so startup typically takes a few seconds; observed startup varies (~2-5s). The server accepts only a validated loopback address and is stopped after discovery. On Windows, descendant cleanup is best effort using the current
taskkill /T /Fimplementation; this is not a strict child-containment guarantee.
# Interactive TUI (default)
ocs
# Override config path (opencode.json or opencode.jsonc)
ocs --config /path/to/opencode.json
# List available models grouped by provider
ocs --list-models
# List the runtime agent catalog
ocs --list-agents
# Control backup retention (0 to disable)
ocs --backup-count 10| Flag | Default | Description |
|---|---|---|
--config |
auto-detected | Override config file path |
--list-models |
false |
List available models grouped by provider |
--list-agents |
false |
List the agent catalog with name, mode, model, and status columns |
--backup-count |
5 |
Number of backups to retain (0 to disable) |
| Document | Description |
|---|---|
| Installation | Multi-platform installation guide |
| Contributing | Issue-first workflow, conventions, labels |
| Changelog | Release history |
| License | MIT License |
main.go CLI entry point (flag parsing + dispatch)
internal/
agentcatalog/ Runtime catalog classification and degraded static fallback
config/ Config/model loading, layered resolution, backup, and writes
opencode/ Model retrieval and temporary loopback runtime-agent probe
tui/ Bubbletea terminal UI (agent catalog, model selection, save)
test/ Integration tests and test fixtures
opencode modelsoutput is grouped by provider for model selection.- A short-lived loopback
opencode serveprocess supplies the authoritative catalog throughGET /agent. - Native, custom, and plugin runtime agents are classified into Primary, Subagent, and All; hidden native agents are excluded.
- If that probe fails, static JSON, global Markdown, and project Markdown identities are used with a degraded warning. Effective model precedence remains JSON, then project Markdown, then global Markdown.
- Model selection provides fuzzy filtering across all providers.
- Save confirmation creates a backup, then writes only the global
modelor selectedagent.<name>.modeloverride to JSON/JSONC. Markdown files are never modified.
See CONTRIBUTING.md for the full contribution workflow, code style, and testing standards.
MIT