Skip to content

Comments

fix(cli): respect -m flag over agent model config#14503

Open
DerrickBarra wants to merge 5 commits intoanomalyco:devfrom
GambitGamesLLC:fix/cli-model-flag
Open

fix(cli): respect -m flag over agent model config#14503
DerrickBarra wants to merge 5 commits intoanomalyco:devfrom
GambitGamesLLC:fix/cli-model-flag

Conversation

@DerrickBarra
Copy link

@DerrickBarra DerrickBarra commented Feb 20, 2026

Issue for this PR

Closes #14502

Type of change

  • Bug fix

What does this PR do?

Problem: The CLI -m flag was being ignored when an agent has a model configured or when the provider is not yet in the synced cache. This caused the TUI to show 'No provider selected' or fall back to default models (e.g., 'big-pickle') instead of using the CLI-specified model.

Root Cause: currentModel() checked agent model before CLI args, and isModelValid() required the provider to be in sync.data.provider cache.

Fix: Check CLI args.model first without strict validation in both currentModel() and fallbackModel().

How did you verify your code works?

Built OpenCode from source and tested with: opencode -m openrouter/meta-llama/llama-3.1-8b-instruct

Before: TUI showed 'Build · big-pickle' with 'Free usage exceeded' error
After: TUI shows 'Build · llama-3.1-8b-instruct' and uses OpenRouter correctly.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The CLI -m flag was being ignored because:
1. Agent model took precedence over CLI flag
2. isModelValid() required provider to be in synced cache

This caused custom providers like openrouter/* to fail with
'No provider selected' or fallback to default models.

Fix by checking CLI -m flag first without strict validation:
- currentModel() now checks args.model before agent model
- fallbackModel() trusts CLI models even if not in cache

This allows users to specify any provider/model via CLI:
  opencode -m openrouter/meta-llama/llama-3.1-8b-instruct

Fixes #<issue-number>
@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Feb 20, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

DerrickBarra and others added 4 commits February 20, 2026 18:56
The CLI -m flag was being ignored because:
1. Agent model took precedence over CLI flag
2. isModelValid() required provider to be in synced cache

This fix:
1. Adds allowUncached parameter to isModelValid() for CLI models
2. Passes CLI -m flag through getFirstValidModel() chain with priority
3. Allows custom providers like openrouter/* to work even if not in cache

Fixes anomalyco#14502
getFirstValidModel() now destructures the model to return only
providerID and modelID, stripping the allowUncached flag.

This ensures the return type matches what the rest of the codebase
expects while still using allowUncached for validation.
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.

CLI -m flag ignored when agent has configured model or provider not in cache

1 participant