Skip to content

A tiny friend in your Mac's notch and on your iPhone that keeps an eye on your AI coding agents: Claude Code, Codex, Cursor, Gemini CLI, Antigravity and more. Approve from the notch or your Lock Screen.

Discover Claude API models and preserve the saved selection

Anatoly Lazarev37adcc3c0db8
diff --git a/CLAUDE.md b/CLAUDE.md
index e0d51a02..4f802850 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -18,6 +18,8 @@ cd NotchBuddy && xcodegen && xcodebuild -scheme NotchBuddy -configuration Debug
To run it day to day on the Mac (signed, iPhone link, permissions kept across builds): `./scripts/dev-install.sh` — it installs the only Coucou in /Applications and removes the copies earlier builds left.
Windows and Linux: `cd windows && npm install && npm run tauri dev`
+The Claude API model picker discovers account models independently of subscription routing. Opening Settings, changing the API key and Refresh reload the list without changing the saved model. Keep saved and custom choices; commit a model choice only after settings save succeeds.
+
## Rules
- Swift 6, SwiftUI + AppKit. No third-party dependencies unless truly unavoidable. The character is drawn in code (`Canvas` + `TimelineView`), no Rive/Lottie/images.
- Secrets live in the Keychain, never on disk or in git.
diff --git a/windows/screenshots/claude-model-picker.jpg b/windows/screenshots/claude-model-picker.jpg
new file mode 100644
index 00000000..d1ef4c08
Binary files /dev/null and b/windows/screenshots/claude-model-picker.jpg differ
diff --git a/windows/src-tauri/src/chat.rs b/windows/src-tauri/src/chat.rs
index a681e05e..c479959a 100644
--- a/windows/src-tauri/src/chat.rs
+++ b/windows/src-tauri/src/chat.rs
@@ -257,8 +257,7 @@ pub async fn models(settings: &Settings, provider: &str) -> Result<Vec<ModelInfo
return Ok(cli_relay::models(provider));
}
if provider == ANTHROPIC {
- let key = secrets::get(claude::KEY).ok_or_else(no_key)?;
- return claude::models(&key).await;
+ return claude::available_models().await;
}
if let Some(p) = openai_compat::provider(provider) {
let key = secrets::get(p.key).ok_or_else(no_key)?;
diff --git a/windows/src-tauri/src/claude.rs b/windows/src-tauri/src/claude.rs
index 50e74f91..0f90c67f 100644
--- a/windows/src-tauri/src/claude.rs
+++ b/windows/src-tauri/src/claude.rs
@@ -248,6 +248,11 @@ async fn call_with_timeout(endpoint: &Url, key: &str, body: &Value, timeout: Dur
}
/// The models on the user's Anthropic account, newest first, as the API lists them.
+pub async fn available_models() -> Result<Vec<ModelInfo>, String> {
+ let key = secrets::get(KEY).ok_or_else(|| t("No API key — add it in Settings."))?;
+ models(&key).await
+}
+
pub async fn models(key: &str) -> Result<Vec<ModelInfo>, String> {
let url = models_endpoint(&endpoint()?);
let response = net::client(&url, Duration::from_secs(10))?
@@ -338,6 +343,19 @@ fn base64(bytes: &[u8]) -> String {
mod tests {
use super::*;
+ #[test]
+ #[ignore = "Uses the configured Claude API key for model discovery and one short synthetic request"]
+ fn configured_api_lists_and_calls_sonnet_5_5() {
+ let runtime = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
+ let models = runtime.block_on(available_models()).unwrap_or_else(|_| panic!("Configured Claude API model discovery failed"));
+ println!("Available Claude API models: {:?}", models.iter().map(|m| &m.id).collect::<Vec<_>>());
+ assert!(models.iter().any(|m| m.id == "claude-sonnet-5-5"), "Sonnet 5.5 is not in this account's model list");
+ let reply = runtime.block_on(complete("claude-sonnet-5-5", "Answer with the single word OK.", "This is a synthetic connection test.", 256, Duration::from_secs(60)))
+ .unwrap_or_else(|_| panic!("Sonnet 5.5 synthetic request failed"));
+ assert_eq!(reply.trim(), "OK");
+ println!("Sonnet 5.5 returned the expected synthetic reply");
+ }
+
#[test]
fn base64_matches_rfc4648_vectors() {
assert_eq!(base64(b""), "");
diff --git a/windows/src-tauri/src/lib.rs b/windows/src-tauri/src/lib.rs
index 765772de..fb0a9868 100644
--- a/windows/src-tauri/src/lib.rs
+++ b/windows/src-tauri/src/lib.rs
@@ -548,6 +548,12 @@ async fn chat_models(shared: State<'_, Shared>, provider: String) -> Result<Vec<
chat::models(&settings, &provider).await
}
+/// The Claude API settings use their own key even when chat uses a CLI plan.
+#[tauri::command]
+async fn claude_api_models() -> Result<Vec<ModelInfo>, String> {
+ claude::available_models().await
+}
+
/// Settings → Local models → Connect: does the server answer, and with which models?
#[tauri::command]
async fn local_connect(provider: String, url: String) -> Result<local_chat::Connected, String> {
@@ -885,6 +891,7 @@ pub fn run() {
log_line,
chat_send,
chat_models,
+ claude_api_models,
local_connect,
local_set_key,
chat_reset,
diff --git a/windows/src/core/bridge.ts b/windows/src/core/bridge.ts
index c8868a08..fe2a0a26 100644
--- a/windows/src/core/bridge.ts
+++ b/windows/src/core/bridge.ts
@@ -370,6 +370,7 @@ export const Bridge = {
* the provider only when it has a key (or a server address).
*/
chatModels: (provider: string) => callOrThrow<ModelInfo[]>("chat_models", { provider }),
+ claudeApiModels: () => callOrThrow<ModelInfo[]>("claude_api_models"),
/** Settings → Local models → Connect: does the server answer, and with which models? */
/** The custom server's key, bound to the address it is entered for. */
localSetKey: (url: string, key: string) => call<void>("local_set_key", { url, key }),
diff --git a/windows/src/settings/claude-models.ts b/windows/src/settings/claude-models.ts
new file mode 100644
index 00000000..25a87c05
--- /dev/null
+++ b/windows/src/settings/claude-models.ts
@@ -0,0 +1,71 @@
+import { Bridge, type ModelInfo } from "../core/bridge";
+import { h, clear } from "../views/dom";
+import { t } from "../i18n/i18n";
+
+// Verified against Anthropic's catalog. Account discovery replaces these
+// choices when a key is present; never replace a saved model automatically.
+export const CLAUDE_MODELS: ModelInfo[] = [
+ { id: "claude-sonnet-5-5", label: "Claude Sonnet 5.5" },
+ { id: "claude-opus-5-5", label: "Claude Opus 5.5" },
+ { id: "claude-haiku-5-5", label: "Claude Haiku 5.5" },
+ { id: "claude-fable-5-1", label: "Claude Fable 5.1" },
+];
+
+export function claudeModelControl(saved: () => string, save: (id: string) => Promise<void>) {
+ const select = h("select", { "aria-label": t("Model") }) as HTMLSelectElement;
+ const refresh = h("button", { text: t("Refresh") }) as HTMLButtonElement;
+ const feedback = h("div", { class: "hint", role: "status" });
+ const element = h("div", {}, h("div", { class: "row" }, h("label", { text: t("Model") }), select, refresh), feedback);
+ let models = CLAUDE_MODELS;
+ let hasKey = false, loading = false, saving = false, generation = 0;
+ let loadError = "", saveError = "";
+
+ function controls() {
+ select.disabled = saving;
+ refresh.disabled = !hasKey || loading || saving;
+ feedback.textContent = saveError || loadError || (loading ? t("Loading models…") : "");
+ }
+ function render() {
+ clear(select);
+ const choices = new Map(models.map(model => [model.id, model.label]));
+ const current = saved();
+ if (current && !choices.has(current)) choices.set(current, current);
+ for (const [id, label] of choices) select.append(h("option", { value: id, text: label }));
+ select.value = current;
+ controls();
+ }
+ async function reload(present = hasKey) {
+ hasKey = present;
+ const request = ++generation;
+ loading = present;
+ loadError = "";
+ controls();
+ if (!present) { models = CLAUDE_MODELS; if (!saving) render(); return; }
+ try {
+ // Explicit API discovery must not be redirected by a Claude Code
+ // subscription switch. Credentials stay entirely in the native client.
+ const received = await Bridge.claudeApiModels();
+ if (request !== generation) return;
+ models = received;
+ } catch (error) {
+ if (request !== generation) return;
+ loadError = String(error).replace(/^Error:\s*/, "");
+ } finally {
+ if (request === generation) { loading = false; if (!saving) render(); controls(); }
+ }
+ }
+ select.addEventListener("change", async () => {
+ if (saving) return;
+ const next = select.value;
+ if (!next || next === saved()) return;
+ saving = true;
+ saveError = "";
+ controls();
+ try { await save(next); }
+ catch (error) { saveError = String(error).replace(/^Error:\s*/, ""); }
+ finally { saving = false; render(); }
+ });
+ refresh.addEventListener("click", () => { if (!refresh.disabled) void reload(); });
+ render();
+ return { element, reload };
+}
diff --git a/windows/src/settings/main.ts b/windows/src/settings/main.ts
index 04d9609f..6e2365f6 100644
--- a/windows/src/settings/main.ts
+++ b/windows/src/settings/main.ts
@@ -20,6 +20,7 @@ import {
import { h, clear } from "../views/dom";
import { startHub, type PageId } from "../hub/shell";
import { FLOW_PAGE_RENDERERS } from "../hub/pages";
+import { claudeModelControl } from "./claude-models";
import { agentsSection } from "./agents";
import { phoneSection } from "./phone";
import { whatsappSection } from "./whatsapp";
@@ -393,12 +394,6 @@ function subscriptionsSection(): HTMLElement {
// ── Claude API section ────────────────────────────────────────────────────────
-const MODELS: [string, string][] = [
- ["claude-opus-5", "Claude Opus 5"],
- ["claude-sonnet-5", "Claude Sonnet 5"],
- ["claude-haiku-4-5", "Claude Haiku 4.5"],
-];
-
/** The state line under Claude: the key, else Claude Code (switched on above), else what is missing. */
function apiState(hasKey: boolean, relay: boolean): string {
if (hasKey) return t("Key saved in the {store}.", { store: KEY_STORE });
@@ -430,6 +425,7 @@ function apiSection(hasKey: boolean, relay: boolean): HTMLElement {
state.textContent = apiState(present, ready && !present);
field.placeholder = present ? `•••••••••••• ${t("(stored)")}` : "sk-ant-...";
clearBtn.style.display = present ? "" : "none";
+ void model.reload(present);
}
saveBtn.addEventListener("click", async () => {
@@ -457,16 +453,11 @@ function apiSection(hasKey: boolean, relay: boolean): HTMLElement {
}
});
- const model = h("select", {}) as HTMLSelectElement;
- for (const [id, label] of MODELS) model.append(h("option", { value: id, text: label }));
- if (!MODELS.some(([id]) => id === settings.model)) {
- model.append(h("option", { value: settings.model, text: settings.model }));
- }
- model.value = settings.model;
- model.addEventListener("change", () => {
- settings.model = model.value;
- void save();
+ const model = claudeModelControl(() => settings.model, async (value) => {
+ await Bridge.saveSettings({ ...settings, model: value });
+ settings.model = value;
});
+ void model.reload(hasKey);
clearBtn.style.display = hasKey ? "" : "none";
@@ -476,7 +467,7 @@ function apiSection(hasKey: boolean, relay: boolean): HTMLElement {
h("h2", {}, dot, h("span", { text: "Claude" })),
state,
h("div", { class: "row" }, h("label", { text: t("API key") }), field, saveBtn, clearBtn),
- h("div", { class: "row" }, h("label", { text: t("Model") }), model),
+ model.element,
feedback,
);
}
diff --git a/windows/tests/claude-models.test.mjs b/windows/tests/claude-models.test.mjs
new file mode 100644
index 00000000..7b487304
--- /dev/null
+++ b/windows/tests/claude-models.test.mjs
@@ -0,0 +1,84 @@
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import { installFakeDom } from "./fakedom.mjs";
+import { Bridge } from "../src/core/bridge.ts";
+import { claudeModelControl } from "../src/settings/claude-models.ts";
+
+installFakeDom();
+const flush = () => new Promise(resolve => setTimeout(resolve, 0));
+const select = control => control.element.find("select")[0];
+const ids = control => control.element.find("option").map(option => option.getAttribute("value"));
+
+test("current Claude presets include Sonnet 5.5 and retain a saved older model without an API request", async t => {
+ let calls = 0;
+ t.mock.method(Bridge, "claudeApiModels", async () => { calls++; return []; });
+ const control = claudeModelControl(() => "claude-sonnet-5", async () => { throw new Error("unexpected save"); });
+ await control.reload(false);
+ assert.ok(ids(control).includes("claude-sonnet-5-5"));
+ assert.ok(ids(control).includes("claude-opus-5-5"));
+ assert.ok(ids(control).includes("claude-haiku-5-5"));
+ assert.equal(select(control).value, "claude-sonnet-5");
+ assert.equal(calls, 0);
+});
+
+test("API discovery uses its own catalog and never replaces the user's saved model", async t => {
+ t.mock.method(Bridge, "chatModels", () => { throw new Error("subscription-aware chat route must not be used"); });
+ t.mock.method(Bridge, "claudeApiModels", async () => [{ id: "claude-new", label: "New account model" }]);
+ const control = claudeModelControl(() => "custom-gateway-model", async () => { throw new Error("unexpected save"); });
+ await control.reload(true);
+ assert.deepEqual(ids(control), ["claude-new", "custom-gateway-model"]);
+ assert.equal(select(control).value, "custom-gateway-model");
+});
+
+test("removing or replacing a key invalidates a late model response", async t => {
+ let complete;
+ t.mock.method(Bridge, "claudeApiModels", () => new Promise(resolve => { complete = resolve; }));
+ let saved = "claude-sonnet-5-5";
+ const control = claudeModelControl(() => saved, async next => { saved = next; });
+ const loading = control.reload(true);
+ await control.reload(false);
+ complete([{ id: "stale-private-model", label: "Stale" }]);
+ await loading;
+ select(control).value = "claude-opus-5-5";
+ select(control).fire("change");
+ await flush();
+ assert.ok(!ids(control).includes("stale-private-model"));
+ assert.equal(saved, "claude-opus-5-5");
+});
+
+test("failed model saves revert the selection, survive a late list response and allow retry", async t => {
+ let complete, calls = 0, fail = true, saved = "claude-sonnet-5";
+ t.mock.method(Bridge, "claudeApiModels", () => new Promise(resolve => { complete = resolve; }));
+ const control = claudeModelControl(() => saved, async next => {
+ calls++;
+ await flush();
+ if (fail) throw new Error("Settings file is locked");
+ saved = next;
+ });
+ const loading = control.reload(true);
+ select(control).value = "claude-sonnet-5-5";
+ select(control).fire("change");
+ select(control).fire("change");
+ assert.equal(select(control).disabled, true);
+ await flush(); await flush();
+ assert.equal(calls, 1);
+ complete([{ id: "claude-sonnet-5-5", label: "Claude Sonnet 5.5" }]);
+ await loading;
+ assert.match(control.element.textContent, /Settings file is locked/);
+ assert.equal(select(control).value, saved);
+ fail = false;
+ select(control).value = "claude-sonnet-5-5";
+ select(control).fire("change");
+ await flush(); await flush();
+ assert.equal(saved, "claude-sonnet-5-5");
+ assert.doesNotMatch(control.element.textContent, /Settings file is locked/);
+});
+
+test("catalog failures keep known choices and report the error", async t => {
+ t.mock.method(Bridge, "claudeApiModels", async () => { throw new Error("Claude API unavailable"); });
+ const control = claudeModelControl(() => "claude-sonnet-5-5", async () => {});
+ await control.reload(true);
+ assert.match(control.element.textContent, /Claude API unavailable/);
+ assert.ok(ids(control).includes("claude-sonnet-5-5"));
+ assert.equal(select(control).disabled, false);
+});