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 OpenCode Headroom retrieve results (#3782)
lorenzozanec7ebaedd74b2
diff --git a/headroom/config.py b/headroom/config.pyindex 0cbc35bf2..76ba6b8e4 100644--- a/headroom/config.py+++ b/headroom/config.py@@ -360,7 +360,9 @@ def _tool_name_aliases(name: str) -> tuple[str, ...]:aliases = [name]lname = name.lower()- if lname.startswith("mcp__"):+ if lname == "headroom_headroom_retrieve":+ aliases.append("headroom_retrieve")+ elif lname.startswith("mcp__"):# OpenAI-style MCP wrappers use mcp__server__tool. Custom agents that# speak Anthropic sometimes emit the same wrapper as mcp_Server_tool.parts = name.split("__", 2)diff --git a/tests/test_tool_name_aliases.py b/tests/test_tool_name_aliases.pynew file mode 100644index 000000000..db5c41c3e--- /dev/null+++ b/tests/test_tool_name_aliases.py@@ -0,0 +1,25 @@+"""Tests for normalizing client-specific tool names."""++from __future__ import annotations++import pytest++from headroom.config import DEFAULT_EXCLUDE_TOOLS, is_tool_excluded+++ "name",+ [+ "headroom_retrieve",+ "mcp__headroom__headroom_retrieve",+ "mcp_headroom_headroom_retrieve",+ "headroom_headroom_retrieve",+ ],+)+def test_retrieve_tool_aliases_are_excluded(name: str) -> None:+ assert is_tool_excluded(name, DEFAULT_EXCLUDE_TOOLS)+++def test_unrelated_underscored_tool_names_are_not_excluded() -> None:+ assert not is_tool_excluded("my_headroom_retrieve", DEFAULT_EXCLUDE_TOOLS)+ assert not is_tool_excluded("other_Read", DEFAULT_EXCLUDE_TOOLS)diff --git a/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py b/tests/test_transforms/test_content_router_ccr_retrieve_exemption.pyindex cb48a951b..1bb9b443f 100644--- a/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py+++ b/tests/test_transforms/test_content_router_ccr_retrieve_exemption.py@@ -181,6 +181,20 @@ class TestContentRouterCcrRetrieveExemption:assert "<<ccr:" not in tool_msg["content"]assert "router:excluded:ccr_retrieve" in result.transforms_applied+ def test_server_tool_mcp_name_not_recompressed(self):+ """OpenCode's <server>_<tool> name must resolve to the excluded tool."""+ 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