context-compress 2026.3.22 → 2026.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.claude-plugin/marketplace.json +17 -0
  2. package/.claude-plugin/plugin.json +12 -0
  3. package/.codex-plugin/plugin.json +40 -0
  4. package/.mcp.json +11 -0
  5. package/README.md +275 -44
  6. package/dist/cli/doctor.d.ts.map +1 -1
  7. package/dist/cli/doctor.js +2 -10
  8. package/dist/cli/doctor.js.map +1 -1
  9. package/dist/cli/filter.d.ts +52 -0
  10. package/dist/cli/filter.d.ts.map +1 -0
  11. package/dist/cli/filter.js +200 -0
  12. package/dist/cli/filter.js.map +1 -0
  13. package/dist/cli/index.d.ts +8 -4
  14. package/dist/cli/index.d.ts.map +1 -1
  15. package/dist/cli/index.js +19 -6
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/cli/lite.d.ts +15 -0
  18. package/dist/cli/lite.d.ts.map +1 -0
  19. package/dist/cli/lite.js +37 -0
  20. package/dist/cli/lite.js.map +1 -0
  21. package/dist/cli/setup.d.ts +23 -1
  22. package/dist/cli/setup.d.ts.map +1 -1
  23. package/dist/cli/setup.js +122 -21
  24. package/dist/cli/setup.js.map +1 -1
  25. package/dist/executor.d.ts.map +1 -1
  26. package/dist/executor.js +7 -4
  27. package/dist/executor.js.map +1 -1
  28. package/dist/filters.d.ts +39 -5
  29. package/dist/filters.d.ts.map +1 -1
  30. package/dist/filters.js +577 -25
  31. package/dist/filters.js.map +1 -1
  32. package/dist/hooks/pretooluse.js +57 -0
  33. package/dist/hooks/pretooluse.js.map +1 -1
  34. package/dist/network.d.ts.map +1 -1
  35. package/dist/network.js +11 -0
  36. package/dist/network.js.map +1 -1
  37. package/dist/server.bundle.mjs +1140 -641
  38. package/dist/server.bundle.mjs.map +4 -4
  39. package/dist/server.d.ts.map +1 -1
  40. package/dist/server.js +36 -612
  41. package/dist/server.js.map +1 -1
  42. package/dist/stats.js +1 -1
  43. package/dist/stats.js.map +1 -1
  44. package/dist/store.d.ts +1 -0
  45. package/dist/store.d.ts.map +1 -1
  46. package/dist/store.js +15 -2
  47. package/dist/store.js.map +1 -1
  48. package/dist/tools/batch-execute.d.ts +4 -0
  49. package/dist/tools/batch-execute.d.ts.map +1 -0
  50. package/dist/tools/batch-execute.js +75 -0
  51. package/dist/tools/batch-execute.js.map +1 -0
  52. package/dist/tools/context.d.ts +17 -0
  53. package/dist/tools/context.d.ts.map +1 -0
  54. package/dist/tools/context.js +2 -0
  55. package/dist/tools/context.js.map +1 -0
  56. package/dist/tools/discover.d.ts +4 -0
  57. package/dist/tools/discover.d.ts.map +1 -0
  58. package/dist/tools/discover.js +65 -0
  59. package/dist/tools/discover.js.map +1 -0
  60. package/dist/tools/execute-file.d.ts +4 -0
  61. package/dist/tools/execute-file.d.ts.map +1 -0
  62. package/dist/tools/execute-file.js +66 -0
  63. package/dist/tools/execute-file.js.map +1 -0
  64. package/dist/tools/execute.d.ts +4 -0
  65. package/dist/tools/execute.d.ts.map +1 -0
  66. package/dist/tools/execute.js +54 -0
  67. package/dist/tools/execute.js.map +1 -0
  68. package/dist/tools/fetch-and-index.d.ts +4 -0
  69. package/dist/tools/fetch-and-index.d.ts.map +1 -0
  70. package/dist/tools/fetch-and-index.js +91 -0
  71. package/dist/tools/fetch-and-index.js.map +1 -0
  72. package/dist/tools/index-content.d.ts +4 -0
  73. package/dist/tools/index-content.d.ts.map +1 -0
  74. package/dist/tools/index-content.js +85 -0
  75. package/dist/tools/index-content.js.map +1 -0
  76. package/dist/tools/search.d.ts +4 -0
  77. package/dist/tools/search.d.ts.map +1 -0
  78. package/dist/tools/search.js +57 -0
  79. package/dist/tools/search.js.map +1 -0
  80. package/dist/tools/stats.d.ts +4 -0
  81. package/dist/tools/stats.d.ts.map +1 -0
  82. package/dist/tools/stats.js +10 -0
  83. package/dist/tools/stats.js.map +1 -0
  84. package/dist/types.d.ts +0 -1
  85. package/dist/types.d.ts.map +1 -1
  86. package/dist/util/auto-mode.d.ts +40 -0
  87. package/dist/util/auto-mode.d.ts.map +1 -0
  88. package/dist/util/auto-mode.js +181 -0
  89. package/dist/util/auto-mode.js.map +1 -0
  90. package/dist/util/fetch-code.d.ts +10 -0
  91. package/dist/util/fetch-code.d.ts.map +1 -0
  92. package/dist/util/fetch-code.js +87 -0
  93. package/dist/util/fetch-code.js.map +1 -0
  94. package/dist/util/intent-filter.d.ts +17 -0
  95. package/dist/util/intent-filter.d.ts.map +1 -0
  96. package/dist/util/intent-filter.js +28 -0
  97. package/dist/util/intent-filter.js.map +1 -0
  98. package/dist/util/label.d.ts +4 -0
  99. package/dist/util/label.d.ts.map +1 -0
  100. package/dist/util/label.js +14 -0
  101. package/dist/util/label.js.map +1 -0
  102. package/dist/util/path.d.ts +8 -0
  103. package/dist/util/path.d.ts.map +1 -0
  104. package/dist/util/path.js +21 -0
  105. package/dist/util/path.js.map +1 -0
  106. package/dist/util/stream-compress.d.ts +36 -0
  107. package/dist/util/stream-compress.d.ts.map +1 -0
  108. package/dist/util/stream-compress.js +104 -0
  109. package/dist/util/stream-compress.js.map +1 -0
  110. package/dist/util/version.d.ts +2 -0
  111. package/dist/util/version.d.ts.map +1 -0
  112. package/dist/util/version.js +15 -0
  113. package/dist/util/version.js.map +1 -0
  114. package/docs/agentic-benchmark.md +110 -0
  115. package/docs/token-reduction-report.md +47 -18
  116. package/hooks/claude-codex-hooks.json +19 -0
  117. package/hooks/pretooluse.mjs +38 -0
  118. package/package.json +12 -8
  119. package/skills/context-compress-audit/SKILL.md +49 -0
  120. package/skills/context-compress-audit/agents/openai.yaml +13 -0
