cubtoken

A single Rust binary (ctk) that compresses Claude Code's native tool outputs — Read, Grep, Glob, and optionally Bash — before they enter the model's context window. Large file reads become tree-sitter signature skeletons with exact line ranges; noisy grep results fold per file; huge glob listings become directory trees. Zero workflow change.
Host: Claude Code (all four tools). See Other hosts for why nothing else is supported.
Where the evidence actually is: large Read compression is the proven case — 76–88% estimated savings on the reads that trigger it. Grep, Glob and Bash folding are implemented and tested but fired rarely in dogfooding, so treat their value as unproven rather than typical. ctk stats reports what your own sessions did.
Stream compressors like rtk only see commands run through the Bash tool — by rtk's own docs, Claude Code's built-in Read/Grep/Glob bypass it entirely, and those native reads are usually the biggest token sink in a session. cubtoken covers exactly that gap and coexists with rtk (Bash handling is off by default and defers to rtk when detected).
How it works
cubtoken installs as a post-tool hook. The tool runs normally (a local file read costs nothing); the hook then replaces the result before it reaches the model — which is where tokens are actually spent. That replacement is Claude Code's PostToolUse + updatedToolOutput. Verified live: a session reading a 26KB source file received a ~70%-smaller skeleton view.
42 pub struct Registry {
… [L43-L46]
48 impl Registry {
49 /// Create an empty registry.
50 pub fn new() -> Self {
… [L51-L56]
Getting started
-
Requirements. Claude Code with exec-form hooks (command + args) and PostToolUse.updatedToolOutput. Verified against Claude Code 2.1.258; if ctk doctor passes but nothing ever compresses, update Claude Code first.
-
Get the binary. (Required for both hook options below). Prebuilt archives are on the Releases page for three targets:
| Platform | Archive |
|---|
| Linux x86_64 | ctk-x86_64-unknown-linux-gnu.tar.gz |
| macOS Apple Silicon | ctk-aarch64-apple-darwin.tar.gz |
| Windows x86_64 | ctk-x86_64-pc-windows-msvc.zip |
Anything else — Intel Macs and Linux ARM included — builds from source. Every release also ships SHA256SUMS and a build attestation:
sha256sum -c SHA256SUMS --ignore-missing
gh attestation verify ctk-*.tar.gz --repo thepragmaticbear/cubtoken
To build from source instead (stable Rust, no minimum version pinned):
git clone https://github.com/thepragmaticbear/cubtoken.git
cd cubtoken
cargo install --locked --path crates/ctk-cli
That puts ctk in ~/.cargo/bin. Install it somewhere permanent. init embeds the absolute path of whichever binary you ran it with, so installing the hook straight out of ./target/release breaks the moment you cargo clean — init warns when it sees a target/ path.
-
Install the hook. Choose one of two ways to register the hook:
-
Option A: ctk init (CLI) — Run inside the project you want to compress:
ctk init
That writes .claude/settings.local.json plus a starter .cubtoken.toml. PostToolUse matches Read|Grep|Glob|Bash|Edit|Write|NotebookEdit. cubtoken also registers lifecycle hooks for session start, turns, tool batches, stops, and session end. They print nothing unless you opt in to output.mode = "concise", and the adaptive governor needs them to tell which Reads were recoveries. The plugin registers the same set. Use ctk init --global to install once for every project (~/.claude/settings.json, or $CLAUDE_CONFIG_DIR/settings.json when set); the global install does not write a .cubtoken.toml. init is idempotent — re-running it just refreshes cubtoken's entries, and an existing .cubtoken.toml is never overwritten.
-
Option B: Claude Code Plugin — plugins/cubtoken/ ships the same hook as a Claude Code plugin, which resolves ctk at call time rather than baking in an absolute path — so cargo clean or moving the binary can't silently break it:
/plugin marketplace add thepragmaticbear/cubtoken
/plugin install cubtoken@cubtoken
Both commands run inside Claude Code, not in a shell. The plugin doesn't write a starter .cubtoken.toml; defaults apply until you add one. If the install summary says to run /reload-plugins, run it.