Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(doctor): recognize Azure Foundry routing for Claude Code (#1339)

jknd5318ac23559
diff --git a/headroom/cli/doctor.py b/headroom/cli/doctor.py
index e30628661..3a7f6f667 100644
--- a/headroom/cli/doctor.py
+++ b/headroom/cli/doctor.py
@@ -316,7 +316,7 @@ def check_version_drift(livez: dict[str, Any] | None, installed: str) -> CheckRe
def _claude_base_url_in(path: Path) -> tuple[str, CheckResult | None]:
- """Read ``env.ANTHROPIC_BASE_URL`` from one Claude settings file.
+ """Read the active Claude routing URL from one settings file.
Returns ``(base_url, error)``. A parse problem comes back as a WARN so the
caller surfaces it verbatim instead of skipping the file and reporting the
@@ -340,7 +340,10 @@ def _claude_base_url_in(path: Path) -> tuple[str, CheckResult | None]:
)
env_block = payload.get("env")
if isinstance(env_block, dict):
- return str(env_block.get("ANTHROPIC_BASE_URL", "") or ""), None
+ base_url = str(env_block.get("ANTHROPIC_BASE_URL", "") or "")
+ if not base_url and str(env_block.get("CLAUDE_CODE_USE_FOUNDRY", "") or ""):
+ base_url = str(env_block.get("ANTHROPIC_FOUNDRY_BASE_URL", "") or "")
+ return base_url, None
return "", None
diff --git a/tests/test_cli_doctor.py b/tests/test_cli_doctor.py
index f257578ac..c40f5ce24 100644
--- a/tests/test_cli_doctor.py
+++ b/tests/test_cli_doctor.py
@@ -185,6 +185,42 @@ class TestClaudeRouting:
assert result.status == WARN
assert "gateway.corp.example" in result.summary
+ def test_foundry_url_passes(self, tmp_path):
+ # In Foundry mode ANTHROPIC_BASE_URL is absent by design; routing lives
+ # in ANTHROPIC_FOUNDRY_BASE_URL. doctor must recognize it as routed.
+ path = tmp_path / "settings.json"
+ path.write_text(
+ json.dumps(
+ {
+ "env": {
+ "CLAUDE_CODE_USE_FOUNDRY": "1",
+ "ANTHROPIC_FOUNDRY_BASE_URL": "http://127.0.0.1:8787",
+ }
+ }
+ ),
+ encoding="utf-8",
+ )
+ assert check_claude_routing(path, 8787).status == PASS
+
+ def test_foundry_without_base_url_warns(self, tmp_path):
+ # Foundry mode on but no upstream URL configured: still unrouted.
+ path = tmp_path / "settings.json"
+ path.write_text(
+ json.dumps({"env": {"CLAUDE_CODE_USE_FOUNDRY": "1"}}),
+ encoding="utf-8",
+ )
+ assert check_claude_routing(path, 8787).status == WARN
+
+ def test_foundry_url_ignored_without_flag(self, tmp_path):
+ # Without CLAUDE_CODE_USE_FOUNDRY the foundry URL is not consulted, so a
+ # settings file carrying only the foundry key reads as unrouted.
+ path = tmp_path / "settings.json"
+ path.write_text(
+ json.dumps({"env": {"ANTHROPIC_FOUNDRY_BASE_URL": "http://127.0.0.1:8787"}}),
+ encoding="utf-8",
+ )
+ assert check_claude_routing(path, 8787).status == WARN
+
class TestClaudeDesktop:
def test_no_desktop_dir_produces_no_row(self, tmp_path):