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(wrap): overwrite drifted selfheal hook command instead of skipping it (#2723)
rNoz2643f34a542d
diff --git a/tests/test_cli/test_wrap_dead_marker_selfheal.py b/tests/test_cli/test_wrap_dead_marker_selfheal.pyindex 5faf5bc22..8ae20e436 100644--- a/tests/test_cli/test_wrap_dead_marker_selfheal.py+++ b/tests/test_cli/test_wrap_dead_marker_selfheal.py@@ -317,3 +317,74 @@ def test_selfheal_command_preserves_live_marker(tmp_path: Path, monkeypatch) ->def test_selfheal_never_raises_without_settings(tmp_path: Path, monkeypatch) -> None:monkeypatch.chdir(tmp_path)wrap_cli._selfheal_dead_wrap_base_url() # no .claude dir at all — silent no-op+++def test_wrap_selfheal_hook_overwrites_drifted_command(tmp_path: Path) -> None:+ path = _settings(tmp_path)+ path.parent.mkdir(parents=True)+ path.write_text(+ json.dumps(+ {+ "hooks": {+ "SessionStart": [+ {+ "matcher": "startup|resume",+ "hooks": [+ {+ "type": "command",+ "command": f"/usr/bin/claude wrap selfheal --marker {_HOOK_MARKER}",+ "timeout": 10,+ }+ ],+ }+ ]+ }+ }+ ),+ encoding="utf-8",+ newline="\n",+ )++ wrap_cli._ensure_claude_wrap_selfheal_hook(path)++ payload = json.loads(path.read_text(encoding="utf-8"))+ entries = payload["hooks"]["SessionStart"]+ assert len(entries) == 1+ command = entries[0]["hooks"][0]["command"]+ assert "/usr/bin/claude" not in command+ assert "wrap selfheal" in command+ assert _HOOK_MARKER in command+++def test_wrap_selfheal_hook_skips_malformed_sessionstart_entries(tmp_path: Path) -> None:+ path = _settings(tmp_path)+ path.parent.mkdir(parents=True)+ path.write_text(+ json.dumps(+ {+ "hooks": {+ "SessionStart": [+ "not-a-dict",+ {"matcher": "startup", "hooks": "not-a-list"},+ ]+ }+ }+ ),+ encoding="utf-8",+ newline="\n",+ )++ wrap_cli._ensure_claude_wrap_selfheal_hook(path)++ payload = json.loads(path.read_text(encoding="utf-8"))+ entries = payload["hooks"]["SessionStart"]+ assert entries[0] == "not-a-dict"+ assert entries[1] == {"matcher": "startup", "hooks": "not-a-list"}+ marked = [+ entry+ for entry in entries+ if isinstance(entry, dict)+ and isinstance(entry.get("hooks"), list)+ and any(_HOOK_MARKER in h.get("command", "") for h in entry["hooks"])+ ]+ assert len(marked) == 1