Pure Python token compression for AI agent CLI output. Zero telemetry, zero network calls, stdlib only.
Project description
aibrain-compress
Pure Python token compression for AI agent CLI output. Zero telemetry, zero network calls, stdlib only.
The problem
LLM agents that run shell commands on your behalf — Claude Code, Cursor, Aider, Codex, and so on — have to read the raw output of git, pytest, eslint, cargo, docker, and friends. That output is written for humans, not for a fixed context window. A single git push with progress bars, a pytest run with passing tests, or a large eslint sweep can burn thousands of tokens on noise before the actual signal is reached.
aibrain-compress filters that output. It strips progress bars, deduplicates spam, condenses diffs, keeps only failing tests, and collapses stack traces — while preserving every error, warning, and material piece of state. Pure stdlib, no network calls, no telemetry.
Token savings
| Category | Commands | Typical savings |
|---|---|---|
| Tests | pytest, vitest, jest, cargo test | 90-99% |
| ESLint (large runs) | eslint | 60-80% |
| TypeScript | tsc | 40-55% |
| Cargo build, prettier, next build | cargo build, prettier, next build | 70-87% |
| Git push (with progress bars) | git push | 80-87% |
| Git push (clean) | git push | ~63% |
| Git add / pull / fetch / stash | summary-only filter | 80%+ |
| Git status | hint stripping | 50-60% |
| Git diff | context reduction (configurable) | 40-80% |
Savings are density-dependent: a test run with one failure compresses far more than a test run with fifty.
Install
pip install aibrain-compress
Requires Python 3.8+. No runtime dependencies.
Usage
Wrap mode — run a command, get compressed output
aibrain-compress git status
aibrain-compress git diff HEAD~1
aibrain-compress pytest
aibrain-compress cargo test
Pipe mode — compress output from a command you already ran
git status | aibrain-compress -- git status
pytest | aibrain-compress -- pytest
The -- separator tells aibrain-compress that the arguments after it describe the command whose output is on stdin.
Hook mode — make git auto-compress in your shell
aibrain-compress init # install shell hook (bash or PowerShell)
aibrain-compress disable # remove the hook
Once the hook is installed, plain git status, git diff, etc. print compressed output automatically. The hook captures exit codes correctly so scripts keep working. Your ~/.bashrc or PowerShell profile is backed up before modification.
Supported commands
Git (status, diff, log, commit, push, pull, add, fetch, stash, branch, show, worktree, merge, rebase, and more), pytest, vitest, jest, cargo test, go test, cargo build, tsc, eslint, biome, prettier, next build, docker ps/images/logs, pip list/install, npm/pnpm/yarn install, Python tracebacks, env/printenv, ps, ls, cat *.json. Unknown commands fall through to a generic noise-stripping + deduplication filter.
Public Python API
from aibrain_compress import compress
raw = """On branch main
nothing to commit, working tree clean
"""
compressed = compress(['git', 'status'], raw)
print(compressed)
compress(command, output) takes the argv list of the command and the raw combined stdout+stderr string. It returns a compressed string and never raises — on any internal error it falls back to the generic filter or the raw input.
Configuration
A config file at ~/.aibrain/compress.toml can toggle filters per category:
[compress]
enabled = true # master switch — false disables everything
[compress.git]
enabled = true
[compress.env]
enabled = false # keep raw env output
Environment variables take precedence over the config file:
AIBRAIN_COMPRESS_DISABLE— master disableAIBRAIN_COMPRESS_DISABLE_GIT,_TEST,_BUILD,_DOCKER,_PIP,_ENV,_JSON,_TRACEBACKAIBRAIN_COMPRESS_DIFF_CONTEXT=N— context lines ingit diff(default: 0)
An interactive settings menu is available via aibrain-compress config.
What this does NOT do
- It does not run any LLM, tokenizer, or ML model — the compression is entirely rule-based.
- It does not modify the exit code or semantics of the wrapped command.
- It does not send anything over the network.
- It is not a general-purpose log compression tool; it targets developer CLI output specifically.
License
MIT. See LICENSE.
Related
aibrain-compress is extracted from the AIBrain portable cognitive substrate for AI agents. The rest of AIBrain deals with persistent memory, skill learning, and agent orchestration — this package is the part that deals with the firehose of CLI output those agents have to read.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aibrain_compress-2.1.0.tar.gz.
File metadata
- Download URL: aibrain_compress-2.1.0.tar.gz
- Upload date:
- Size: 44.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c74539631eea5da31843c9043ffa5318efaab3e487f8c721bb56b67bb0feb05
|
|
| MD5 |
f52767453478bffd85f1945434061e24
|
|
| BLAKE2b-256 |
77cfe698829786649fbce23c472d4904c11d9a550327123beda132aac2e11a94
|
File details
Details for the file aibrain_compress-2.1.0-py3-none-any.whl.
File metadata
- Download URL: aibrain_compress-2.1.0-py3-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2875ca008c1fe2778d8d4d58ed2add16aa39d13354a0711e70efc68b17243135
|
|
| MD5 |
aa2cd5f5ffadb8f1b25d360b9c402874
|
|
| BLAKE2b-256 |
cf1f3fe4bff8ad7e060b6e55007a5c67f116d04566c09b64c62e0fdd51400323
|