Spend Claude Code's tokens on your code, not on noise
Kompactor trims what Claude reads (test runs, installs, git output, whole-file reads) and how much it writes, and shows the saving after every turn. It works in the Claude Code CLI and the VS Code extension, on this machine only.
Install
pip install kompactor # on macOS: pip3 install kompactor
kompactor setup
Setup turns Kompactor on for Claude Code and opens the dashboard. Restart Claude Code afterwards. Kompactor needs Python 3.9 or newer, and nothing else.
Other ways to install
kompactor setup.pipx install kompactor
# or: uv tool install kompactor
/plugin marketplace add amarkum/kompactor
/plugin install kompactor@kompactor
/kompactor setup
code --install-extension kompactor-0.6.0.vsix
install.ps1 from the clone.git clone https://github.com/amarkum/kompactor.git
./kompactor/install.sh
What setup changes
- Adds Kompactor's hooks to
~/.claude/settings.json, which the Claude Code CLI and the VS Code extension both read, and keeps a backup next to it. - Adds the
/kompactorskill, and a status line with running savings if you don't have one. - On macOS and Linux, sets
CLAUDE_CODE_SHELL_PREFIX, which lets Kompactor compact failing commands too. - Never replaces a status line or shell prefix you already have.
kompactor install --uninstallremoves everything it added.
Open the dashboard any time with kompactor ui, or Kompactor: Open Dashboard in VS Code. pip install -U kompactor updates it.
What happens in a session
Kompactor works through Claude Code hooks, so it acts on every tool call without Claude having to remember to use it. Your commands run exactly as typed; only what Claude reads changes.
Quality vs tokens
One level sets every option. Move toward quality and Claude sees more raw output; toward savings and it sees less. Every individual setting can still be changed on the dashboard, globally or per project.
| Level | What Claude gets | Use when |
|---|---|---|
| 1 Max quality | Almost everything. Only outputs over about 1,500 tokens are touched, and only pure noise is removed. | Debugging something subtle, or auditing Kompactor itself. |
| 2 Quality | Noisy commands compacted, passing tests hidden, one-line git log. Big files still read whole up to 800 lines. | You want savings with no change to how Claude reads files. |
| 3 Balanced | Outline-first reads, library stack frames trimmed, a 500-token code map, lean code style. | Default. Day-to-day work. |
| 4 Savings | Tighter caps, 3 lines of diff context, test banners dropped, shorter replies. | Long sessions, big repos, tight budgets. |
| 5 Max savings | Most aggressive caps, 1 line of diff context, telegraphic replies. | Routine tasks where you mostly want results. |
Changing the level
- Dashboard: Quality vs tokens. The live preview shows exactly what Claude would get, with removed lines marked.
- VS Code: click the Kompactor item in the status bar, then Choose quality vs tokens level.
- In Claude Code: type
/kompactor balanced,/kompactor max savingsand so on. - Terminal:
kompactor config preset 4, orkompactor presetsto list them.
Using it from chat
Kompactor installs a small /kompactor skill (about 370 tokens, loaded only when used).
| Type | What Claude does |
|---|---|
/kompactor | Shows savings so far. |
/kompactor max savings | Switches the level. Any level name or number works. |
/kompactor review | Reviews your current diff for code that could be cut: duplicates of existing helpers, options nobody asked for, dead branches. |
/kompactor audit | Lists dead-code candidates from the code graph and ranks what is safe to remove. |
/kompactor debt | Summarises shortcut:, FIXME, HACK and TODO comments by severity. |
/kompactor graph <question> | Finds code by topic, or shows what a change affects. |
Code graph
Kompactor indexes functions, classes, methods, imports and calls for Python, Go, TypeScript, JavaScript and React on this machine. Building it takes well under a second for most repos, and only changed files are re-parsed. It is stored outside your repo, so it never shows up in diffs.
# find code by topic
kompactor graph query "session cookie signing"
# what breaks if this changes, and which tests to run
kompactor graph impact src/flask/sessions.py
# one symbol: where, who uses it, what it uses, its tests
kompactor graph explain Flask.make_response
# overview, dead code, import cycles
kompactor graph report
kompactor graph unused
You rarely need to type these. Claude gets the outline and the "imported by / tests" line automatically when it opens a big file, and the rules mention the commands in one line.
Seeing the savings
| Where | What you see |
|---|---|
| Claude Code, after each reply | Kompactor: −8.2k tokens this turn (13.1k › 4.9k, −63%) · session −41k (≈$0.38) · context ≈31% smaller |
| CLI status line | Kompactor −41.3k ≈$0.38 · ctx −31% · last turn −8.2k · Balanced |
| VS Code status bar | Running total and context reduction. Each new turn briefly shows its saving. |
| VS Code sidebar | Click the Kompactor icon in the activity bar: tokens and dollars for this session, today and the last 30 days, then recent turns by session. Expand a turn to see each command and file Kompactor compacted, with tokens before and after. A turn where Claude read in full what had been shortened shows the tokens it added back. |
| Dashboard | Per-turn chart, biggest wins by command, savings by feature, per project. |
kompactor estimate | Replays your past Claude Code sessions through the current settings and reports the share of tool output, billed tokens and cost it would have saved. |
"Context smaller" compares the context Claude carries now with what it would carry without Kompactor, counting everything trimmed since the last compaction. If Claude ends up reading a whole file anyway, the claimed saving for that file is taken back.
Dollars are what the kept-out tokens would have cost at the model's API prices. A token Kompactor keeps out would have been written to Claude Code's prompt cache once, then read back on every later request until the context was compacted, so the estimate counts one cache write plus a cache read per request, at the prices of the model that answered (Claude Opus 5.5, for example, writes at $5 and reads at $0.20 per million tokens). On a Claude subscription you aren't billed per token, so it's what the same work would have cost on the API.
Projects and languages
Each repo's languages are detected from pyproject.toml or requirements.txt (Python), go.mod (Go), tsconfig.json or package.json (TypeScript) and a react or next dependency (React). The profile decides which stack frames are library noise, which files are generated, and which lock files collapse in diffs. You can pin languages on the dashboard instead.
Give a repo its own level under Projects & languages, for example Max quality for a payments service and Savings for everything else.
A settings file in the repo
Commit a .kompactor.json next to the code to give everyone who uses Kompactor in that repo the same level. preset is the level, 1 (Max quality) to 5 (Max savings); overrides sets any option by its name in kompactor config.
{ "preset": 4, "overrides": { "never_compact": ["terraform plan"] } }
The repo's file beats your global level, and your own choice for that project still wins. Entries Kompactor doesn't recognise are ignored.
Getting the full output
- Every compacted output ends with a note such as
[kompactor: 4210›612 tokens; full output: kompactor show 17]. Claude, or you, can runkompactor show 17, orkompactor show 17 --lines 120-180for a slice. kompactor search "TypeError"searches every stashed output.- To skip compaction for one command, start it with
KOMPACTOR_RAW=1. - For commands you always want raw, add them to Never compact these commands on the dashboard.
- An outline is never a dead end: repeating the same Read returns the whole file.
Proving it on your repo
kompactor prove runs the same tasks through real headless Claude Code sessions with and without Kompactor, and reports tokens, cost, turns and whether each answer was right. Write a few tasks that look like your own work:
{ "tasks": [ {
"id": "failing-tests", "repo": "api",
"prompt": "Run the tests with `pytest -v` and tell me which fail and why.",
"tools": ["Bash(pytest:*)", "Read", "Grep"],
"max_turns": 8, "expect": ["test_refund_rounding"] } ] }
kompactor prove --tasks my-tasks.json --repos ~/code --reps 3 --out evidence
Each run is capped at $1 by default (--budget). The report lands in evidence/REPORT.md. Use --preset 1 to 5 to test a level, and --set name=value to test a single setting.
Kompactor's own results, from 54 sessions on Flask, Cobra, SWR, ky and zustand: 16% fewer tokens and 10% lower cost at the default level, with every answer correct in both arms. Failing test runs and code search gained the most. The same sessions at Max savings came in at 12% fewer tokens and 10% lower cost, and at Max quality close to neutral (+3% tokens, −1% cost).
Troubleshooting
Is it working?
Dashboard › Setup › Run self-test runs every installed hook exactly as Claude Code would and shows pass or fail with timings. From a terminal, use kompactor doctor.
Claude can't run kompactor
Installs from VS Code or a clone add a launcher at ~/.kompactor/bin/kompactor, which Claude can always call. Add ~/.kompactor/bin to your PATH if you want to type kompactor yourself.
Turn it off
Dashboard › Setup › Disable, or kompactor install --uninstall. This removes the hooks, the status line and the shell prefix. Your other hooks and your own status line are never touched. To keep everything except the shell prefix, turn off Compact failing commands too on the dashboard or run kompactor install --no-shell-prefix.
Every command fails with kompactor-shell: not found
~/.kompactor was deleted while Kompactor was still set up. Remove the CLAUDE_CODE_SHELL_PREFIX line from ~/.claude/settings.json, or reinstall and run kompactor install --uninstall. If Kompactor itself is broken or removed but the script is still there, commands simply run untouched.
Where is my data?
In ~/.kompactor: settings (config.json), the savings history and stashed outputs (kompactor.db, pruned after 30 days by default) and code graphs (graphs/). Nothing is sent anywhere.
FAQ
Does it change what my commands do?
No. Commands run exactly as written, with your normal permissions: Claude Code checks Claude's command against your rules before Kompactor is involved. Kompactor only changes the text Claude reads afterwards. The one visible difference: for tests, builds, linters and installs, the shell prefix collects the output until the command finishes, so those lines don't stream live in the terminal. Servers, watch modes and every other command stream as usual, and the exit code is always the command's own.
Does it slow Claude Code down?
Each hook takes about 50 to 90 ms, far less than a model turn. The shell prefix adds about 50 ms to test, build and lint commands and nothing measurable to the rest. Code graphs build in under a second for most repos, in the background for big ones.
How is this different from graphify, ponytail or caveman?
Each of those covers one layer. Kompactor covers command output, file reads, code navigation, reply length and code size together, acts automatically through hooks, keeps its own instructions small, and measures the result in real A/B sessions. The README has a feature-by-feature comparison.
Will Claude miss something important?
Errors, failing tests, your own stack frames and summaries are kept at every level, and the full output is always one command away. If in doubt, use a lower level for that project.