Feature Request: Remember last used model/agent across sessions #7449

Open
opened 2026-02-16 18:07:12 -05:00 by yindo · 11 comments
Owner

Originally created by @nxxxsooo on GitHub (Jan 24, 2026).

Originally assigned to: @thdxr on GitHub.

Feature Request

Is your feature request related to a problem?
When starting OpenCode, it always uses the default model/agent from config, even if the user switched to a different model in the previous session. Users have to manually switch models every time they start a new session.

Describe the solution you'd like
OpenCode should remember the last used model/agent and restore it when starting a new session. This could be:

  1. A global preference stored in ~/.local/share/opencode/ (e.g., last_model.json)
  2. Or a config option like remember_last_model: true in opencode.json or oh-my-opencode.json

Describe alternatives you've considered
Currently users must manually edit config files to change the default model, which is inconvenient for those who frequently switch between models.

Additional context
This would greatly improve UX for users who:

  • Switch between local models (LMStudio) and cloud models
  • Use different models for different types of tasks
  • Want their workspace preferences to persist
Originally created by @nxxxsooo on GitHub (Jan 24, 2026). Originally assigned to: @thdxr on GitHub. ## Feature Request **Is your feature request related to a problem?** When starting OpenCode, it always uses the default model/agent from config, even if the user switched to a different model in the previous session. Users have to manually switch models every time they start a new session. **Describe the solution you'd like** OpenCode should remember the last used model/agent and restore it when starting a new session. This could be: 1. A global preference stored in `~/.local/share/opencode/` (e.g., `last_model.json`) 2. Or a config option like `remember_last_model: true` in opencode.json or oh-my-opencode.json **Describe alternatives you've considered** Currently users must manually edit config files to change the default model, which is inconvenient for those who frequently switch between models. **Additional context** This would greatly improve UX for users who: - Switch between local models (LMStudio) and cloud models - Use different models for different types of tasks - Want their workspace preferences to persist
Author
Owner

@github-actions[bot] commented on GitHub (Jan 24, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #4930: Retain current model and agent selection when switching sessions
  • #6338: Model select always prioritizes OpenCode Zen over last used?
  • #7948: TUI: User selected agent/model is overwritten by server defaults when creating a new session
  • #8349: Model selection is "lost" on continuation and Agent selection is "lost" on compaction
  • #6075: Remembering the last model used (closed - may have context on implementation challenges)

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 24, 2026): This issue might be a duplicate of existing issues. Please check: - #4930: Retain current model and agent selection when switching sessions - #6338: Model select always prioritizes OpenCode Zen over last used? - #7948: TUI: User selected agent/model is overwritten by server defaults when creating a new session - #8349: Model selection is "lost" on continuation and Agent selection is "lost" on compaction - #6075: Remembering the last model used (closed - may have context on implementation challenges) Feel free to ignore if none of these address your specific case.
Author
Owner

@IdrisGit commented on GitHub (Jan 24, 2026):

@thdxr I can look into this, if it's a valid request.

@IdrisGit commented on GitHub (Jan 24, 2026): @thdxr I can look into this, if it's a valid request.
Author
Owner

@nxxxsooo commented on GitHub (Jan 25, 2026):

@amio Both approaches would solve my problem:

  • Last used: Zero config, just works
  • Favorites: More control, useful if you switch between specific models often

Happy to go with whatever @thdxr thinks fits better with OpenCode's direction.

Also, the current "Recents" section feels a bit confusing - when scrolling through the model list, I sometimes think my model config is broken, only to realize it just moved to Recents. A dedicated favorites list with quick switching would be much clearer.

@IdrisGit Thanks for offering to look into this! 🙏

@nxxxsooo commented on GitHub (Jan 25, 2026): @amio Both approaches would solve my problem: - **Last used**: Zero config, just works - **Favorites**: More control, useful if you switch between specific models often Happy to go with whatever @thdxr thinks fits better with OpenCode's direction. Also, the current "Recents" section feels a bit confusing - when scrolling through the model list, I sometimes think my model config is broken, only to realize it just moved to Recents. A dedicated favorites list with quick switching would be much clearer. @IdrisGit Thanks for offering to look into this! 🙏
Author
Owner

