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): surface that Claude Desktop agent sessions bypass the proxy (#2987)

Abhay Singhbe5b26d807be
diff --git a/headroom/cli/doctor.py b/headroom/cli/doctor.py
index a45a0cbf1..cd5d4839a 100644
--- a/headroom/cli/doctor.py
+++ b/headroom/cli/doctor.py
@@ -14,6 +14,7 @@ from __future__ import annotations
import json
import os
import re
+import sys
from collections.abc import Callable, Mapping
from dataclasses import asdict, dataclass
from datetime import datetime
@@ -224,6 +225,51 @@ def check_claude_auth_conflict(
)
+def claude_desktop_config_dir() -> Path:
+ """Return Claude Desktop's per-user config directory for this platform.
+
+ Claude Desktop (``com.anthropic.claudefordesktop``) stores its config here,
+ distinct from Claude Code CLI's ``~/.claude``. Directory existence is used as
+ a proxy for "Desktop is installed / has been run" (#2925).
+ """
+ home = Path.home()
+ if sys.platform == "darwin":
+ return home / "Library" / "Application Support" / "Claude"
+ if os.name == "nt":
+ appdata = os.environ.get("APPDATA")
+ base = Path(appdata) if appdata else home / "AppData" / "Roaming"
+ return base / "Claude"
+ xdg = os.environ.get("XDG_CONFIG_HOME")
+ base = Path(xdg) if xdg else home / ".config"
+ return base / "Claude"
+
+
+def check_claude_desktop(config_dir: Path) -> CheckResult | None:
+ """Surface that Claude Desktop agent sessions bypass the proxy (#2925 / #869).
+
+ Claude Desktop unconditionally overwrites ``ANTHROPIC_BASE_URL`` when it
+ spawns agent sessions, so a correctly-wrapped ``~/.claude/settings.json``
+ (which the ``claude`` check verifies for the terminal CLI) does not route
+ Desktop traffic. Without this, ``doctor`` passes on the settings value alone
+ and never hints that Desktop sessions are unrouted.
+
+ Reported as its own per-surface row -- like ``wrap_marker`` and ``shell env``
+ -- and only when Desktop is detected, so it never contradicts a genuinely
+ routed CLI. Returns ``None`` when Desktop is absent (no row).
+ """
+ if not config_dir.exists():
+ return None
+ return CheckResult(
+ name="claude desktop",
+ status=WARN,
+ summary="agent sessions bypass the proxy (Desktop overwrites ANTHROPIC_BASE_URL)",
+ hint=(
+ "Desktop routing is not supported yet (see #869); use the terminal "
+ "Claude Code CLI for proxy-routed sessions."
+ ),
+ )
+
+
def check_claude_remote_control_gate(
settings_path: Path,
environ: Mapping[str, str],
@@ -630,6 +676,9 @@ def doctor(port: int, emit_json: bool) -> None:
)
if remote_control_gate_check is not None:
checks.append(remote_control_gate_check)
+ desktop_check = check_claude_desktop(claude_desktop_config_dir())
+ if desktop_check is not None:
+ checks.append(desktop_check)
deployments = check_deployments(list_manifests())
if deployments is not None:
checks.append(deployments)
diff --git a/tests/test_cli_doctor.py b/tests/test_cli_doctor.py
index 6fe42581d..8695af976 100644
--- a/tests/test_cli_doctor.py
+++ b/tests/test_cli_doctor.py
@@ -15,6 +15,7 @@ from headroom.cli.doctor import (
SKIP,
WARN,
check_budget,
+ check_claude_desktop,
check_claude_remote_control_gate,
check_claude_routing,
check_codex_routing,
@@ -152,6 +153,43 @@ class TestClaudeRouting:
assert "gateway.corp.example" in result.summary
+class TestClaudeDesktop:
+ def test_no_desktop_dir_produces_no_row(self, tmp_path):
+ # #2925: absent Desktop -> no row, so it never contradicts a routed CLI.
+ assert check_claude_desktop(tmp_path / "Claude") is None
+
+ def test_desktop_present_warns_about_bypass(self, tmp_path):
+ desktop = tmp_path / "Claude"
+ desktop.mkdir()
+ result = check_claude_desktop(desktop)
+ assert result is not None
+ assert result.name == "claude desktop"
+ assert result.status == WARN
+ assert "bypass" in result.summary
+ assert "#869" in (result.hint or "")
+
+ def test_doctor_appends_desktop_row_when_present(self, tmp_path, monkeypatch):
+ # Integration: the entrypoint surfaces the Desktop row when detected.
+ desktop = tmp_path / "Claude"
+ desktop.mkdir()
+ monkeypatch.setattr(doctor_mod, "claude_desktop_config_dir", lambda: desktop)
+ monkeypatch.setattr(doctor_mod, "probe_json", lambda *a, **k: None)
+ monkeypatch.setattr(doctor_mod, "list_manifests", lambda: [])
+ result = CliRunner().invoke(main, ["doctor", "--json"])
+ payload = json.loads(result.output)
+ rows = {c["name"]: c for c in payload["checks"]}
+ assert "claude desktop" in rows
+ assert rows["claude desktop"]["status"] == WARN
+
+ def test_doctor_omits_desktop_row_when_absent(self, tmp_path, monkeypatch):
+ monkeypatch.setattr(doctor_mod, "claude_desktop_config_dir", lambda: tmp_path / "Claude")
+ monkeypatch.setattr(doctor_mod, "probe_json", lambda *a, **k: None)
+ monkeypatch.setattr(doctor_mod, "list_manifests", lambda: [])
+ result = CliRunner().invoke(main, ["doctor", "--json"])
+ payload = json.loads(result.output)
+ assert "claude desktop" not in {c["name"] for c in payload["checks"]}
+
+
class TestClaudeRemoteControlGate:
def test_settings_custom_base_warns(self, tmp_path):
path = tmp_path / "settings.json"