@@ -0,0 +1,17 @@
1
+ {
2
+ "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
3
+ "name": "context-compress",
4
+ "description": "MCP server and hook toolkit that keeps large tool output searchable instead of dumping it into context.",
5
+ "owner": {
6
+ "name": "Open330",
7
+ "url": "https://github.com/Open330"
8
+ },
9
+ "plugins": [
10
+ {
11
+ "name": "context-compress",
12
+ "description": "Compress Bash, Read, WebFetch, logs, tests, and API output before it reaches the context window.",
13
+ "source": "./",
14
+ "category": "productivity"
15
+ }
16
+ ]
17
+ }
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "context-compress",
3
+ "version": "2026.6.0",
4
+ "description": "Keep large tool output searchable without flooding the agent context window.",
5
+ "author": {
6
+ "name": "Open330",
7
+ "url": "https://github.com/Open330"
8
+ },
9
+ "skills": "./skills/",
10
+ "hooks": "./hooks/claude-codex-hooks.json",
11
+ "mcpServers": "./.mcp.json"
12
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "context-compress",
3
+ "version": "2026.6.0",
4
+ "description": "Keep large tool output searchable without flooding the agent context window.",
5
+ "author": {
6
+ "name": "Open330",
7
+ "url": "https://github.com/Open330"
8
+ },
9
+ "homepage": "https://github.com/Open330/context-compress",
10
+ "repository": "https://github.com/Open330/context-compress",
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "mcp",
14
+ "claude-code",
15
+ "context-window",
16
+ "token-optimization",
17
+ "developer-tools"
18
+ ],
19
+ "skills": "./skills/",
20
+ "mcpServers": "./.mcp.json",
21
+ "interface": {
22
+ "displayName": "Context Compress",
23
+ "shortDescription": "Compress tool output before it enters context.",
24
+ "longDescription": "Run commands, fetch pages, index large outputs, and search the retained data through an MCP server so agents see concise answers instead of raw logs.",
25
+ "developerName": "Open330",
26
+ "category": "Productivity",
27
+ "capabilities": [
28
+ "MCP",
29
+ "Skills",
30
+ "Token optimization"
31
+ ],
32
+ "websiteURL": "https://github.com/Open330/context-compress",
33
+ "brandColor": "#2563EB",
34
+ "defaultPrompt": [
35
+ "Run tests through context-compress and summarize failures.",
36
+ "Index this large output and search it for root causes.",
37
+ "Audit this session for raw tool output waste."
38
+ ]
39
+ }
40
+ }
package/.mcp.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "mcpServers": {
3
+ "context-compress": {
4
+ "cwd": ".",
5
+ "command": "node",
6
+ "args": [
7
+ "./dist/index.js"
8
+ ]
9
+ }
10
+ }
11
+ }
package/README.md CHANGED
@@ -2,22 +2,76 @@
2
2
 
3
3
  # context-compress
4
4
 
5
- **Keep your context window lean. Let the sandbox do the heavy lifting.**
5
+ **Stop drowning your AI agent in shell output.**
6
+ Large tool output stays searchable — not stuffed into the context window.
7
+ Use it through an MCP server, a drop-in CLI, agent plugins, or all three.
6
8
 