@IdrisGit commented on GitHub (Jan 25, 2026):

@nxxxsooo so I misread the issue a bit, I thought the model was not loading from the config.

The behaviour is very much intended, here is the order of model selection on startup or new session, config —> last used —> provider fallback.

If you want to always use the last model used, just remove the default model from config.

If your issue is something else, can please provide steps to reproduce.

@IdrisGit commented on GitHub (Jan 25, 2026): @nxxxsooo so I misread the issue a bit, I thought the model was not loading from the config. The behaviour is very much intended, here is the order of model selection on startup or new session, config —> last used —> provider fallback. If you want to always use the last model used, just remove the default model from config. If your issue is something else, can please provide steps to reproduce.
Author
Owner

@IdrisGit commented on GitHub (Jan 25, 2026):

@nxxxsooo regarding the "Recent" section issue, I have a open PR (https://github.com/anomalyco/opencode/pull/10518) for it, check it out and do give your feedback, if you like the solution thumbsup the PR.

@IdrisGit commented on GitHub (Jan 25, 2026): @nxxxsooo regarding the "Recent" section issue, I have a open PR (https://github.com/anomalyco/opencode/pull/10518) for it, check it out and do give your feedback, if you like the solution thumbsup the PR.
Author
Owner

@nxxxsooo commented on GitHub (Jan 25, 2026):

@IdrisGit I tested removing the default model from config. After restart, it didn't use my last selected model - instead it fell back to a different provider's model (anthropic/Opus 4.5).

It seems like the "last used" part of the selection order (config → last used → provider fallback) isn't working, and it's jumping straight to provider fallback.

Steps to reproduce:

  1. Have multiple providers configured (e.g., lmstudio, anthropic, google)
  2. Set a default model in config, use opencode, then switch to a different model
  3. Remove the default model from config and restart
  4. Expected: uses last selected model
  5. Actual: falls back to a different provider's model
@nxxxsooo commented on GitHub (Jan 25, 2026): @IdrisGit I tested removing the default model from config. After restart, it didn't use my last selected model - instead it fell back to a different provider's model (anthropic/Opus 4.5). It seems like the "last used" part of the selection order (config → last used → provider fallback) isn't working, and it's jumping straight to provider fallback. Steps to reproduce: 1. Have multiple providers configured (e.g., lmstudio, anthropic, google) 2. Set a default model in config, use opencode, then switch to a different model 3. Remove the default model from config and restart 4. Expected: uses last selected model 5. Actual: falls back to a different provider's model
Author
Owner

@IdrisGit commented on GitHub (Jan 25, 2026):

@nxxxsooo will check 👍🏼

@IdrisGit commented on GitHub (Jan 25, 2026): @nxxxsooo will check 👍🏼
Author
Owner

@IdrisGit commented on GitHub (Jan 26, 2026):

@nxxxsooo I tried the steps you mentioned, seems to be working fine for me, can you please share your opencode version, a screenrecoding of the issue would be much helpful as well

@IdrisGit commented on GitHub (Jan 26, 2026): @nxxxsooo I tried the steps you mentioned, seems to be working fine for me, can you please share your opencode version, a screenrecoding of the issue would be much helpful as well
Author
Owner

@rekram1-node commented on GitHub (Jan 26, 2026):

yeah please share:

opencode debug config

@rekram1-node commented on GitHub (Jan 26, 2026): yeah please share: opencode debug config
Author
Owner

@nxxxsooo commented on GitHub (Feb 6, 2026):

@IdrisGit @rekram1-node

Version: 1.1.53 (macOS, Apple Silicon)

Config (providers/MCP redacted):

{
  "provider": {
    "lmstudio": {
      "options": { "baseURL": "http://127.0.0.1:1234/v1" },
      "models": {
        "qwen3-30b-a3b-instruct-2507": { ... },
        "codestral-22b-v0.1": { ... },
        "qwen2.5-72b-instruct@4bit": { ... },
        "deepseek-r1-distill-llama-70b": { ... }
      }
    },
    "google": {
      "models": {
        "antigravity-gemini-3-pro": { ... },
        "antigravity-gemini-3-flash": { ... },
        "gemini-2.5-flash": { ... },
        "gemini-2.5-pro": { ... },
        "gemini-3-flash-preview": { ... },
        "gemini-3-pro-preview": { ... }
      }
    },
    "claudecode-relay": {
      "npm": "@ai-sdk/anthropic",
      "models": {
        "claude-opus-4-6": { ... },
        "claude-opus-4-5-20251101": { ... },
        "claude-opus-4-1-20250805": { ... },
        "claude-opus-4-20250514": { ... },
        "claude-sonnet-4-5-20250929": { ... },
        "claude-sonnet-4-20250514": { ... },
        "claude-haiku-4-5-20251001": { ... },
        "claude-3-5-haiku-20241022": { ... },
        "claude-3-5-sonnet-20241022": { ... },
        "claude-3-7-sonnet-20250219": { ... },
        "claude-3-haiku-20240307": { ... },
        "claude-3-opus-20240229": { ... }
      }
    }
  },
  "model": "claudecode-relay/claude-opus-4-5-20251101"
}

So I have 3 providers (lmstudio, google, claudecode-relay) with a default model set. During a session I switch to e.g. a lmstudio model, then restart — it goes back to the config default instead of remembering the last used model.

I understand the intended order is config → last used → provider fallback, but the "last used" step seems to not persist across restarts for me. Happy to provide a screen recording if this config info isn't enough to reproduce.

@nxxxsooo commented on GitHub (Feb 6, 2026): @IdrisGit @rekram1-node **Version**: 1.1.53 (macOS, Apple Silicon) **Config** (providers/MCP redacted): ```json { "provider": { "lmstudio": { "options": { "baseURL": "http://127.0.0.1:1234/v1" }, "models": { "qwen3-30b-a3b-instruct-2507": { ... }, "codestral-22b-v0.1": { ... }, "qwen2.5-72b-instruct@4bit": { ... }, "deepseek-r1-distill-llama-70b": { ... } } }, "google": { "models": { "antigravity-gemini-3-pro": { ... }, "antigravity-gemini-3-flash": { ... }, "gemini-2.5-flash": { ... }, "gemini-2.5-pro": { ... }, "gemini-3-flash-preview": { ... }, "gemini-3-pro-preview": { ... } } }, "claudecode-relay": { "npm": "@ai-sdk/anthropic", "models": { "claude-opus-4-6": { ... }, "claude-opus-4-5-20251101": { ... }, "claude-opus-4-1-20250805": { ... }, "claude-opus-4-20250514": { ... }, "claude-sonnet-4-5-20250929": { ... }, "claude-sonnet-4-20250514": { ... }, "claude-haiku-4-5-20251001": { ... }, "claude-3-5-haiku-20241022": { ... }, "claude-3-5-sonnet-20241022": { ... }, "claude-3-7-sonnet-20250219": { ... }, "claude-3-haiku-20240307": { ... }, "claude-3-opus-20240229": { ... } } } }, "model": "claudecode-relay/claude-opus-4-5-20251101" } ``` So I have 3 providers (lmstudio, google, claudecode-relay) with a default model set. During a session I switch to e.g. a lmstudio model, then restart — it goes back to the config default instead of remembering the last used model. I understand the intended order is config → last used → provider fallback, but the "last used" step seems to not persist across restarts for me. Happy to provide a screen recording if this config info isn't enough to reproduce.
Author
Owner

@IdrisGit commented on GitHub (Feb 6, 2026):

yeah a screen recording would be really helpful

@IdrisGit commented on GitHub (Feb 6, 2026): yeah a screen recording would be really helpful
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7449