kompactor 0.7.6__tar.gz → 0.7.8__tar.gz

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 (45) hide show
  1. kompactor-0.7.8/PKG-INFO +459 -0
  2. kompactor-0.7.8/README.md +426 -0
  3. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/__init__.py +1 -1
  4. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/cli.py +1 -1
  5. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/installer.py +1 -1
  6. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/usage.html +5 -5
  7. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/ui.html +6 -6
  8. kompactor-0.7.8/kompactor.egg-info/PKG-INFO +459 -0
  9. {kompactor-0.7.6 → kompactor-0.7.8}/pyproject.toml +13 -2
  10. {kompactor-0.7.6 → kompactor-0.7.8}/tests/test_kompactor.py +1 -1
  11. kompactor-0.7.6/PKG-INFO +0 -297
  12. kompactor-0.7.6/README.md +0 -275
  13. kompactor-0.7.6/kompactor.egg-info/PKG-INFO +0 -297
  14. {kompactor-0.7.6 → kompactor-0.7.8}/LICENSE +0 -0
  15. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/__main__.py +0 -0
  16. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/_launch.py +0 -0
  17. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/config.py +0 -0
  18. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/estimate.py +0 -0
  19. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/filters.py +0 -0
  20. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/graph.py +0 -0
  21. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/hooks.py +0 -0
  22. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/langs.py +0 -0
  23. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/outline.py +0 -0
  24. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/prove.py +0 -0
  25. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/rules.py +0 -0
  26. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/samples.py +0 -0
  27. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/server.py +0 -0
  28. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/shellwrap.py +0 -0
  29. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/OFL.txt +0 -0
  30. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/plex-mono-400.woff2 +0 -0
  31. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/plex-mono-500.woff2 +0 -0
  32. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/plex-sans-400.woff2 +0 -0
  33. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/plex-sans-500.woff2 +0 -0
  34. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/fonts/plex-sans-600.woff2 +0 -0
  35. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/static/logo-mark.svg +0 -0
  36. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/store.py +0 -0
  37. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor/tokens.py +0 -0
  38. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor.egg-info/SOURCES.txt +0 -0
  39. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor.egg-info/dependency_links.txt +0 -0
  40. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor.egg-info/entry_points.txt +0 -0
  41. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor.egg-info/requires.txt +0 -0
  42. {kompactor-0.7.6 → kompactor-0.7.8}/kompactor.egg-info/top_level.txt +0 -0
  43. {kompactor-0.7.6 → kompactor-0.7.8}/setup.cfg +0 -0
  44. {kompactor-0.7.6 → kompactor-0.7.8}/tests/test_graph.py +0 -0
  45. {kompactor-0.7.6 → kompactor-0.7.8}/tests/test_shell.py +0 -0
