Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

fix(cli): preserve Claude Code background model override (#386)

Elias Shiehb256d936f1d7
diff --git a/switchyard/cli/launchers/claude_code_launcher.py b/switchyard/cli/launchers/claude_code_launcher.py
index 42279731d..0623c7518 100644
--- a/switchyard/cli/launchers/claude_code_launcher.py
+++ b/switchyard/cli/launchers/claude_code_launcher.py
@@ -66,8 +66,9 @@ def _claude_env(port: int, model: str) -> dict[str, str]:
* ``ANTHROPIC_BASE_URL`` — our proxy URL.
* ``ANTHROPIC_AUTH_TOKEN`` — opaque token; skips Console OAuth.
* ``ANTHROPIC_API_KEY=""`` — silences the auth-conflict warning.
- * ``ANTHROPIC_MODEL`` / ``ANTHROPIC_SMALL_FAST_MODEL`` — initial
- active model for the session.
+ * ``ANTHROPIC_MODEL`` — initial active model for the session.
+ * ``ANTHROPIC_SMALL_FAST_MODEL`` — existing background-model override,
+ falling back to the active model.
* ``ANTHROPIC_CUSTOM_MODEL_OPTION`` — registers ``model`` as a custom
slot in ``/model`` so the user can come back to it after toggling
to a builtin.
@@ -79,7 +80,7 @@ def _claude_env(port: int, model: str) -> dict[str, str]:
"ANTHROPIC_AUTH_TOKEN": "switchyard",
"ANTHROPIC_API_KEY": "",
"ANTHROPIC_MODEL": model,
- "ANTHROPIC_SMALL_FAST_MODEL": model,
+ "ANTHROPIC_SMALL_FAST_MODEL": os.environ.get("ANTHROPIC_SMALL_FAST_MODEL", model),
"ANTHROPIC_CUSTOM_MODEL_OPTION": model,
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1",
}
diff --git a/tests/test_launchers.py b/tests/test_launchers.py
index b0fc60bb7..4e15e2754 100644
--- a/tests/test_launchers.py
+++ b/tests/test_launchers.py
@@ -9,6 +9,7 @@ from pathlib import Path
import pytest
from switchyard.cli.launch_command import _config_path
+from switchyard.cli.launchers.claude_code_launcher import _claude_env
from switchyard.cli.launchers.native_server import NativeServer
from switchyard.cli.switchyard_cli import _build_parser
@@ -50,6 +51,17 @@ def test_default_config_is_packaged_openrouter_deployment() -> None:
assert "OPENROUTER_API_KEY" in config.read_text()
+def test_claude_env_preserves_small_fast_model_override(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ monkeypatch.setenv("ANTHROPIC_SMALL_FAST_MODEL", "background-route")
+
+ env = _claude_env(4321, "agent-route")
+
+ assert env["ANTHROPIC_MODEL"] == "agent-route"
+ assert env["ANTHROPIC_SMALL_FAST_MODEL"] == "background-route"
+
+
def test_native_server_passes_config_directly_to_binding(
monkeypatch: pytest.MonkeyPatch,
tmp_path: Path,