Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.
launch: populate Codex model picker with installed Ollama models (#18887)
Parth Sareen6eaad729530a
diff --git a/cmd/launch/codex.go b/cmd/launch/codex.goindex 21d2a67d0..e0ec0ff4a 100644--- a/cmd/launch/codex.go+++ b/cmd/launch/codex.go@@ -224,7 +224,7 @@ func ensureCodexConfig(modelName string, models []LaunchModel) error {}catalogPath := codexModelCatalogPathForConfig(configPath)- if err := writeCodexModelCatalog(catalogPath, codexCatalogModel(modelName, models)); err != nil {+ if err := writeCodexModelCatalog(catalogPath, codexCatalogModels(modelName, models)); err != nil {return err}@@ -673,11 +673,29 @@ func codexCatalogModel(modelName string, models []LaunchModel) LaunchModel {return fallbackLaunchModel(modelName)}-func writeCodexModelCatalog(catalogPath string, model LaunchModel) error {- entry := buildCodexModelEntry(model)+func codexCatalogModels(modelName string, models []LaunchModel) []LaunchModel {+ selected := codexCatalogModel(modelName, models)+ catalogModels := []LaunchModel{selected}+ seen := map[string]bool{launchModelRecommendationKey(selected.Name): true}+ for _, model := range models {+ key := launchModelRecommendationKey(model.Name)+ if key == "" || seen[key] {+ continue+ }+ seen[key] = true+ catalogModels = append(catalogModels, model.WithCloudLimits())+ }+ return catalogModels+}++func writeCodexModelCatalog(catalogPath string, models []LaunchModel) error {+ entries := make([]any, 0, len(models))+ for _, model := range models {+ entries = append(entries, buildCodexModelEntry(model))+ }catalog := map[string]any{- "models": []any{entry},+ "models": entries,}data, err := json.MarshalIndent(catalog, "", " ")diff --git a/cmd/launch/codex_test.go b/cmd/launch/codex_test.goindex 6155c84ec..0376daa24 100644--- a/cmd/launch/codex_test.go+++ b/cmd/launch/codex_test.go@@ -67,6 +67,59 @@ func TestCodexArgs(t *testing.T) {}}+func TestCodexCatalogContainsSwitchableModels(t *testing.T) {+ setTestHome(t, t.TempDir())+ t.Setenv("OLLAMA_CONTEXT_LENGTH", "65536")+ models := []LaunchModel{+ {Name: "qwen3:latest", ContextLength: 65536},+ {Name: "qwen3:latest"},+ {Name: "qwen3:4b", Capabilities: []modelpkg.Capability{modelpkg.CapabilityVision}},+ {Name: "gpt-oss:20b-cloud", ContextLength: 131072},+ {Name: ""},+ }+ if err := ensureCodexConfig("qwen3", models); err != nil {+ t.Fatal(err)+ }+ path, err := codexModelCatalogPath()+ if err != nil {+ t.Fatal(err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ var catalog struct {+ Models []map[string]any `json:"models"`+ }+ if err := json.Unmarshal(data, &catalog); err != nil {+ t.Fatal(err)+ }+ var names []string+ for _, entry := range catalog.Models {+ names = append(names, entry["slug"].(string))+ }+ if want := []string{"qwen3", "qwen3:4b", "gpt-oss:20b-cloud"}; !slices.Equal(names, want) {+ t.Fatalf("catalog names = %v, want %v", names, want)+ }+ if got := catalog.Models[1]["input_modalities"]; !slices.Equal(got.([]any), []any{"text", "image"}) {+ t.Fatalf("switched model lost vision metadata: %v", got)+ }+ if got := catalog.Models[2]["context_window"]; got != float64(131072) {+ t.Fatalf("cloud model lost context window: %v", got)+ }+ // Refreshing after a model is removed must remove it from /model too.+ if err := ensureCodexConfig("qwen3", models[:1]); err != nil {+ t.Fatal(err)+ }+ data, err = os.ReadFile(path)+ if err != nil {+ t.Fatal(err)+ }+ if err := json.Unmarshal(data, &catalog); err != nil || len(catalog.Models) != 1 {+ t.Fatalf("refreshed catalog = %s, err = %v", data, err)+ }+}+func TestCodexArgsRejectManagedProfile(t *testing.T) {c := &Codex{}for _, extra := range [][]string{diff --git a/cmd/launch/launch.go b/cmd/launch/launch.goindex 1c0f34748..65af0bc50 100644--- a/cmd/launch/launch.go+++ b/cmd/launch/launch.go@@ -1455,6 +1455,28 @@ func hasLocalModel(inventory []LaunchModel, name string) bool {func (c *launcherClient) resolveRunModels(ctx context.Context, integration string, models []string) []LaunchModel {recommendations := c.recommendations(ctx)+ if integration == "codex" {+ // Codex reads its /model choices from the generated catalog. Include+ // installed tool-capable models as well as the requested starting model.+ if inventory, err := c.modelInventory().Load(ctx); err == nil {+ cloudDisabled := false+ if slices.ContainsFunc(inventory, func(model LaunchModel) bool { return model.Remote || isCloudModelName(model.Name) }) {+ cloudDisabled, _ = cloudStatusDisabled(ctx, c.apiClient)+ }+ models = slices.Clone(models)+ for _, model := range inventory {+ if !model.ToolCapable || isDeprecatedLaunchModel(model.Name) || (cloudDisabled && (model.Remote || isCloudModelName(model.Name))) {+ continue+ }+ if slices.ContainsFunc(models, func(name string) bool {+ return launchModelRecommendationKey(name) == launchModelRecommendationKey(model.Name)+ }) {+ continue+ }+ models = append(models, model.Name)+ }+ }+ }resolved := c.modelInventory().Resolve(ctx, models)byName := make(map[string]*api.ModelRecommendationThinking, len(recommendations))for _, recommendation := range recommendations {diff --git a/cmd/launch/launch_test.go b/cmd/launch/launch_test.goindex 6f91a8882..65db6af58 100644--- a/cmd/launch/launch_test.go+++ b/cmd/launch/launch_test.go@@ -75,6 +75,47 @@ func TestResolveRunModelsCarriesRecommendationThinkingMetadata(t *testing.T) {}}+func TestResolveRunModelsCodexIncludesInstalledToolModels(t *testing.T) {+ for _, disabled := range []bool{false, true} {+ t.Run(fmt.Sprintf("cloud disabled=%t", disabled), func(t *testing.T) {+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ switch r.URL.Path {+ case "/api/tags":+ fmt.Fprint(w, `{"models":[{"name":"qwen3:latest","capabilities":["completion","tools"]},{"name":"qwen3:4b","capabilities":["completion","tools"]},{"name":"embedding:latest","capabilities":["embedding"]},{"name":"custom:cloud","remote_model":"custom","capabilities":["completion","tools"]}]}`)+ case "/api/experimental/model-recommendations":+ fmt.Fprint(w, `{"recommendations":[]}`)+ case "/api/status":+ fmt.Fprintf(w, `{"cloud":{"disabled":%t}}`, disabled)+ case "/api/show":+ fmt.Fprint(w, `{}`)+ default:+ http.NotFound(w, r)+ }+ }))+ defer server.Close()+ t.Setenv("OLLAMA_HOST", server.URL)+ client, err := newLauncherClient(defaultLaunchPolicy(false, false))+ if err != nil {+ t.Fatal(err)+ }+ models := client.resolveRunModels(t.Context(), "codex", []string{"qwen3"})+ want := []string{"qwen3:latest", "qwen3:4b"}+ if !disabled {+ want = append(want, "custom:cloud")+ }+ // The writer collapses the requested alias and installed canonical name.+ catalog := codexCatalogModels("qwen3", models)+ want[0] = "qwen3"+ if got := launchModelNames(catalog); !slices.Equal(got, want) {+ t.Fatalf("catalog = %v, want %v", got, want)+ }+ if got := launchModelNames(client.resolveRunModels(t.Context(), "test", []string{"qwen3"})); !slices.Equal(got, []string{"qwen3:latest"}) {+ t.Fatalf("other integration received extra models: %v", got)+ }+ })+ }+}+func TestResolveRunModelsUsesThinkingDiscovery(t *testing.T) {for _, tc := range []struct {name, show stringdiff --git a/docs/integrations/codex.mdx b/docs/integrations/codex.mdxindex ac20a3c30..425d2b404 100644--- a/docs/integrations/codex.mdx+++ b/docs/integrations/codex.mdx@@ -24,6 +24,11 @@ ollama launch codexWhen launched through `ollama launch codex`, Ollama refreshes the model catalogand uses a dedicated Codex profile for that session.+Type `/model` inside Codex to switch between your installed, tool-capable Ollama+models without restarting. The starting model remains selected, and each model+keeps its own context window, vision, and thinking settings. Pull additional+models with `ollama pull <model>` before launching to include them in the picker.+To configure without launching:```shell