Skip to content

feat(cli): honor --model alone without requiring --provider#854

Open
0xfandom wants to merge 1 commit intoGitlawb:mainfrom
0xfandom:feat/808-standalone-model-flag
Open

feat(cli): honor --model alone without requiring --provider#854
0xfandom wants to merge 1 commit intoGitlawb:mainfrom
0xfandom:feat/808-standalone-model-flag

Conversation

@0xfandom
Copy link
Copy Markdown
Contributor

Summary

  • --model <name> now works standalone (no --provider required), overriding the active session model process-scoped.
  • Routes the value to the env var matching the already-active provider (OPENAI_MODEL / GEMINI_MODEL / MISTRAL_MODEL / ANTHROPIC_MODEL) after saved-profile application and before the startup banner, so the banner, provider resolution, and outgoing request payload all agree.
  • Preserves the existing --provider <name> --model <name> path (handled by applyProviderFlagFromArgs).

Closes #808.

Why

Today Commander parses --model inside main.tsx, but the startup banner and provider-env-reading code run earlier. Saved-profile users running openclaude --model gpt-4o-mini saw their stale profile model in the banner, and callers reading the *_MODEL env var directly (e.g. StartupScreen.detectProvider) missed the override entirely.

The fix mirrors the existing --provider early-path in cli.tsx: hook into the bootstrap flow right before printStartupScreen() and propagate the flag value to the correct env var.

No writes to .openclaude-profile.json — override is process-scoped, as the issue asked.

Changes

  • src/utils/providerFlag.ts — export parseModelFlag, add applyModelFlagFromArgs that detects active provider from CLAUDE_CODE_USE_* and sets the matching *_MODEL.
  • src/entrypoints/cli.tsx — call applyModelFlagFromArgs after saved-profile env application and before the startup banner, gated on --model being present.
  • src/utils/providerFlag.test.ts — new tests covering parseModelFlag and applyModelFlagFromArgs across OpenAI / Gemini / Mistral / GitHub / Anthropic providers, saved-profile override, colon-bearing Ollama tags, and the --provider passthrough no-op.

Test plan

  • bun test src/utils/providerFlag.test.ts — 34 pass, 0 fail
  • bun test (full suite) — 1227 pass, 0 fail
  • Saved OpenAI profile + openclaude --model gpt-4o-mini → banner shows gpt-4o-mini, profile file unchanged
  • Saved Gemini profile + openclaude --model gemini-2.0-flash → banner shows gemini-2.0-flash
  • openclaude --provider openai --model gpt-4o → existing behavior preserved

gnanam1990
gnanam1990 previously approved these changes Apr 26, 2026
Copy link
Copy Markdown
Collaborator

@gnanam1990 gnanam1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Closes #808 cleanly — defers to applyProviderFlagFromArgs when both flags are set, and the 9-test matrix covers every provider branch plus the ollama colon-syntax case. LGTM 🚀

@0xfandom
Copy link
Copy Markdown
Contributor Author

@kevincodex1 Any update on this

gnanam1990
gnanam1990 previously approved these changes May 1, 2026
Copy link
Copy Markdown
Collaborator

@gnanam1990 gnanam1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approved at 1fc3ccc after the rebase onto current main.

Verified locally:

bun test src/utils/providerFlag.test.ts src/utils/providerAutoDetect.test.ts
→ 64 pass / 0 fail

The --model resolution still defers cleanly to applyProviderFlagFromArgs when both flags are present, and the matrix (9 provider branches + the ollama colon-syntax case) still passes after the rebase. No fingerprints / red flags introduced. LGTM 🚀

@0xfandom 0xfandom force-pushed the feat/808-standalone-model-flag branch 2 times, most recently from 09908ea to ddbbee9 Compare May 4, 2026 08:35
@0xfandom
Copy link
Copy Markdown
Contributor Author

0xfandom commented May 4, 2026

Rebased onto current main at ddbbee9 to clear the 7-commit drift from #849 / #972 / #983 / #979 / #980. No file overlap with any of those — only src/entrypoints/cli.tsx, src/utils/providerFlag.ts, src/utils/providerFlag.test.ts change here, none of which the new commits touch. Same diff as before (138 insertions, 1 deletion); bun run build + bun test src/utils/providerFlag.test.ts (49/49) green.

@gnanam1990 — re-approval ping if it still looks clean.

@0xfandom 0xfandom requested a review from gnanam1990 May 4, 2026 18:13
Closes Gitlawb#808. Today `openclaude --model <name>` is parsed by Commander
inside main.tsx but the startup banner and any provider-env-reading
code run first, so the override is invisible until request time and
saved-profile users see their stale model in the banner.

Add applyModelFlagFromArgs that runs after saved-profile env
application and before the banner. It routes the value to the env var
matching the already-active provider (OPENAI_MODEL / GEMINI_MODEL /
MISTRAL_MODEL / ANTHROPIC_MODEL) so the banner, resolution, and
request payload all agree. Skipped when --provider is also present;
that path is still handled by applyProviderFlagFromArgs.

No writes to .openclaude-profile.json — override is process-scoped.
@0xfandom 0xfandom force-pushed the feat/808-standalone-model-flag branch from ddbbee9 to b78d8bf Compare May 6, 2026 06:44
@0xfandom
Copy link
Copy Markdown
Contributor Author

0xfandom commented May 6, 2026

Rebased onto current main (post 0.9.2 release). 17-commit drift cleared with no conflicts — only src/entrypoints/cli.tsx + src/utils/providerFlag.{ts,test.ts} changed; nothing in those merged commits touches them.

bun test src/utils/providerFlag.test.ts src/utils/providerAutoDetect.test.ts
→ 75 pass / 0 fail
bun run build → green

No logic changes since the prior approval.

@0xfandom
Copy link
Copy Markdown
Contributor Author

0xfandom commented May 7, 2026

Any update on this @kevincodex1 @gnanam1990

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add --model <name> CLI flag for one-off model switching

2 participants