Remember last chosen provider/model in HX_HOME/last.json

This commit is contained in:
hermes committed 2026-10-06 11:43:51 +00:00
1 parent 6f951ad7f8
commit 2f1ce2c072
2 files changed
+65 -4

No files matched your search

+19 -4
View File
@@ -99,6 +99,8 @@ struct Config {
explore_model: Option<String>,
/// Capture the mouse for wheel scrolling (default true; false = terminal selection works without shift).
mouse: Option<bool>,
/// Reuse the last model chosen with /model or /provider (default true).
remember_model: Option<bool>,
/// "ask" (default) or "yolo": whether bash/write/edit prompt in the TUI.
permissions: Option<String>,
/// Replaces the built-in system prompt (AGENTS.md etc. are still appended).
@@ -146,6 +148,7 @@ impl Config {
max_tokens: o.max_tokens.or(c.max_tokens),
explore_model: o.explore_model.or(c.explore_model),
mouse: o.mouse.or(c.mouse),
remember_model: o.remember_model.or(c.remember_model),
permissions: o.permissions.or(c.permissions),
system_prompt: o.system_prompt.or(c.system_prompt),
lsp: o.lsp.or(c.lsp),
@@ -478,10 +481,18 @@ async fn main() -> Result<()> {
let cwd = std::env::current_dir()?;
let cfg = Config::load(&cwd)?;
let kinds = logged_in();
// default provider: configured, else the first one logged in
let last_path = context::hx_home().join("last.json");
let remember = cfg.remember_model != Some(false);
// last /model choice, only while its provider is still logged in
let last = remember
.then(|| hx_core::switch::Last::load(&last_path))
.flatten()
.filter(|l| kinds.contains(&l.provider));
// default provider: flag, config, last choice, else the first one logged in
let kind = cli
.provider
.or(cfg.provider)
.or(last.as_ref().map(|l| l.provider))
.or(kinds.first().copied())
.unwrap_or(Kind::Claude);
let models = catalog(&kinds).await;
@@ -490,7 +501,9 @@ async fn main() -> Result<()> {
(None, Some(m)) => hx_ai::models::kind_of(&models, m).unwrap_or(kind),
_ => kind,
};
let model = cli.model.or(cfg.model).unwrap_or_else(|| {
// the remembered model applies only to the provider it was chosen on
let last_model = last.filter(|l| l.provider == kind).map(|l| l.model);
let model = cli.model.or(cfg.model).or(last_model).unwrap_or_else(|| {
match kind {
Kind::Claude => cfg.claude_model.clone(),
Kind::Codex => cfg.codex_model.clone(),
@@ -667,7 +680,8 @@ async fn main() -> Result<()> {
models.clone(),
Box::new(provider),
cfg.compact_at.is_none(),
),
)
.remember_in(last_path.clone()),
},
)
.await;
@@ -685,7 +699,8 @@ async fn main() -> Result<()> {
models.clone(),
Box::new(provider),
cfg.compact_at.is_none(),
),
)
.remember_in(last_path),
pricing,
specs,
open_sessions,