From b06c06ad80004de879d73d6d61ea6e43cd0604e4 Mon Sep 17 00:00:00 2001 From: hermes Date: Fri, 16 Oct 2026 20:13:46 +0000 Subject: [PATCH] cli: claude_cli auto-on when claude is in PATH; false disables --- crates/hx-cli/src/main.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/crates/hx-cli/src/main.rs b/crates/hx-cli/src/main.rs index b7fd7fa..0283f84 100644 --- a/crates/hx-cli/src/main.rs +++ b/crates/hx-cli/src/main.rs @@ -111,14 +111,22 @@ enum McpAction { } /// `~/.hx/config.toml`, overridden by `.hx/config.toml` in the project. +#[derive(Clone, serde::Deserialize)] +#[serde(untagged)] +enum CliCfg { + Switch(bool), + Args(Vec), +} + #[derive(Default, serde::Deserialize)] #[serde(default, deny_unknown_fields)] struct Config { provider: Option, model: Option, claude_model: Option, - /// Run Claude through the official `claude` CLI (subscription billing). Value = extra `claude` args, `[]` for none. - claude_cli: Option>, + /// Run Claude through the official `claude` CLI (subscription billing). Default: on when `claude` is in PATH. + /// `false` = own OAuth calls (billed as extra usage); `true` / `[]` = on; a list = on with extra `claude` args. + claude_cli: Option, /// OpenAI-compatible endpoint (Ollama, vLLM, LM Studio, OpenRouter, ...), provider "custom". openai_compat: Option, codex_model: Option, @@ -629,7 +637,15 @@ async fn main() -> Result<()> { if let Some(oc) = cfg.openai_compat.clone() { let _ = COMPAT.set(oc); } - if let Some(a) = cfg.claude_cli.clone() { + // auto-detect, except against a test server (HX_BASE_URL) + let cli_args = match cfg.claude_cli.clone() { + Some(CliCfg::Args(a)) => Some(a), + Some(CliCfg::Switch(on)) => on.then(Vec::new), + None => (std::env::var_os("HX_BASE_URL").is_none() + && hx_ai::claude_cli::ClaudeCli::available()) + .then(Vec::new), + }; + if let Some(a) = cli_args { let _ = CLAUDE_CLI.set(a); } // MCP servers connect while the model catalog loads @@ -1020,6 +1036,19 @@ mod tests { #[cfg(test)] mod config_tests { + #[test] + fn claude_cli_switch_or_args() { + use super::{CliCfg, Config}; + let p = |t: &str| toml::from_str::(t).unwrap().claude_cli; + assert!(matches!( + p("claude_cli = false"), + Some(CliCfg::Switch(false)) + )); + assert!(matches!(p("claude_cli = true"), Some(CliCfg::Switch(true)))); + assert!(matches!(p("claude_cli = [\"-x\"]"), Some(CliCfg::Args(a)) if a == ["-x"])); + assert!(p("").is_none()); + } + #[test] fn sample_config_parses() { let s = super::SAMPLE_CONFIG;