zdk/lowfat

lowfat - slim your command output. strips noise, saves tokens.

lowfat – Trim CLI output to save AI token costs

What it is – lowfat is a tiny, single‑binary command‑line tool that sits between your shell (or an AI‑assistant integration) and the commands you run. It filters and compresses the textual output of commands and files before that text is sent to a large‑language‑model (LLM) agent, cutting down the number of tokens the model has to process.

Why it matters – LLMs charge per token. When an AI‑assistant runs a shell command (e.g., git diff) and feeds the raw output into the model, a lot of the text is noise (status messages, unchanged lines, comments, etc.). lowfat removes or collapses that noise, letting the same command convey the essential information with far fewer tokens.


Core ideas

Idea What it means
Lightweight A small Rust binary; extra behaviour is added via plug‑ins.
Local‑first No telemetry – all data stays on your machine.
Composable Works like any Unix filter (`
User‑owned lowfat history shows which commands saved the most tokens, letting you tune filters for your own workflow.

How it works

  1. Pre‑tool hook – Before a command runs, lowfat rewrites the command (or its arguments) using a filter pipeline.
  2. Post‑read hook – After a file is read by an agent (e.g., Claude), lowfat post‑read compresses the file content (strip comments, truncate large arrays, summarize lock files, etc.).
  3. Levels – Three aggressiveness levels:
    • lite – mild trimming, safe for most cases.
    • full – stronger cuts (e.g., drop unchanged diff hunks).
    • ultra – maximal compression (collapse function bodies, keep only signatures).
  4. Plugins – Write your own filters in the .lf DSL, shell, or Python (PEP 723/uv). The built‑in set covers common tools like git, docker, grep, find, ls, and tree.

Installation

# via Cargo (Rust package manager)
cargo install lowfat
# or Homebrew (macOS/Linux)
brew install zdk/tools/lowfat

Pre‑built binaries are also available on the GitHub Releases page.


Quick start

# Run a command through lowfat
lowfat git status
lowfat docker ps
lowfat ls -la

# Show configured filters and their loudness
lowfat info
lowfat info git

# See how many tokens you’ve saved so far
lowfat stats
lowfat stats --audit   # recent plugin runs
lowfat history          # rank commands by potential savings

# Change aggressiveness on the fly
lowfat level ultra          # set default for the session
LOWFAT_LEVEL=lite lowfat git log   # one‑off override

Agent integrations

  • Claude Code – Add a hook in ~/.claude/settings.json so every Bash command is automatically passed through lowfat.
  • OpenCode – lowfat opencode install drops the appropriate plug‑in for the detected OpenCode version; commands are rewritten transparently.
  • Shell – eval "$(lowfat shell-init zsh)" (or bash) adds a wrapper that activates lowfat when environment variables like CLAUDECODE=1 are present, or when you set LOWFAT_ENABLE=1.
  • Pi agent – Add eval "$(lowfat shell-init zsh)"; to the agent’s shellCommandPrefix.

File‑content compression (post-read)

Type What lowfat does
Source code (Rust, Python, …) Strip comments, normalise whitespace; ultra collapses bodies to signatures
Markdown Remove badges/HTML comments, truncate long code blocks and tables
HTML / Vue / Svelte Drop <style>/<script> sections, optionally keep only text
JSON / JSONC Truncate huge arrays, collapse deep nesting
Lock files (Cargo.lock, package‑lock.json, …) Replace with a short summary (package count + top deps)
Unknown Keep head & tail with a line‑count note

Files that would save less than ~10 % are passed through unchanged.


Performance snapshot (sample repo)

Command Reduction at lite full ultra
git diff –16 % –38 % –96 %
git log –53 % –80 % –91 %
git status –62 % –62 % –74 %
docker ps –38 % –38 % –85 %
ls -la –2 % –75 % –87 %

These numbers reflect raw output token reduction; actual savings depend on how much of your LLM prompt consists of command output.


Comparison to similar tools

Feature lowfat rtk (closest competitor)
Core size Minimal binary, plug‑in driven Batteries‑included monolith
Built‑in commands 6 curated (git, docker, grep, find, ls, tree) 100+
Custom filter language .lf DSL + shell + Python TOML DSL
Compression levels lite/full/ultra --aggressive, --ultra-compact
Post‑read file compression Yes (code, markdown, HTML, JSON, lock files) Limited
Telemetry None Opt‑in, anonymous aggregate
Savings analytics Local stats & history Local gain & discover

License & provenance

  • License – Apache‑2.0 (permissive, commercial‑friendly).
  • AI notice – The project acknowledges that multiple AI tools were used during development.

Bottom line

lowfat is a practical, privacy‑first utility for anyone who uses LLM‑backed coding assistants (Claude, OpenCode, Pi, etc.) and wants to keep token bills low by trimming noisy CLI output and file contents. Its plug‑in architecture lets you extend the tool to any command you rely on, while the built‑in integrations make it easy to drop into existing AI‑agent workflows.

Related

  • Dispatch
  • Project
  • Project
  • Project
  • Project