@@ -0,0 +1,459 @@
1
+ Metadata-Version: 2.4
2
+ Name: kompactor
3
+ Version: 0.7.8
4
+ Summary: Cut the tokens Claude Code spends on noise: compacted command output (failing runs included), outline-first reads, a local code graph, and per-turn savings.
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/amarkum/kompactor
7
+ Project-URL: Documentation, https://github.com/amarkum/kompactor#readme
8
+ Project-URL: Changelog, https://github.com/amarkum/kompactor/blob/main/CHANGELOG.md
9
+ Project-URL: Evidence, https://github.com/amarkum/kompactor/blob/main/evidence/REPORT.md
10
+ Project-URL: Issues, https://github.com/amarkum/kompactor/issues
11
+ Keywords: claude,claude-code,claude-code-plugin,anthropic,ai-coding,llm,tokens,token-optimization,context-window,cost-optimization,developer-tools,hooks,code-graph
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Topic :: Software Development
18
+ Classifier: Topic :: Software Development :: Testing
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Classifier: Programming Language :: Python :: 3.12
25
+ Classifier: Programming Language :: Python :: 3.13
26
+ Classifier: Environment :: Plugins
27
+ Requires-Python: >=3.9
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Provides-Extra: exact
31
+ Requires-Dist: tiktoken>=0.7; extra == "exact"
32
+ Dynamic: license-file
33
+
34
+ <p align="center">
35
+ <picture>
36
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/amarkum/kompactor/main/docs/brand/kompactor-logo-dark.png">
37
+ <img src="https://raw.githubusercontent.com/amarkum/kompactor/main/docs/brand/kompactor-logo-light.png" alt="Kompactor" width="240">
38
+ </picture>
39
+ </p>
40
+
41
+ <p align="center"><b>Cut the tokens Claude Code spends on noise.</b><br>
42
+ Shorter tool output for Claude, the same answers, and a dashboard that shows what every turn saved.</p>
43
+
44
+ <p align="center">
45
+ <a href="https://pypi.org/project/kompactor/"><img src="https://img.shields.io/pypi/v/kompactor?color=f5a524&label=PyPI" alt="PyPI version"></a>
46
+ <a href="https://pypi.org/project/kompactor/"><img src="https://img.shields.io/pypi/pyversions/kompactor" alt="Python versions"></a>
47
+ <a href="https://github.com/amarkum/kompactor/blob/main/LICENSE"><img src="https://img.shields.io/github/license/amarkum/kompactor" alt="MIT license"></a>
48
+ <img src="https://img.shields.io/badge/dependencies-none-brightgreen" alt="No dependencies">
49
+ <img src="https://img.shields.io/badge/Claude%20Code-plugin-d97757" alt="Claude Code plugin">
50
+ <a href="https://github.com/amarkum/kompactor/stargazers"><img src="https://img.shields.io/github/stars/amarkum/kompactor?style=flat" alt="GitHub stars"></a>
51
+ </p>
52
+
53
+ <p align="center">
54
+ <a href="#quick-start">Quick start</a> ·
55
+ <a href="#how-it-works">How it works</a> ·
56
+ <a href="#evidence">Evidence</a> ·
57
+ <a href="#configuration">Configuration</a> ·
58
+ <a href="#faq">FAQ</a>
59
+ </p>
60
+
61
+ ---
62
+
63
+ Most of a Claude Code session's tokens aren't your prompt or Claude's answer. They're **tool output**: test runs, installs, `git log`, whole-file reads. That output is sent again on every later turn until the context is compacted. Kompactor shrinks it before Claude reads it, and always keeps errors, failing tests, your own stack frames and summary lines.
64
+
65
+ | Tokens per session | Cost per session | Output tokens | Answers correct |
66
+ |:---:|:---:|:---:|:---:|
67
+ | **−16%** | **−10%** | **−22%** | **27/27** (same as without) |
68
+
69
+ Measured in 54 real Claude Code sessions on Flask, Cobra, SWR, ky and zustand at the default level. Single commands shrink far more: a failing `pytest -v` run goes from 9,842 to 1,138 tokens, and a fresh `npm install` from ~33,000 to 469. [See the evidence](#evidence).
70
+
71
+ ![Kompactor dashboard: tokens kept out of Claude's context, turn by turn](https://raw.githubusercontent.com/amarkum/kompactor/main/docs/dashboard-overview.png)
72
+
73
+ ## Contents
74
+
75
+ - [Features](#features)
76
+ - [Quick start](#quick-start)
77
+ - [How it works](#how-it-works)
78
+ - [Examples](#examples)
79
+ - [Usage](#usage)
80
+ - [Quality vs tokens](#quality-vs-tokens)
81
+ - [Configuration](#configuration)
82
+ - [See your savings](#see-your-savings)
83
+ - [Code graph](#code-graph)
84
+ - [Use it across a team](#use-it-across-a-team)
85
+ - [Evidence](#evidence)
86
+ - [Supported languages](#supported-languages)
87
+ - [What Kompactor runs and changes](#what-kompactor-runs-and-changes)
88
+ - [Troubleshooting](#troubleshooting)
89
+ - [FAQ](#faq)
90
+ - [Development](#development)
91
+ - [Contributing](#contributing)
92
+ - [License](#license)
93
+
94
+ ## Features
95
+
96
+ - **Compacts command output.** Passing tests, progress bars, download chatter, library stack frames and lock-file diffs are dropped. Errors, failures, your own frames and summary lines are always kept.
97
+ - **Handles failing commands.** Claude Code skips output hooks when a command fails and cuts its output to the first and last ~5K characters. Kompactor's shell prefix runs the command to completion, compacts it and passes the exit code through.
98
+ - **Outline-first file reads.** Big source files arrive as an outline (symbols, line ranges, who imports the file, which tests cover it). Claude reads just the ranges it needs; repeating the read returns the whole file.
99
+ - **Local code graph.** Find code by topic, see callers, the impact of a change and the tests to run, for Python, Go, TypeScript, JavaScript and React.
100
+ - **Terse replies and lean code.** Short, readable rules for answer-first prose and smallest-diff code, from 0 to 177 tokens depending on the level.
101
+ - **Per-turn savings.** In the reply, the status line, the VS Code status bar and a local dashboard. Numbers are conservative and never count output Claude wouldn't have read.
102
+ - **One dial for quality vs tokens.** Five levels, every option adjustable, per project, with a live preview of exactly what Claude would see.
103
+ - **Nothing is lost.** Every shortened output keeps a raw copy (`kompactor show <id>`), and every hook fails open.
104
+ - **Private and dependency-free.** Python 3.9+ standard library only. Runs locally, sends nothing anywhere, no telemetry.
105
+ - **Proven, reproducibly.** `kompactor prove` reruns real Claude Code tasks with and without Kompactor; the results are in this repo.
106
+
107
+ ## Quick start
108
+
109
+ Pick one. All of them set up the same thing, and the Claude Code CLI and VS Code extension share it.
110
+
111
+ **Claude Code plugin** (recommended). In any Claude Code session, one line at a time:
112
+ ```
113
+ /plugin marketplace add amarkum/kompactor
114
+ /plugin install amarkum@kompactor
115
+ /kompactor setup
116
+ ```
117
+ The last step adds the status line and the shell prefix that compacts failing commands, which a plugin can't set itself. Then restart Claude Code.
118
+
119
+ **pip / pipx / uv** (macOS, Linux, Windows):
120
+ ```bash
121
+ pipx install kompactor # or: pip install kompactor · uv tool install kompactor
122
+ kompactor setup
123
+ ```
124
+
125
+ **VS Code.** Download `kompactor-0.7.8.vsix` from [Releases](https://github.com/amarkum/kompactor/releases), install it (Extensions › `⋯` › *Install from VSIX…*), and click **Enable** when Kompactor asks.
126
+
127
+ **From source:**
128
+ ```bash
129
+ git clone https://github.com/amarkum/kompactor.git && ./kompactor/install.sh # Windows: .\kompactor\install.ps1
130
+ ```
131
+
132
+ ### After you install
133
+
134
+ 1. **Restart Claude Code** (CLI or VS Code). Kompactor starts with the next session.
135
+ 2. **Work as usual.** You don't call Kompactor; it acts on Claude's tool calls by itself. After each reply you'll see a line like `Kompactor: −8.2k tokens this turn`, and the status line shows the running total.
136
+ 3. **Check it's on:** run `kompactor` in a terminal (or `/kompactor` in Claude Code):
137
+ ```
138
+ Kompactor 0.7.8: ON
139
+ Connected via the Claude Code plugin. New Claude Code sessions are compacted.
140
+ Level: Balanced (level 3 of 5). Change it: `kompactor config preset 1-5`, the dashboard, or /kompactor balanced
141
+ Saved so far: 41.3k tokens (−38%) over 52 tool calls. Details: `kompactor gain`
142
+ ```
143
+ 4. **Open the dashboard:** `kompactor start` runs it in the background on a free port and prints the address.
144
+
145
+ ## How it works
146
+
147
+ Kompactor uses Claude Code's hooks, so it sits between Claude's tools and Claude itself:
148
+
149
+ | When Claude… | Kompactor… | Mechanism |
150
+ |---|---|---|
151
+ | runs a command | drops passing tests, progress bars, download chatter, library stack frames and lock-file diffs; keeps errors, failures, your frames and summaries | `PostToolUse` hook |
152
+ | runs a command that **fails** | runs it to completion, compacts it and passes the exit code through, so the failures in the middle survive | `CLAUDE_CODE_SHELL_PREFIX` |
153
+ | gets more than ~30K characters back | compacts the whole output instead of Claude Code's 2 KB preview | `PostToolUse` hook |
154
+ | opens a big source file | returns its outline first: symbols with line ranges, signatures, importers and covering tests | `PreToolUse` hook |
155
+ | first searches the code | adds a short map of the most depended-on modules, once per session | `PostToolUse` context |
156
+ | writes a reply (subagents too) | gets a few lines of rules: answer first, smallest diff, reuse before writing | `SessionStart`, `SubagentStart` |
157
+ | finishes a turn | shows what the turn saved | `Stop` hook |
158
+
159
+ **Nothing is lost.** Every shortened output keeps a raw copy that Claude can fetch with `kompactor show <id>` (the id is printed in the short version). An outline-first read is "deny once, allow on retry", so Claude can always get the full file. Kompactor never changes what a command does, your permission rules still apply, and every hook fails open. How Claude Code's hooks behave on success, failure and very long output is written up in [docs/SPEC.md](https://github.com/amarkum/kompactor/blob/main/docs/SPEC.md).
160
+
161
+ ## Examples
162
+
163
+ Ask Claude Code the way you normally would. These prompts come from the [evidence](#evidence) runs:
164
+
165
+ | You ask | What Kompactor does | Measured |
166
+ |---|---|---|
167
+ | "Run the tests and tell me which one fails and why." | Claude sees the failing test, its error and the summary line instead of hundreds of passing tests, even when the run exits non-zero. | Go: −33% tokens; vitest: −37% cost |
168
+ | "Where is the session cookie signed?" | Big files arrive as outlines with line ranges, and the first search adds a map of the main modules, so Claude finds the code in fewer turns. | Flask: −26% tokens |
169
+ | "Install the dependencies and check that it builds." | Download and progress chatter is dropped; warnings, errors and the result are kept. | `npm install`: ~33,000 › 469 tokens |
170
+ | "What does changing `createStore` affect?" | The code graph lists the files that use it and the tests to run. | 27/27 answers correct |
171
+ | `/kompactor review` | Lists cuts in your current diff: duplicated helpers, unused options, dead branches. | |
172
+
173
+ ## Usage
174
+
175
+ ### In Claude Code
176
+
177
+ | Command | What it does |
178
+ |---|---|
179
+ | `/kompactor` or `/kompactor status` | Is it on, current level, savings so far |
180
+ | `/kompactor balanced`, `/kompactor max savings`, `/kompactor max quality` | Change the level |
181
+ | `/kompactor stop` · `/kompactor start` | Pause it · turn it back on |
182
+ | `/kompactor review` | Suggests cuts in your current diff |
183
+ | `/kompactor audit` · `/kompactor debt` | Dead-code candidates · a list of FIXME/HACK/TODO shortcuts |
184
+
185
+ ### In a terminal
186
+
187
+ | Command | What it does |
188
+ |---|---|
189
+ | `kompactor` / `kompactor status` | On or off, level, savings, how it works |
190
+ | `kompactor setup` | Connect to Claude Code (CLI + VS Code) and open the dashboard |
191
+ | `kompactor start` / `kompactor stop` | Turn on (dashboard in the background, free port) / pause |
192
+ | `kompactor uninstall [--purge]` | Remove from Claude Code (`--purge` also deletes `~/.kompactor`) |
193
+ | `kompactor presets` · `kompactor config preset 4` | List levels · change level |
194
+ | `kompactor config <setting> <value>` | Change one [setting](#settings) |
195
+ | `kompactor gain` | Savings so far |
196
+ | `kompactor estimate` | Replay your past sessions: what Kompactor would have saved |
197
+ | `kompactor graph <action>` | `query`, `impact`, `explain`, `callers`, `deps`, `path`, `report`, `unused` |
198
+ | `kompactor show ID` · `kompactor search TEXT` | The raw outputs Kompactor shortened |
199
+ | `kompactor run -- <command>` | Run any command and print its compacted output (for other agents or scripts) |
200
+ | `kompactor prove` | A/B test Kompactor in real Claude Code sessions |
201
+ | `kompactor doctor` | Check the installation and show recent hook errors |
202
+ | `kompactor ui` | The dashboard, in the foreground |
203
+
204
+ ## Quality vs tokens
205
+
206
+ ![Quality vs tokens with a live preview of what Claude receives](https://raw.githubusercontent.com/amarkum/kompactor/main/docs/dashboard-quality.png)
207
+
208
+ One level sets everything. Change it on the dashboard, with `/kompactor <level>` in chat, or with `kompactor config preset <1-5>`. Each project can have its own level.
209
+
210
+ | Level | What Claude gets | Max lines per output | Outline files from | Code map | Reply rules |
211
+ |---|---|---:|---:|---:|---:|
212
+ | 1 Max quality | Almost everything; only pure noise is removed from large outputs | 600 | 1,500 lines | — | 0 tokens |
213
+ | 2 Quality | Noisy commands compacted, passing tests hidden, one-line `git log` | 400 | 800 lines | — | 72 tokens |
214
+ | 3 **Balanced** (default) | Library frames trimmed, code map, lean-code rules | 200 | 400 lines | 500 tokens | 156 tokens |
215
+ | 4 Savings | Tighter caps, 3 lines of diff context, shorter prose | 120 | 250 lines | 700 tokens | 176 tokens |
216
+ | 5 Max savings | 1 line of diff context, telegraphic prose | 80 | 150 lines | 900 tokens | 177 tokens |
217
+
218
+ ## Configuration
219
+
220
+ Settings come from, in increasing priority: the level → your global choices → a committed `.kompactor.json` in the repo → your per-project choices on the dashboard → `KOMPACTOR_<SETTING>` environment variables → `KOMPACTOR_PRESET`. The dashboard is the easiest way to change them; `kompactor config` prints the effective settings for the current folder.
221
+
222
+ ### Settings
223
+
224
+ | Setting | Type | What it does |
225
+ |---|---|---|
226
+ | `bash` | bool | Compact command output |
227
+ | `bash_wrap` | bool | Compact failing commands too (needs the shell prefix from `kompactor setup`) |
228
+ | `bash_plain` | bool | Ask Claude to run commands without `\| head`, `\| tail` or `\| grep`, since Kompactor keeps every failure |
229
+ | `bash_min_tokens` | int | Leave outputs smaller than this untouched |
230
+ | `bash_max_lines` | int | Max lines kept per output (head and tail kept; error lines from the middle always kept) |
231
+ | `max_line_chars` | int | Clip longer lines (minified code, giant JSON) with a `+N chars` note |
232
+ | `grep_per_file` | int | Search matches shown per file before `+N more` |
233
+ | `test_hide_passing` | bool | Drop passing-test lines; keep failures and the summary |
234
+ | `test_boilerplate` | bool | Drop test-runner banners, separators and timing lines |
235
+ | `trim_stack_frames` | bool | Collapse library frames (site-packages, node_modules, Go runtime) in tracebacks |
236
+ | `diff_context` | int | Unchanged lines kept around each change in diffs (`-1` = all) |
237
+ | `git_log_compact` | bool | Turn verbose `git log` into `sha date author: subject` |
238
+ | `read_outline` | bool | Outline-first reads for big files |
239
+ | `read_outline_lines` | int | Line count from which a file is outlined first |
240
+ | `read_graph_context` | bool | Outlines say which modules import the file and which tests cover it |
241
+ | `read_dedupe` | bool | Re-reading an unchanged file gets a short note |
242
+ | `graph` | bool | Build and use the local code graph |
243
+ | `session_map_tokens` | int | Token budget for the code map given on the first search (`0` = off) |
244
+ | `style` | choice | Prose: `off`, `lite`, `full`, `ultra` |
245
+ | `code_style` | choice | Code: `normal`, `lean`, `strict` |
246
+ | `subagent_rules` | bool | Give subagents the same rules |
247
+ | `never_compact` | list | Commands whose output always passes through untouched |
248
+
249
+ General: `turn_summary` (savings line after each reply), `statusline`, `retention_days` (default 30).
250
+
251
+ ### Environment variables
252
+
253
+ | Variable | Effect |
254
+ |---|---|
255
+ | `KOMPACTOR_RAW=1` | Pass output through untouched (for the whole session, or prefix a single command with it) |
256
+ | `KOMPACTOR_PRESET=1…5` | Force a level |
257
+ | `KOMPACTOR_<SETTING>` | Override one setting, e.g. `KOMPACTOR_BASH_MAX_LINES=300` |
258
+ | `KOMPACTOR_HOME` | Where Kompactor keeps its data (default `~/.kompactor`) |
259
+ | `KOMPACTOR_REPO` | The repo the dashboard's share commands name, for teams running a fork |
260
+
261
+ ### Per-repository settings
262
+
263
+ Commit a `.kompactor.json` next to the code to give everyone the same level and overrides:
264
+ ```json
265
+ { "preset": 4, "overrides": { "never_compact": ["terraform plan"] } }
266
+ ```
267
+
268
+ ## See your savings
269
+
270
+ | Where | What you see |
271
+ |---|---|
272
+ | After each reply | `Kompactor: −8.2k tokens this turn (13.1k › 4.9k, −63%) · session −41k · context ≈31% smaller` |
273
+ | CLI status line | `Kompactor −41.3k · ctx −31% · last turn −8.2k · Balanced` |
274
+ | VS Code status bar | Running savings; hover for details |
275
+ | Dashboard (`kompactor start`) | Per-turn chart, biggest wins, savings by feature and by project |
276
+ | `kompactor gain` | The same numbers in the terminal |
277
+ | `kompactor estimate` | Replays your **past** sessions and shows what Kompactor would have saved |
278
+
279
+ The numbers are conservative: they count only what Claude would really have read. When Claude Code would have truncated an output anyway, only the truncated size counts, and when Claude reads a whole file after its outline, the outline's saving is reversed.
280
+
281
+ ## Code graph
282
+
283
+ ![Code graph of Flask: a 395-token map instead of 165.8k tokens of source, and a search for "session cookie"](https://raw.githubusercontent.com/amarkum/kompactor/main/docs/dashboard-graph.png)
284
+
285
+ A local index of your repository: functions, classes, imports and calls. It builds in about a second (Flask: 84 files in 0.35 s), refreshes in the background after edits, and is never sent anywhere or written into your repo. Claude uses it on its own; you can query it too:
286
+
287
+ ```
288
+ kompactor graph query "session cookie" find code by topic, with line ranges and who uses it
289
+ kompactor graph impact createStore what uses it, and which tests to run
290
+ kompactor graph explain Name one symbol: signature, callers, callees, tests
291
+ kompactor graph callers / deps / path who calls it, what it imports, how two modules connect
292
+ kompactor graph report core modules, entry points, import cycles
293
+ kompactor graph unused dead-code candidates
294
+ ```
295
+
296
+ ## Use it across a team
297
+
298
+ ![Share with your team: the dashboard's Setup panel](https://raw.githubusercontent.com/amarkum/kompactor/main/docs/dashboard-team.png)
299
+
300
+ **Turn it on for everyone who works in a repo.** Commit this as `.claude/settings.json`:
301
+ ```json
302
+ {
303
+ "extraKnownMarketplaces": {
304
+ "kompactor": { "source": { "source": "github", "repo": "amarkum/kompactor" }, "autoUpdate": true }
305
+ },
306
+ "enabledPlugins": { "amarkum@kompactor": true }
307
+ }
308
+ ```
309
+ When a teammate trusts the folder, Claude Code installs the plugin; each person then runs `/kompactor setup` once. `autoUpdate` keeps everyone on the latest release. Admins can put the same keys in Claude Code's managed settings to roll it out to every machine, and a team that runs its own fork sets `KOMPACTOR_REPO` so the dashboard shows the fork's commands.
310
+
311
+ ## Evidence
312
+
313
+ `kompactor prove` runs each task in real headless Claude Code sessions (`claude -p`), 3 times without Kompactor and 3 times with it, interleaved, with the same prompt, tools, turn limit and budget cap. Tokens are input + cache writes + cache reads + output across every API call; cost is Claude Code's own figure.
314
+
315
+ | Task | Repo | Tokens | Cost | Turns | Correct (without › with) |
316
+ |---|---|---:|---:|---|---|
317
+ | Find the failing Go test and its error | Cobra | **−33%** | **−18%** | 3.3 › 2.0 | 3/3 › 3/3 |
318
+ | Find how requests are deduplicated | SWR | **−32%** | −12% | 3.0 › 2.0 | 3/3 › 3/3 |
319
+ | Find where the session cookie is signed | Flask | **−26%** | −11% | 3.7 › 2.7 | 3/3 › 3/3 |
320
+ | Find the flag-group validation function | Cobra | −24% | −6% | 2.7 › 2.3 | 3/3 › 3/3 |
321
+ | Most-changed files in the last 40 commits | Flask | −16% | +4% | 3.7 › 3.0 | 3/3 › 3/3 |
322
+ | Find the failing vitest test (`--reporter=verbose`) | zustand | −7% | **−37%** | 2.0 › 2.0 | 3/3 › 3/3 |
323
+ | Type-check and list errors | ky | +1% | −2% | 2.0 › 2.0 | 3/3 › 3/3 |
324
+ | Find the failing pytest tests | Flask | +1% | +3% | 2.0 › 2.0 | 3/3 › 3/3 |
325
+ | What does changing `createStore` affect | zustand | +17% | +4% | 2.0 › 2.3 | 3/3 › 3/3 |
326
+ | **Total (54 sessions)** | | **−16%** | **−10%** | | **27/27 › 27/27** |
327
+
328
+ At the other levels, against the same baseline:
329
+
330
+ | Level | Tokens | Cost | Output tokens | Correct |
331
+ |---|---:|---:|---:|---|
332
+ | 1 Max quality | +3% | −1% | 0% | 27/27 |
333
+ | 3 Balanced (default) | **−16%** | **−10%** | **−22%** | 27/27 |
334
+ | 5 Max savings | −12% | −10% | −22% | 27/27 |
335
+
336
+ Single commands, measured directly (`bench/bench.py`):
337
+
338
+ | Repo | Command | Raw tokens | Balanced | Max savings |
339
+ |---|---|---:|---:|---:|
340
+ | Flask | `pytest -v tests` (1 failure, 482 passed) | 9,842 | 1,138 (**−88%**) | 696 (**−93%**) |
341
+ | Flask | `grep -rn 'def ' src` | 8,492 | 3,230 (−62%) | 1,323 (−84%) |
342
+ | Flask | `git log -n 40` | 1,457 | 598 (−59%) | 598 (−59%) |
343
+ | ky | `npm install` (fresh) | ~33,000 | 469 (**−99%**) | 451 (−99%) |
344
+ | ky | `grep -rn await source` | 2,938 | 1,653 (−44%) | 1,058 (−64%) |
345
+ | Flask | Read `src/flask/app.py` (1,625 lines) › outline | 14,084 | 1,490 (−89%) | 1,490 (−89%) |
346
+ | ky | Read `source/core/Ky.ts` (1,376 lines) › outline | 12,452 | 919 (−93%) | 919 (−93%) |
347
+
348
+ - **The wins come from avoided turns.** Every turn re-sends the whole context. The vitest failure was 32K characters of passing tests; Kompactor gave Claude 1K characters with the failure, at 37% lower cost.
349
+ - **Short sessions pay a small fixed cost.** On 2-turn tasks with little output, the rules add about 1%.
350
+ - **Session savings are smaller than command savings** because most of each session is Claude Code's own fixed context.
351
+
352
+ **Read more:** [full report](https://github.com/amarkum/kompactor/blob/main/evidence/REPORT.md) · [every session's tokens, tool calls and answers](https://github.com/amarkum/kompactor/blob/main/evidence/results.json) · [what Claude received in each arm for the same failing run](https://github.com/amarkum/kompactor/blob/main/evidence/EXAMPLE.md) · [how Kompactor compares with graphify, rtk, caveman and others](https://github.com/amarkum/kompactor/blob/main/docs/comparison.md)
353
+
354
+ **Reproduce it:** `python -m kompactor prove --tasks bench/tasks.json --repos <folder with the bench repos> --reps 3`
355
+
356
+ ## Supported languages
357
+
358
+ Command output from any language is compacted. These languages also get language-aware trimming, outlines and the code graph; Kompactor detects them per repo (`pyproject.toml`, `go.mod`, `tsconfig.json`/`package.json`, a `react` or `next` dependency).
359
+
360
+ | | Python | Go | TypeScript / React |
361
+ |---|---|---|---|
362
+ | Library stack frames collapsed | `site-packages`, stdlib, `.venv` | `GOROOT`, `runtime/`, `pkg/mod` | `node_modules`, `node:internal`, `react-dom`, `next/dist` |
363
+ | Generated files (outline instead of a full read) | `*_pb2.py`, migrations | `*.pb.go`, `*_gen.go`, `zz_generated*`, mocks | `*.d.ts`, `*.min.js`, `dist/`, `.next/` |
364
+ | Lock files collapsed in diffs | `poetry.lock`, `uv.lock`, `Pipfile.lock` | `go.sum` | `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml` |
365
+ | Test runners | pytest, unittest, tox, nox | `go test`, gotestsum | jest, vitest, mocha, playwright |
366
+ | Code graph | classes, functions, decorators, imports, calls | packages, structs, interfaces, methods | components, hooks, JSX renders, `tsconfig` paths, workspaces |
367
+
368
+ ## What Kompactor runs and changes
369
+
370
+ Everything below happens on your machine. Kompactor makes no network requests of its own and has no telemetry. (If you install the optional `tiktoken` package for exact token counts, tiktoken downloads its token table once, on first use.)
371
+
372
+ **What it runs.** Python hooks that Claude Code calls (`python3 kompactor/_launch.py hook <name>` from the plugin folder): after Bash, Read, Grep, Glob and edit tool calls; before Read; at session start, subagent start and before compaction; and when a turn ends. After `/kompactor setup` on macOS and Linux, Claude's Bash commands run through Kompactor's shell prefix (`~/.kompactor/bin/kompactor-shell`) so failing runs can be compacted too. The prefix runs after Claude Code's permission check, on Claude's original command, and returns its exit code unchanged.
373
+
374
+ **What it adds to Claude's context.** Compacted tool output, outlines in place of large file reads, a code map once per session, a one-line savings note after each turn, and short reply rules at session start and for subagents. The rules are plain text you can read in [`kompactor/rules.py`](https://github.com/amarkum/kompactor/blob/main/kompactor/rules.py).
375
+
376
+ **What it reads.** The tool output Claude Code passes to its hooks, the files Claude reads (to outline them), your project's source (for the code graph), and the context size Claude Code gives the status line. Hooks never read your session transcripts. `kompactor estimate` and the dashboard's **Replay your history** panel read your local Claude Code session logs in `~/.claude/projects` only when you run them; the result isn't stored or sent anywhere.
377
+
378
+ **What it writes.** `~/.kompactor/`: settings, the savings ledger, raw copies of shortened output (for `kompactor show`), the code graph index and the `~/.kompactor/bin/` launchers. History is deleted after 30 days by default. Setup edits `~/.claude/settings.json` to add Kompactor's hooks (non-plugin installs), a status line (only if you have none) and `CLAUDE_CODE_SHELL_PREFIX` (only if it isn't set), keeping a backup in `settings.json.kompactor-backup`; non-plugin installs also get the `/kompactor` skill in `~/.claude/skills`. Nothing is written to your repositories.
379
+
380
+ **What it never does.** Change your permission rules or sandbox settings, change what a command does, or send your code or output anywhere. Details: [privacy policy](https://github.com/amarkum/kompactor/blob/main/PRIVACY.md).
381
+
382
+ ## Troubleshooting
383
+
384
+ | Problem | What to do |
385
+ |---|---|
386
+ | No savings line after replies | Restart Claude Code after setup, then run `kompactor doctor`: it checks the installation and shows recent hook errors. The dashboard's **Self-test** panel runs every hook once. |
387
+ | An output looks too short | Claude can fetch the original with `kompactor show <id>`, or search earlier outputs with `kompactor search "text"`. |
388
+ | A command should never be shortened | Add it to **Never compact these commands** on the dashboard, or to `never_compact` in `.kompactor.json`. For a single run, start the command with `KOMPACTOR_RAW=1`. |
389
+ | Something seems off | `kompactor stop` turns Kompactor off at once; every hook also lets the original output through if it hits an error. Errors are logged to `~/.kompactor/hook-errors.log`. |
390
+ | The dashboard port is busy | `kompactor start` picks a free port by itself and prints the address. |
391
+
392
+ **Turn it off or remove it:**
393
+ ```bash
394
+ kompactor stop # pause: output passes through untouched; settings are kept
395
+ kompactor start # turn it back on
396
+ kompactor uninstall # remove hooks, status line, shell prefix and skill (--purge also deletes ~/.kompactor)
397
+ ```
398
+ Then remove the package the way you installed it: `claude plugin uninstall amarkum@kompactor`, `pipx uninstall kompactor`, or uninstall the extension in VS Code.
399
+
400
+ ## FAQ
401
+
402
+ **Does Kompactor change Claude's answers?**
403
+ In the measured runs, no: 27 of 27 answers were correct with and without it. It removes noise and always keeps errors, failures and summary lines.
404
+
405
+ **Does it send my code anywhere?**
406
+ No. Everything runs locally through Claude Code's hooks.
407
+
408
+ **Why is the per-session saving smaller than the per-command saving?**
409
+ Most of what each turn re-sends is Claude Code's own fixed context: the system prompt, tool definitions and your messages. Kompactor shrinks the tool-output part, which can drop 80–99% per command.
410
+
411
+ **Does it work in VS Code, Cursor or other editors?**
412
+ It works wherever Claude Code runs: the CLI and the Claude Code extension in VS Code and Cursor. It doesn't apply to the Claude chat apps, which don't run plugin hooks.
413
+
414
+ **Can I use it with agents other than Claude Code?**
415
+ The hooks are Claude Code-specific, but `kompactor run -- <command>` and `kompactor filter` compact any command's output for other agents and scripts.
416
+
417
+ **How much latency does it add?**
418
+ About 50–100 ms per hook, because the filters run in Python.
419
+
420
+ **Is it free?**
421
+ Yes. MIT-licensed, no account, no paid tier.
422
+
423
+ ## Development
424
+
425
+ ```bash
426
+ git clone https://github.com/amarkum/kompactor.git && cd kompactor
427
+ python -m unittest discover tests # 80 tests, including the real shell prefix run as Claude Code runs it
428
+ node vscode/test/smoke.js # VS Code extension against a mock API
429
+ claude plugin validate . # check the plugin manifest
430
+ ./scripts/build-vsix.sh # › dist/kompactor-<version>.vsix
431
+ ```
432
+
433
+ | Path | What's there |
434
+ |---|---|
435
+ | `kompactor/hooks.py` | Claude Code hook handlers |
436
+ | `kompactor/filters.py` | Command-output compaction rules |
437
+ | `kompactor/shellwrap.py` | The shell prefix for failing commands |
438
+ | `kompactor/outline.py`, `kompactor/graph.py` | Outlines and the code graph |
439
+ | `kompactor/config.py`, `kompactor/rules.py` | Levels, settings and the reply rules |
440
+ | `kompactor/server.py`, `kompactor/ui.html` | The local dashboard |
441
+ | `kompactor/prove.py`, `bench/` | The A/B harness and benchmark tasks |
442
+ | `vscode/` | The VS Code extension |
443
+ | `docs/SPEC.md` | How Claude Code's hooks behave, and why Kompactor uses a shell prefix |
444
+
445
+ Releases: `python scripts/bump_version.py X.Y.Z`, commit and push to `main`. The workflow runs the tests and publishes to PyPI with trusted publishing.
446
+
447
+ ## Contributing
448
+
449
+ Bug reports, ideas and pull requests are welcome. See [CONTRIBUTING.md](https://github.com/amarkum/kompactor/blob/main/CONTRIBUTING.md) for how to set up, test and propose changes, and [CHANGELOG.md](https://github.com/amarkum/kompactor/blob/main/CHANGELOG.md) for what's new.
450
+
451
+ - **Questions and bugs:** [open an issue](https://github.com/amarkum/kompactor/issues)
452
+ - **Security problems:** report them privately, as described in [SECURITY.md](https://github.com/amarkum/kompactor/blob/main/SECURITY.md)
453
+ - **Privacy:** [PRIVACY.md](https://github.com/amarkum/kompactor/blob/main/PRIVACY.md)
454
+
455
+ ## License
456
+
457
+ [MIT](https://github.com/amarkum/kompactor/blob/main/LICENSE) © The Kompactor authors. The dashboard uses the IBM Plex fonts under the [SIL Open Font License](https://github.com/amarkum/kompactor/blob/main/kompactor/static/fonts/OFL.txt).
458
+
459
+ Built by [stackcone](https://stackcone.com). Read the story behind it: [Kompactor: Cut the Tokens Claude Code Spends on Noise](https://stackcone.com/blog/posts/kompactor-claude-code-token-saver/).