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
Auto-register codebase-memory-mcp as MCP server with --code-graph
chopratejas4ee519f2c4ff
diff --git a/headroom/cli/mcp.py b/headroom/cli/mcp.pyindex 79fa8a72b..abdd57a1a 100644--- a/headroom/cli/mcp.py+++ b/headroom/cli/mcp.py@@ -244,13 +244,33 @@ def mcp_uninstall() -> None:err=True,)+ # Also remove codebase-memory-mcp if registered (installed by --code-graph)+ if claude_cli:+ cbm_check = subprocess.run(+ [claude_cli, "mcp", "get", "codebase-memory-mcp"],+ capture_output=True,+ )+ if cbm_check.returncode == 0:+ cbm_rm = subprocess.run(+ [claude_cli, "mcp", "remove", "codebase-memory-mcp", "-s", "user"],+ capture_output=True,+ text=True,+ )+ if cbm_rm.returncode == 0:+ click.echo("✓ codebase-memory-mcp MCP server removed")+ removed = True+# Also remove from mcp.json fallback config if presentif MCP_CONFIG_PATH.exists():config = load_mcp_config()- if "headroom" in config.get("mcpServers", {}):- del config["mcpServers"]["headroom"]+ changed = False+ for server_name in ("headroom", "codebase-memory-mcp"):+ if server_name in config.get("mcpServers", {}):+ del config["mcpServers"][server_name]+ changed = True+ if changed:save_mcp_config(config)- click.echo(f"✓ Headroom MCP server removed from {MCP_CONFIG_PATH}")+ click.echo(f"✓ MCP servers removed from {MCP_CONFIG_PATH}")removed = Trueif not removed:diff --git a/headroom/cli/wrap.py b/headroom/cli/wrap.pyindex a59bb2441..a3e19cb18 100644--- a/headroom/cli/wrap.py+++ b/headroom/cli/wrap.py@@ -192,13 +192,51 @@ def _setup_rtk(verbose: bool = False) -> Path | None:return rtk_path+_CBM_MCP_SERVER_NAME = "codebase-memory-mcp"+++def _register_cbm_mcp_server(cbm_bin: str) -> None:+ """Register codebase-memory-mcp as an MCP server in Claude Code.++ Uses ``claude mcp add`` so the tools appear in ``/mcp`` automatically.+ Idempotent — skips if already registered.+ """+ claude_cli = shutil.which("claude")+ if not claude_cli:+ return++ # Check if already registered+ check = subprocess.run(+ [claude_cli, "mcp", "get", _CBM_MCP_SERVER_NAME],+ capture_output=True,+ text=True,+ )+ if check.returncode == 0:+ return # Already registered++ result = subprocess.run(+ [claude_cli, "mcp", "add", _CBM_MCP_SERVER_NAME, "-s", "user", "--", cbm_bin],+ capture_output=True,+ text=True,+ )+ if result.returncode == 0:+ click.echo(f" Code graph: registered {_CBM_MCP_SERVER_NAME} MCP server")+ else:+ pass # Non-critical — tools won't appear in /mcp but graph still works++def _setup_code_graph(verbose: bool = False) -> bool:- """Ensure codebase-memory-mcp is installed and project is indexed.+ """Ensure codebase-memory-mcp is installed, registered as MCP server, and project is indexed.codebase-memory-mcp builds a knowledge graph of the codebase usingtree-sitter, enabling the LLM to query code structure (call chains,function definitions, impact analysis) instead of reading entire files.+ Steps:+ 1. Download the binary if not already present.+ 2. Register as an MCP server in Claude Code (``claude mcp add``).+ 3. Index the current project (fast, idempotent).+With Claude Code's MCP Tool Search, the 14 graph tools add ~200 tokensoverhead per request (not the full ~1,915) — they're lazy-loaded.@@ -218,6 +256,9 @@ def _setup_code_graph(verbose: bool = False) -> bool:cbm_bin = str(cbm_path)+ # Register as MCP server so tools appear in /mcp+ _register_cbm_mcp_server(cbm_bin)+# Index current project (fast — ~1s for most repos, idempotent)project_dir = str(Path.cwd())try: