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.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(proxy): preserve Cline headroom__headroom_retrieve results from recompression (#4586)
Ryrenz1b9d296c196d
diff --git a/headroom/config.py b/headroom/config.pyindex 25d8e5b78..b42617575 100644--- a/headroom/config.py+++ b/headroom/config.py@@ -368,7 +368,9 @@ def _tool_name_aliases(name: str) -> tuple[str, ...]:aliases = [name]lname = name.lower()- if lname == "headroom_headroom_retrieve":+ # Clients that prefix MCP tools with the server name: OpenCode joins with a+ # single underscore, Cline with a double one (<server>__<tool>, #4585).+ if lname in ("headroom_headroom_retrieve", "headroom__headroom_retrieve"):aliases.append("headroom_retrieve")elif lname.startswith("mcp__"):# OpenAI-style MCP wrappers use mcp__server__tool. Custom agents thatdiff --git a/tests/test_tool_name_aliases.py b/tests/test_tool_name_aliases.pyindex db5c41c3e..35a9106c0 100644--- a/tests/test_tool_name_aliases.py+++ b/tests/test_tool_name_aliases.py@@ -14,6 +14,7 @@ from headroom.config import DEFAULT_EXCLUDE_TOOLS, is_tool_excluded"mcp__headroom__headroom_retrieve","mcp_headroom_headroom_retrieve","headroom_headroom_retrieve",+ "headroom__headroom_retrieve",],)def test_retrieve_tool_aliases_are_excluded(name: str) -> None:diff --git a/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py b/tests/test_transforms/test_content_router_ccr_retrieve_exemption.pyindex 1bb9b443f..767a690d1 100644--- a/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py+++ b/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py@@ -195,6 +195,20 @@ class TestContentRouterCcrRetrieveExemption:assert "<<ccr:" not in tool_msg["content"]assert "router:excluded:ccr_retrieve" in result.transforms_applied+ def test_cline_server_tool_mcp_name_not_recompressed(self):+ """Cline's <server>__<tool> name must resolve to the excluded tool (#4585)."""+ content = _big_json()+ router = ContentRouter(ContentRouterConfig(min_section_tokens=10))+ tokenizer = _get_tokenizer()++ messages = _openai_messages("headroom__headroom_retrieve", content)+ result = router.apply(messages, tokenizer)++ tool_msg = next(m for m in result.messages if m.get("tool_call_id") == "call_ccr_1")+ assert tool_msg["content"] == content+ assert "<<ccr:" not in tool_msg["content"]+ assert "router:excluded:ccr_retrieve" in result.transforms_applied+def test_bare_tool_name_also_protected(self):"""The proxy's own internally-injected retrieval tool uses the barename (not MCP-qualified) — must be protected too, matching the