7
- [![CI](https://github.com/Open330/context-compress/actions/workflows/ci.yml/badge.svg)](https://github.com/Open330/context-compress/actions)
8
- [![Node.js](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
9
+ [![CI](https://github.com/Open330/context-compress/actions/workflows/ci.yml/badge.svg)](https://github.com/Open330/context-compress/actions/workflows/ci.yml)
10
+ [![npm version](https://img.shields.io/npm/v/context-compress?color=cb3837&logo=npm)](https://www.npmjs.com/package/context-compress)
11
+ [![Node.js](https://img.shields.io/badge/node-%E2%89%A518-brightgreen?logo=nodedotjs&logoColor=white)](https://nodejs.org)
9
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
10
13
  [![TypeScript](https://img.shields.io/badge/TypeScript-strict-3178C6?logo=typescript&logoColor=white)](tsconfig.json)
14
+ [![Tests](https://img.shields.io/badge/tests-unit%20%2B%20integration-success)](#contributing)
11
15
 
12
- A context-aware **MCP server** for [Claude Code](https://claude.ai/claude-code) that compresses tool output by processing it in isolated subprocesses. Raw data stays in the sandbox — only concise summaries enter your context window.
13
-
14
- [Quickstart for Agents](#quickstart-for-agents) · [Getting Started](#getting-started) · [How It Works](#how-it-works) · [Token Reduction](#token-reduction) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
16
+ [Quickstart](#quickstart) · [Plugin Support](#plugin-support) · [Compression Modes](#compression-modes) · [vs RTK](#head-to-head-with-rtk) · [How It Works](#how-it-works) · [Configuration](#configuration) · [CLI](#cli) · [Changelog](CHANGELOG.md)
15
17
 
16
18
  </div>
17
19
 
20
+ <table align="center">
21
+ <tr>
22
+ <td align="center" width="25%">
23
+
24
+ **93%**
25
+ <br>token reduction
26
+ <br><sub>aggressive mode</sub>
27
+
28
+ </td>
29
+ <td align="center" width="25%">
30
+
31
+ **Searchable**
32
+ <br>raw data retained
33
+ <br><sub>FTS5 + BM25</sub>
34
+
35
+ </td>
36
+ <td align="center" width="25%">
37
+
38
+ **4 modes**
39
+ <br>incl. LLM-judged
40
+ <br><sub>auto • aggressive • balanced • conservative</sub>
41
+
42
+ </td>
43
+ <td align="center" width="25%">
44
+
45
+ **Plugins**
46
+ <br>Codex + Claude
47
+ <br><sub>MCP • hooks • skills</sub>
48
+
49
+ </td>
50
+ </tr>
51
+ </table>
52
+
18
53
  ---
19
54
 
20
- ## Quickstart for Agents
55
+ ## Quickstart
56
+
57
+ ```bash
58
+ # 1. Install
59
+ npm install -g context-compress
60
+
61
+ # 2. One-line setup — registers the MCP server, installs the hook,
62
+ # enables transparent Bash compression
63
+ context-compress setup --auto
64
+
65
+ # 3. (optional) Pick a mode for the session
66
+ export CONTEXT_COMPRESS_MODE=balanced # or: aggressive, conservative, auto
67
+ ```
68
+
69
+ That's it. Restart Claude Code and shell output is now compressed before it enters context.
70
+
71
+ > **Prefer no MCP at all?** `context-compress wrap "<cmd>"` compresses any shell command's output — drop-in for [RTK](https://github.com/rtk-ai/rtk). See [CLI](#cli).
72
+
73
+ <details>
74
+ <summary><b>Quickstart for AI agents</b> — paste this prompt and your agent will install it</summary>
21
75
 
22
76
  <div><img src="https://quickstart-for-agents.vercel.app/api/header.svg?theme=claude-code&title=context-compress&lang=Agents&mascot=thinking" width="100%" /></div>
23
77
 
@@ -27,7 +81,7 @@ Raw data stays in sandboxed subprocesses, only concise summaries enter your cont
27
81
  Saves ~99% of tokens on large outputs while keeping everything searchable via FTS5.
28
82
 
29
83
  npm install -g context-compress
30
- claude mcp add context-compress -- node $(which context-compress)
84
+ context-compress setup --auto
31
85
  context-compress doctor
32
86
 
33
87
  More info: https://github.com/Open330/context-compress
@@ -35,6 +89,8 @@ More info: https://github.com/Open330/context-compress
35
89
 
36
90
  <div><img src="https://quickstart-for-agents.vercel.app/api/footer.svg?theme=claude-code&project=context-compress" width="100%" /></div>
37
91
 
92
+ </details>
93
+
38
94
  ---
39
95
 
40
96
  ## Why?
@@ -49,6 +105,11 @@ Before: git log --oneline -100 → 8.2KB into context
49
105
  After: execute("git log ...") → 0.3KB summary + full data searchable in FTS5
50
106
  ```
51
107
 
108
+ It works in two modes that compose freely:
109
+
110
+ - **MCP server** — registers as a Claude Code MCP server with 8 tools (`execute`, `search`, `batch_execute`, `fetch_and_index`, `index`, `execute_file`, `stats`, `discover`). Agents call them directly when output would be large.
111
+ - **Standalone CLI** — `context-compress wrap "<cmd>"` runs any shell command and pipes the output through the same compression pipeline. Drop-in for [RTK](https://github.com/rtk-ai/rtk) and friends. The PreToolUse hook can route `Bash` calls through it transparently when `CONTEXT_COMPRESS_FILTER_BASH=1`.
112
+
52
113
  > Based on [context-mode](https://github.com/mksglu/claude-context-mode) by Mert Koseoğlu — rewritten in TypeScript with security hardening, architectural improvements, and better DX.
53
114
 
54
115
  ---
@@ -61,7 +122,27 @@ After: execute("git log ...") → 0.3KB summary + full data searchable in FT
61
122
  npm install -g context-compress
62
123
  ```
63
124
 
64
- ### Add to Claude Code
125
+ ### Plugin Support
126
+
127
+ context-compress now ships plugin metadata for agent hosts:
128
+
129
+ | Host | Files | What they enable |
130
+ |:--|:--|:--|
131
+ | **Codex** | `.codex-plugin/plugin.json`, `.mcp.json`, `skills/` | MCP server registration plus skills in plugin-aware Codex flows. |
132
+ | **Claude Code** | `.claude-plugin/plugin.json`, `.claude-plugin/marketplace.json`, `hooks/claude-codex-hooks.json` | PreToolUse routing, skills, and MCP config from a plugin install. |
133
+ | **Manual / fallback** | `context-compress setup --auto` | Writes `~/.claude/settings.json` directly when plugin installation is not available. |
134
+
135
+ The plugin manifests are designed for built package/archive installs where `dist/`, `hooks/`, and `skills/` are present together. For a raw source checkout, run `npm install && npm run build` before testing the plugin locally, or use the global npm setup above.
136
+
137
+ ### One-line setup
138
+
139
+ ```bash
140
+ context-compress setup --auto
141
+ ```
142
+
143
+ Writes `~/.claude/settings.json` for you: registers the MCP server, installs the PreToolUse hook, enables transparent Bash compression. Idempotent — re-running with the same paths makes zero changes. Preserves any unrelated user settings.
144
+
145
+ ### Manual setup
65
146
 
66
147
  ```bash
67
148
  claude mcp add context-compress -- node $(which context-compress)
@@ -115,7 +196,7 @@ context-compress doctor
115
196
  └─────────────────────────────────────────────────────────┘
116
197
  ```
117
198
 
118
- ### 7 MCP Tools
199
+ ### 8 MCP Tools
119
200
 
120
201
  | Tool | What it does |
121
202
  |:-----|:-------------|
@@ -125,7 +206,8 @@ context-compress doctor
125
206
  | **`search`** | BM25 search with Porter stemming → trigram → fuzzy fallback. |
126
207
  | **`fetch_and_index`** | Fetch URL → HTML-to-markdown → auto-index. Preview only in context. |
127
208
  | **`batch_execute`** | Run N commands + search in ONE call. Replaces 30+ tool calls. |
128
- | **`stats`** | Real-time session statistics: bytes saved, tokens avoided, savings ratio. |
209
+ | **`stats`** | Session + cumulative statistics: bytes saved, tokens avoided, savings ratio. |
210
+ | **`discover`** | Lists indexed sources, top searchable terms, and suggests next actions. |
129
211
 
130
212
  ### Supported Languages
131
213
 
@@ -135,6 +217,68 @@ context-compress doctor
135
217
 
136
218
  ---
137
219
 
220
+ ## Compression Modes
221
+
222
+ context-compress offers four compression modes that trade fidelity for compactness. Pass `--mode` to the CLI, set `CONTEXT_COMPRESS_MODE` in your environment, or let the default (`balanced`) just work.
223
+
224
+ | Mode | Strategy | Use when |
225
+ |:--|:--|:--|
226
+ | `conservative` | ANSI strip only — preserves every byte of meaningful content | You need full fidelity, debugging output, archival logs |
227
+ | `balanced` *(default)* | Strip noise (progress bars, deprecation warnings, hint lines) — keep metadata (commit bodies, file dates, full test failures) | Day-to-day agent work where context might be re-read |
228
+ | `aggressive` | Drop metadata too — git log → oneline, ls -la → name+size, find lower threshold, grep grouped | Maximum token savings; agent will rarely need the dropped detail |
229
+ | `auto` | An LLM (Anthropic API or `claude -p`) picks one of the above per command, based on a 500-byte sample of the output. Decisions cached for 24h | You don't want to think about it — let the model judge per output |
230
+
231
+ ```bash
232
+ # CLI flag (per-call override)
233
+ context-compress wrap --mode aggressive "git log -50"
234
+
235
+ # Env var (set once for the session)
236
+ export CONTEXT_COMPRESS_MODE=aggressive
237
+ ```
238
+
239
+ The PreToolUse hook also forwards `CONTEXT_COMPRESS_MODE` automatically when wrapping Bash commands, so agents transparently get whatever mode you've configured.
240
+
241
+ ### Head-to-head with [RTK](https://github.com/rtk-ai/rtk)
242
+
243
+ Reproduce locally:
244
+
245
+ ```bash
246
+ git clone https://github.com/rtk-ai/rtk /tmp/rtk && (cd /tmp/rtk && cargo build --release)
247
+ RTK_BIN=/tmp/rtk/target/release/rtk tsx scripts/benchmark-vs-rtk.ts
248
+ ```
249
+
250
+ Result on this repository (RTK 0.39.0 vs context-compress 2026.5.0):
251
+
252
+ | Command | Raw | RTK | CC `conservative` | CC `balanced` | CC `aggressive` | CC `auto` (LLM) |
253
+ |:--|--:|--:|--:|--:|--:|--:|
254
+ | `git status` | 577 B | 241 B (58%) | 577 B (0%) | 375 B (35%) | **187 B (68%)** | balanced (35%) |
255
+ | `git log -10` (full) | 21.3 KB | 3.2 KB (85%) | 21.3 KB (0%) | 4.6 KB (79%) | **947 B (96%)** | balanced (79%) |
256
+ | `git log -50` (full) | 36.9 KB | 10.1 KB (73%) | 36.9 KB (0%) | 12.3 KB (67%) | **3.2 KB (91%)** | balanced (67%) |
257
+ | `git diff --stat` | 425 B | 424 B (0%) | 425 B (0%) | 425 B (0%) | 425 B (0%) | balanced (0%) |
258
+ | `ls src/` | 149 B | 229 B (-54%) | 149 B (0%) | 149 B (0%) | 149 B (0%) | conservative (0%) |
259
+ | `ls -laR src/` | 3.8 KB | **229 B (94%)** | 3.8 KB (0%) | 3.1 KB (19%) | 877 B (78%) | aggressive (78%) |
260
+ | `find *.ts` | 1.0 KB | 589 B (44%) | 1.0 KB (0%) | **183 B (83%)** | **183 B (83%)** | aggressive (83%) |
261
+ | `npm test` | 21.8 KB | 114 B (99%) | 16.7 KB (24%) | **120 B (99%)** | **120 B (99%)** | balanced (99%) |
262
+ | **Overall** (byte-weighted) | **85.9 KB** | 15.0 KB (82.5%) | 80.8 KB (6.0%) | 21.2 KB (75.4%) | **6.0 KB (93.0%)** | 19.0 KB (77.9%) |
263
+
264
+ Three things to take from this table:
265
+
266
+ 1. **`balanced` is competitive on its own.** The default mode hits ~75% reduction without dropping any metadata — agents get full commit headers, file perms/dates, and complete test failure detail. Only 7pp behind RTK while making a different fidelity trade-off.
267
+ 2. **`aggressive` decisively wins on raw compression** — 93.0%, beating RTK by 10.5pp. Pick this when you want maximum token savings and the agent will rarely re-read the dropped detail.
268
+ 3. **`auto` lets the model pick.** Per-command LLM judgment landed at 77.9% overall — between balanced and aggressive. The interesting result is *what* it picked: `balanced` for git/test outputs (where commit bodies and failure detail matter), `aggressive` for `ls -laR` and `find` (where the question is "what's there?", not "show me everything"), `conservative` for tiny outputs where compression is pointless.
269
+
270
+ Aggressive mode covers a wider command surface than the table above hints — it also handles `df` (drops pseudo-filesystems), `du` (top-N by size), `ps aux` (PID/%CPU/%MEM/CMD only, drops kernel threads), `npm ls` (strips tree-drawing chars + `deduped`/`extraneous` markers), and `grep`/`rg` (groups by file, truncates long lines).
271
+
272
+ What balanced now does (over conservative):
273
+ - `ls -l*` drops `total N`, `.`/`..` entries (universal noise) but keeps perms/dates
274
+ - `git log` keeps headers + first 3 body lines per commit, replacing the rest with `[+N lines omitted]`
275
+ - `find` / `ls -R` summarizes per-directory once output exceeds 20 entries
276
+ - Generic dedup/progress/group runs at 5KB instead of 10KB
277
+
278
+ > RTK has a single fixed compression strategy — comparable to context-compress `aggressive`. context-compress lets the agent choose: reach for `aggressive` when the question is "what changed", `balanced` when the question is "explain why".
279
+
280
+ ---
281
+
138
282
  ## Token Reduction
139
283
 
140
284
  context-compress achieves **99.2% token reduction** across a typical 12-operation coding session.
@@ -159,6 +303,8 @@ Without context-compress, 12 operations consume **133% of the 200K context windo
159
303
 
160
304
  **[Read the full Token Reduction Report](docs/token-reduction-report.md)** — includes cost analysis, architecture deep-dive, and FAQ on context loss trade-offs.
161
305
 
306
+ **[Read the Agentic Benchmark Plan](docs/agentic-benchmark.md)** — defines the fair on/off benchmark for real Claude Code sessions, including baseline isolation, task success checks, and reporting limits.
307
+
162
308
  ---
163
309
 
164
310
  ## What Changed from context-mode
@@ -200,6 +346,18 @@ CONTEXT_COMPRESS_BLOCK_WEBFETCH=0
200
346
  # Disable Read/Grep nudges
201
347
  CONTEXT_COMPRESS_NUDGE_READ=0
202
348
  CONTEXT_COMPRESS_NUDGE_GREP=0
349
+
350
+ # Compression mode: conservative | balanced (default) | aggressive | auto
351
+ CONTEXT_COMPRESS_MODE=balanced
352
+
353
+ # Auto mode prefers the Anthropic API when ANTHROPIC_API_KEY is set
354
+ # in your shell or secret manager (faster than `claude -p` fallback)
355
+
356
+ # RTK-style transparent Bash wrapping (default: off)
357
+ CONTEXT_COMPRESS_FILTER_BASH=1
358
+
359
+ # Override path to the context-compress binary used by the hook
360
+ CONTEXT_COMPRESS_BIN=/usr/local/bin/context-compress
203
361
  ```
204
362
 
205
363
  ### Config File
@@ -220,12 +378,24 @@ Create `.context-compress.json` in your project root or home directory:
220
378
  ## CLI
221
379
 
222
380
  ```bash
223
- context-compress # Start MCP server (stdio)
224
- context-compress setup # Detect runtimes, show install instructions
225
- context-compress doctor # Diagnose: runtimes, hooks, FTS5, version
226
- context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
381
+ context-compress # Start MCP server (stdio)
382
+ context-compress setup # Detect runtimes, show install instructions
383
+ context-compress setup --auto # One-line: write ~/.claude/settings.json
384
+ context-compress init --auto # Alias for setup --auto
385
+ context-compress doctor # Diagnose: runtimes, hooks, FTS5, version
386
+ context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
387
+
388
+ # RTK-style transparent compression — use anywhere, agent doesn't need MCP
389
+ context-compress wrap "npm test" # default = balanced
390
+ context-compress wrap --mode aggressive "git log -50" # max compression
391
+ context-compress wrap --stream "tail -f /var/log/app.log" # line-by-line for long-running cmds
392
+ context-compress filter --cmd "git push" < captured.log # pipe filter
227
393
  ```
228
394
 
395
+ ### Bash auto-wrap (transparent mode)
396
+
397
+ Set `CONTEXT_COMPRESS_FILTER_BASH=1` and the PreToolUse hook will route output-heavy `Bash` calls through `context-compress wrap` automatically — the agent doesn't need to call `execute()` to benefit. Combine with `CONTEXT_COMPRESS_MODE=aggressive` for maximum compression.
398
+
229
399
  ### Doctor Output Example
230
400
 
231
401
  ```
@@ -235,9 +405,10 @@ context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
235
405
  [PASS] Language coverage: 7/11 (64%)
236
406
  [PASS] Server test: OK
237
407
  [PASS] PreToolUse hook configured
408
+ [PASS] Hook integrity: SHA-256 verified (a3f1c8d2e4...)
238
409
  [PASS] FTS5 / better-sqlite3 works
239
410
 
240
- Version: v2026.3.3
411
+ Version: v2026.5.0
241
412
  All checks passed.
242
413
  ```
243
414
 
@@ -248,46 +419,79 @@ context-compress uninstall # Clean removal: hooks, MCP reg, stale DBs
248
419
  ```
249
420
  context-compress/
250
421
  ├── src/
251
- │ ├── index.ts # Entry point
252
- │ ├── server.ts # MCP server (7 tools)
253
- │ ├── executor.ts # SubprocessExecutor
254
- │ ├── store.ts # ContentStore (FTS5)
255
- │ ├── config.ts # Config system
256
- │ ├── logger.ts # Debug logger
422
+ │ ├── index.ts # MCP server entry
423
+ │ ├── server.ts # Wires deps, registers tools (132 lines, was 845)
424
+ │ ├── executor.ts # SubprocessExecutor + ANSI/dedup pipeline
425
+ │ ├── filters.ts # Command-aware filters (git, npm, ls, find, ps, ...)
426
+ │ ├── store.ts # ContentStore (FTS5 + BM25 + Porter + trigram + Levenshtein)
427
+ │ ├── network.ts # SSRF / DNS rebinding protection
428
+ │ ├── stats.ts # Session + cumulative session tracker
429
+ │ ├── config.ts # Config: ENV → file → defaults
257
430
  │ ├── snippet.ts # FTS5 snippet extraction
258
- │ ├── stats.ts # Session tracker
431
+ │ ├── logger.ts # Debug logger
259
432
  │ ├── types.ts # Shared types
433
+ │ ├── utils.ts # detectInjectionPatterns, limitConcurrency, formatBytes
260
434
  │ ├── runtime/
435
+ │ │ ├── index.ts # Parallel runtime detection + registry
261
436
  │ │ ├── plugin.ts # LanguagePlugin interface
262
- │ │ ├── index.ts # Registry + parallel detection
263
- │ └── languages/ # 11 language plugins
437
+ │ │ └── languages/ # 11 language plugins (js, ts, py, sh, rb, go, rs, php, pl, r, ex)
438
+ ├── tools/ # MCP tool handlers (one file per tool)
439
+ │ │ ├── context.ts # Shared ToolContext interface
440
+ │ │ ├── execute.ts
441
+ │ │ ├── execute-file.ts
442
+ │ │ ├── index-content.ts
443
+ │ │ ├── search.ts
444
+ │ │ ├── fetch-and-index.ts
445
+ │ │ ├── batch-execute.ts
446
+ │ │ ├── stats.ts
447
+ │ │ └── discover.ts
448
+ │ ├── util/ # Pure utilities (extracted from server.ts for testability)
449
+ │ │ ├── path.ts # isWithinProject (path-traversal safe)
450
+ │ │ ├── fetch-code.ts # buildFetchCode (HTML→md sandbox script)
451
+ │ │ ├── intent-filter.ts # createIntentFilter factory
452
+ │ │ ├── label.ts # compactLabel (compression levels)
453
+ │ │ ├── version.ts # getVersion (deduped across CLI commands)
454
+ │ │ ├── stream-compress.ts# Line-by-line StreamCompressor for `wrap --stream`
455
+ │ │ └── auto-mode.ts # LLM-driven mode selection (Anthropic API + claude CLI)
264
456
  │ ├── hooks/
265
- │ │ └── pretooluse.ts # PreToolUse hook (no self-mod)
457
+ │ │ └── pretooluse.ts # PreToolUse hook (curl/Bash/Read/Grep/WebFetch/Task)
266
458
  │ └── cli/
267
- │ ├── index.ts # CLI entry
268
- │ ├── setup.ts # Interactive setup
269
- │ ├── doctor.ts # Diagnostics
270
- └── uninstall.ts # Clean removal
459
+ │ ├── index.ts # CLI dispatcher
460
+ │ ├── lite.ts # Single-binary entry (filter+wrap only, no MCP)
461
+ │ ├── filter.ts # `filter` (stdin) + `wrap` (spawn) commands
462
+ ├── setup.ts # `setup` / `init` — interactive + --auto
463
+ │ ├── doctor.ts # `doctor` — diagnostics
464
+ │ └── uninstall.ts # `uninstall` — clean removal
271
465
  ├── tests/
272
- │ ├── unit/ # 7 unit test files
466
+ │ ├── unit/ # 18 unit test files
273
467
  │ └── integration/ # 3 integration test files
274
- ├── hooks/
275
- └── hooks.json # Hook matcher config
468
+ ├── scripts/
469
+ ├── benchmark.ts # Synthetic compression benchmark
470
+ │ ├── benchmark-real.ts # Real-command benchmark on this repo
471
+ │ └── benchmark-vs-rtk.ts # Head-to-head vs RTK with --auto support
472
+ ├── hooks/ # Pre-built hook bundle (shipped in npm package)
276
473
  ├── skills/ # Slash command definitions
277
- └── dist/ # Compiled output
474
+ ├── docs/ # Token reduction report + architecture docs
475
+ └── dist/ # Compiled output (build artifact)
278
476
  ```
279
477
 
478
+ > `server.ts` is now thin (132 lines) — it constructs deps, builds a `ToolContext`, registers the 8 tool modules, and wires shutdown. All tool handlers live under `src/tools/`, all reusable helpers under `src/util/`.
479
+
280
480
  ---
281
481
 
282
482
  ## Security
283
483
 
284
484
  | Threat | Mitigation |
285
485
  |:-------|:-----------|
286
- | Credential leakage | `passthroughEnvVars` defaults to `[]` — zero env vars passed unless opted in |
287
- | Shell injection (Rust) | `execFileSync` with array arguments — no string interpolation |
288
- | Hook self-modification | No `fs.writeFileSync` in hooks zero filesystem side effects |
289
- | Arbitrary code execution | No `upgrade` command no `git clone` or `npm install` at runtime |
290
- | Silent failures | Debug mode surfaces all catch block errors to stderr |
486
+ | Credential leakage | `passthroughEnvVars` defaults to `[]` — zero env vars passed to subprocesses unless opted in |
487
+ | Shell injection | `execFileSync` with array arguments throughout — no string interpolation into shells |
488
+ | SSRF / private-IP fetch | `fetch_and_index` blocks RFC1918, link-local, loopback, IPv4-mapped IPv6 (incl. hex form `::ffff:HHHH:HHHH`), CGNAT |
489
+ | DNS rebinding (TOCTOU) | `resolveAndValidate` + URL pinning to the resolved IP with original `Host` header preserved |
490
+ | Path traversal | `isWithinProject` uses `realpathSync` to defeat symlink escapes; falls back to string-prefix for not-yet-existing paths |
491
+ | Hook self-modification | Hooks are read-only — no `fs.writeFileSync` in `src/hooks/`. Hook integrity SHA-256 verified by `doctor` |
492
+ | Arbitrary code execution | No `upgrade` command — no `git clone` or `npm install` at runtime. Setup writes only to `~/.claude/settings.json` |
493
+ | Silent failures | `CONTEXT_COMPRESS_DEBUG=1` surfaces all catch-block errors to stderr |
494
+ | Subprocess sandboxing | OS-level sandboxing not enforced (by design for the MCP trust model). See [SECURITY.md](SECURITY.md) for the full trust model. |
291
495
 
292
496
  ---
293
497
 
@@ -297,15 +501,42 @@ context-compress/
297
501
  git clone https://github.com/Open330/context-compress
298
502
  cd context-compress
299
503
  npm install
300
- npm run typecheck # Type checking
301
- npm run lint # Biome linting
302
- npm run test:unit # Unit tests
303
- npm run test # All tests (unit + integration)
304
- npm run build # Compile + bundle
504
+
505
+ npm run typecheck # Strict TS
506
+ npm run lint # Biome
507
+ npm test # All tests (unit + integration)
508
+ npm run test:unit # Unit tests only
509
+
510
+ npm run build # Compile + bundle MCP server + CLI
511
+ npm run build:hooks # Bundle the PreToolUse hook (with SHA-256)
512
+ npm run build:bin # Cross-compile single binaries via Bun (4 targets)
305
513
  ```
306
514
 
515
+ ### Reproducing the benchmarks
516
+
517
+ ```bash
518
+ # Synthetic — fast, reproducible, includes RTK-style commands
519
+ tsx scripts/benchmark.ts
520
+
521
+ # Real-world — runs actual commands in your repo
522
+ tsx scripts/benchmark-real.ts # full
523
+ tsx scripts/benchmark-real.ts --quick # skip npm test
524
+
525
+ # Head-to-head with RTK (build it first)
526
+ git clone https://github.com/rtk-ai/rtk /tmp/rtk
527
+ (cd /tmp/rtk && cargo build --release)
528
+
529
+ RTK_BIN=/tmp/rtk/target/release/rtk tsx scripts/benchmark-vs-rtk.ts
530
+ RTK_BIN=... tsx scripts/benchmark-vs-rtk.ts --auto # also run LLM-judged auto mode
531
+ RTK_BIN=... tsx scripts/benchmark-vs-rtk.ts --json # machine-readable
532
+ ```
533
+
534
+ For real agent sessions, use [docs/agentic-benchmark.md](docs/agentic-benchmark.md) to compare baseline, MCP-only, hook-balanced, and hook-aggressive arms with isolated settings.
535
+
307
536
  ---
308
537
 
309
538
  ## License
310
539
 
311
540
  [MIT](LICENSE) — Based on [context-mode](https://github.com/mksglu/claude-context-mode) by Mert Koseoğlu.
541
+
542
+ > **Inspired by [RTK](https://github.com/rtk-ai/rtk)** for the command-aware filtering tactic. context-compress builds on the same idea with multi-mode trade-offs, an LLM-judged `auto` mode, MCP integration, sandbox execution, and a searchable knowledge base.
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AA8BA,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAiI9C"}
1
+ {"version":3,"file":"doctor.d.ts","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAsBA,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAiI9C"}
@@ -7,16 +7,8 @@ import Database from "better-sqlite3";
7
7
  import { loadConfig } from "../config.js";
8
8
  import { SubprocessExecutor } from "../executor.js";
9
9
  import { detectRuntimes, getRuntimeSummary, hasBun } from "../runtime/index.js";
10
+ import { getVersion } from "../util/version.js";
10
11
  const __dirname = dirname(fileURLToPath(import.meta.url));
11
- function getVersion() {
12
- try {
13
- const pkg = JSON.parse(readFileSync(resolve(__dirname, "..", "..", "package.json"), "utf-8"));
14
- return pkg.version ?? "unknown";
15
- }
16
- catch {
17
- return "unknown";
18
- }
19
- }
20
12
  function readSettings() {
21
13
  try {
22
14
  const path = resolve(homedir(), ".claude", "settings.json");
@@ -138,7 +130,7 @@ export async function doctor() {
138
130
  console.log(` [FAIL] FTS5: ${msg}`);
139
131
  }
140
132
  // 6. Version
141
- const version = getVersion();
133
+ const version = getVersion("unknown");
142
134
  console.log(`\n Version: v${version}`);
143
135
  // Summary
144
136
  console.log();
@@ -1 +1 @@
1
- {"version":3,"file":"doctor.js","sourceRoot":"","sources":["../../src/cli/doctor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAEhF,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D,SAAS,UAAU;IAClB,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QAC9F,OAAO,GAAG,CAAC,OAAO,IAAI,SAAS,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AACF,CAAC;AAED,SAAS,YAAY;IACpB,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,eAAe,CAAC,CAAC;Q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AAG,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,aAAa;IACb,MAAM,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,iBAAiB,OAAO,EAAE,CAAC,CAAC;IAExC,UAAU;IACV,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,KAAK,aAAa,6BAA6B,CAAC,CAAC;QAC7D,OAAO,CAAC,CAAC;IACV,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACtC,OAAO,CAAC,CAAC;AACV,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { type FilterMode, type RequestedMode } from "../filters.js";
2
+ /**
3
+ * Apply the full context-compress output pipeline to a buffer.
4
+ *
5
+ * conservative: ANSI strip only — preserve everything else.
6
+ * balanced: ANSI strip → command filter (drops universal noise:
7
+ * progress bars, hint lines, ./.., 'total N', truncates
8
+ * git log bodies past 3 lines) → dedup/group (if >5KB).
9
+ * Preserves all metadata (perms, dates, commit headers).
10
+ * aggressive: balanced + aggressive command filters that drop metadata
11
+ * (git log → oneline, ls -la → name+size, etc.) and lower
12
+ * the dedup threshold to 2KB.
13
+ *
14
+ * Mirrors what SubprocessExecutor does internally so the same compression
15
+ * is available to standalone shell commands or other agents that don't
16
+ * route through the MCP execute() tool.
17
+ */
18
+ export declare function compressOutput(stdout: string, originalCmd?: string, mode?: FilterMode): string;
19
+ /**
20
+ * Async variant that handles the "auto" meta-mode by asking an LLM to
21
+ * pick conservative/balanced/aggressive for the given command + output.
22
+ * Concrete modes route to the synchronous compressOutput.
23
+ */
24
+ export declare function compressOutputAsync(stdout: string, originalCmd: string | undefined, mode?: RequestedMode): Promise<{
25
+ output: string;
26
+ resolvedMode: FilterMode;
27
+ autoSource?: string;
28
+ }>;
29
+ /**
30
+ * `context-compress filter [--cmd '<orig>'] [--mode conservative|balanced|aggressive|auto]`
31
+ * Reads stdin, applies the pipeline, writes to stdout. Exits 0.
32
+ */
33
+ export declare function runFilter(args: string[]): Promise<number>;
34
+ /**
35
+ * `context-compress wrap [--stream] -- <cmd ...>`
36
+ *
37
+ * Default (buffered): spawn cmd, capture all stdout, apply full pipeline,
38
+ * print filtered stdout, propagate child's exit code.
39
+ *
40
+ * `--stream`: emit filtered output line-by-line as the child produces it.
41
+ * Use for long-running commands (tail -f, cargo watch, builds with
42
+ * progressive output) where buffering would defer all output until exit.
43
+ * Stream mode applies ANSI strip + progress filter + adjacent dedup only —
44
+ * command-aware filters need the full output.
45
+ *
46
+ * Usage:
47
+ * context-compress wrap "npm test"
48
+ * context-compress wrap --stream "tail -f /var/log/app.log"
49
+ * context-compress wrap -- npm test
50
+ */
51
+ export declare function runWrap(args: string[]): Promise<number>;
52
+ //# sourceMappingURL=filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../../src/cli/filter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEN,KAAK,UAAU,EACf,KAAK,aAAa,EAGlB,MAAM,eAAe,CAAC;AAUvB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,EACpB,IAAI,GAAE,UAAyB,GAC7B,MAAM,CAgBR;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CACxC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,IAAI,GAAE,aAA4B,GAChC,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,UAAU,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAU5E;AAoBD;;;GAGG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAc/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CA0C7D"}