Kompactor guide · v0.5

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
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

pipx or uvKeeps Kompactor in its own environment. Then run kompactor setup.
pipx install kompactor
# or: uv tool install kompactor
Claude Code pluginRun these in Claude Code, one at a time. The last one adds the status line and the shell prefix, which a plugin can't set itself.
/plugin marketplace add amarkum/kompactor
/plugin install kompactor@kompactor
/kompactor setup
VS CodeGet the extension file from dist/ on GitHub, install it, then click Enable.
code --install-extension kompactor-0.5.0.vsix
From sourcemacOS and Linux. On Windows, run 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 /kompactor skill, 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 --uninstall removes 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.

Session starts
Short rulesAbout 150 tokens of reply rules for your level. The code graph is built or refreshed in the background.
Claude runs a command
Output is compactedPassing tests, progress bars, download chatter, library stack frames and lock-file diffs are removed. Errors, failures, your own frames and summaries stay. The full output is stashed and Claude is told how to get it.
A command fails, or prints a lot
Still compacted, still completeClaude Code cuts a failing command's output to its first and last few thousand characters, which usually drops the failures at the end of a test run, and it replaces very long output with a 2 KB preview. Kompactor's shell prefix runs tests, builds, linters and installs to completion and hands Claude the failures and summary, with the exit code unchanged. Long outputs are compacted from Claude Code's saved copy.
Claude first searches or reads code
Code map, onceA budgeted map of the most depended-on modules (Balanced and up). Sessions that only run commands don't pay for it.
Claude opens a big file
Outline firstThe first full read of a large source file returns its outline with line ranges and who imports it. Claude then reads only the ranges it needs. Repeating the read returns the whole file.
Claude edits code
Graph refreshChanged files are re-indexed in the background, so later lookups see the new code.
A subagent starts
Same rulesSubagents get the same prose and code rules as the main agent.
Claude replies
Turn summaryThe saving for the turn appears in Claude Code, in the status line, in the VS Code status bar and on the dashboard.

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.

LevelWhat Claude getsUse when
1 Max qualityAlmost everything. Only outputs over about 1,500 tokens are touched, and only pure noise is removed.Debugging something subtle, or auditing Kompactor itself.
2 QualityNoisy 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 BalancedOutline-first reads, library stack frames trimmed, a 500-token code map, lean code style.Default. Day-to-day work.
4 SavingsTighter caps, 3 lines of diff context, test banners dropped, shorter replies.Long sessions, big repos, tight budgets.
5 Max savingsMost 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 savings and so on.
  • Terminal: kompactor config preset 4, or kompactor presets to list them.
Never shortened at any level: code, commands, file paths, error text, numbers, negations, security warnings, commit messages and docs.

Using it from chat

Kompactor installs a small /kompactor skill (about 370 tokens, loaded only when used).

TypeWhat Claude does
/kompactorShows savings so far.
/kompactor max savingsSwitches the level. Any level name or number works.
/kompactor reviewReviews your current diff for code that could be cut: duplicates of existing helpers, options nobody asked for, dead branches.
/kompactor auditLists dead-code candidates from the code graph and ranks what is safe to remove.
/kompactor debtSummarises 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

WhereWhat you see
Claude Code, after each replyKompactor: −8.2k tokens this turn (13.1k › 4.9k, −63%) · session −41k · context ≈31% smaller
CLI status lineKompactor −41.3k · ctx −31% · last turn −8.2k · Balanced
VS Code status barRunning total and context reduction. Each new turn briefly shows its saving.
DashboardPer-turn chart, biggest wins by command, savings by feature, per project.
kompactor estimateReplays 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.

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 run kompactor show 17, or kompactor show 17 --lines 120-180 for 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.