[PR #13783] fix: --prompt submitting the first message before recent model has been loaded #14813

Open
opened 2026-02-16 18:19:34 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13783

State: open
Merged: No


What does this PR do?

Fixes #8551

Issue

Running opencode normally starts the session with the most recent model.
Running opencode with --prompt starts the session with a random(ish) fallback model. Im my case Gemini3.

This happens because the prompt arg is submitted as a message before the model is ready and has loaded the recent model.
The onMount already uses once to make it idempotent. Adding an additional check that the model is "ready" (has loaded recent models, etc.) ensures that the prompt is submitted with the most recent model like when opencode is opened normally.

How did you verify your code works?

Using the latest commit from the dev branch:

  1. Run opencode and pick a model. Send a "hello" message
  2. Run opencode --prompt hello. The model is different than the one selected in step 1
  3. Run bun dev and verify that the model from step 1 is selected
  4. Run bun dev --prompt hello The model is different than step 1 and the same as step 2

Using this fix branch:

  1. Run bun dev and verify that the model from step 1 is selected
  2. Run bun dev --prompt hello The model from step 1 should be selected
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13783 **State:** open **Merged:** No --- ### What does this PR do? Fixes #8551 #### Issue Running opencode normally starts the session with the most recent model. Running opencode with `--prompt` starts the session with a random(ish) fallback model. Im my case Gemini3. This happens because the prompt arg is submitted as a message before the model is ready and has loaded the recent model. The `onMount` already uses `once` to make it idempotent. Adding an additional check that the model is "ready" (has loaded recent models, etc.) ensures that the prompt is submitted with the most recent model like when opencode is opened normally. ### How did you verify your code works? Using the latest commit from the dev branch: 1. Run `opencode` and pick a model. Send a "hello" message 2. Run `opencode --prompt hello`. The model is different than the one selected in step 1 3. Run `bun dev` and verify that the model from step 1 is selected 4. Run `bun dev --prompt hello` The model is different than step 1 and the same as step 2 Using this fix branch: 1. Run `bun dev` and verify that the model from step 1 is selected 2. Run `bun dev --prompt hello` The model from step 1 should be selected
yindo added the pull-request label 2026-02-16 18:19:34 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14813