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(claude): treat non-zero claude --version exit as version-unknown … (#2233)

Ayush Kumar Jhaf71fef1ca6a1
diff --git a/headroom/providers/claude/runtime.py b/headroom/providers/claude/runtime.py
index cec4b4af9..023357d01 100644
--- a/headroom/providers/claude/runtime.py
+++ b/headroom/providers/claude/runtime.py
@@ -218,6 +218,13 @@ def detect_claude_code_version(claude_bin: str | None = None) -> tuple[int, int,
proc = run([binary, "--version"], capture_output=True, text=True, timeout=10)
except (OSError, subprocess.SubprocessError):
return None
+ # A non-zero exit is a detection failure, per this function's contract: a
+ # failing `claude --version` may still print a version-shaped string, and
+ # trusting it would surface a false *exact*-version warning instead of the
+ # self-qualified "2.1.196+ / unknown" path the callers rely on. getattr with
+ # a success default keeps stubbed CompletedProcess objects working.
+ if getattr(proc, "returncode", 0) != 0:
+ return None
# getattr, not attribute access: a stubbed CompletedProcess (e.g. a test's
# SimpleNamespace) may lack stdout/stderr — degrade to "unknown", never raise.
stdout = getattr(proc, "stdout", "") or ""
diff --git a/tests/test_issue_1779_remote_control_gate.py b/tests/test_issue_1779_remote_control_gate.py
index cc6118335..0a7a17e5b 100644
--- a/tests/test_issue_1779_remote_control_gate.py
+++ b/tests/test_issue_1779_remote_control_gate.py
@@ -168,6 +168,23 @@ def test_detect_claude_code_version_parses_wrapper_output(monkeypatch) -> None:
assert detect_claude_code_version("claude") == (2, 1, 196)
+def test_detect_claude_code_version_nonzero_exit_is_none(monkeypatch) -> None:
+ # Review follow-up (PR #1883, @JerrettDavis): a non-zero exit is a detection
+ # failure even when the failing command still prints a version-shaped string.
+ # Trusting it would emit a false *exact*-version Remote Control warning
+ # instead of the self-qualified "2.1.196+ / unknown" path. Must return None.
+ from types import SimpleNamespace
+
+ import headroom._subprocess as _sub
+
+ monkeypatch.setattr(
+ _sub,
+ "run",
+ lambda *a, **k: SimpleNamespace(returncode=1, stdout="2.1.196 (Claude Code)\n", stderr=""),
+ )
+ assert detect_claude_code_version("claude") is None
+
+
# ---------------------------------------------------------------------------
# Sibling co-report (#746 / #1158)
# ---------------------------------------------------------------------------