If you’ve used AI assistants long enough, you’ve probably noticed where most of the token spend goes. It’s rarely the answer — it’s the question. We paste raw logs, full Kubernetes manifests, long test outputs, and sometimes entire chunks of a repo into context, when a compact summary would have carried the same signal.

That’s why I built Shave.

Shave is a small, dependency-free Go CLI that compresses, filters, and summarizes the inputs you hand to an AI: logs, kubectl output, code context, and repetitive command output. Less input means fewer tokens, lower cost, and less noise for the model to sift through.


The idea

Shave sits between the world and the model. Instead of dumping raw output into a prompt, you pipe it through shave and send the compact result.

kubectl logs deploy/api -n prod --tail=5000 | shave logs --errors
kubectl get pods -A -o json | shave k8s pods
shave ctx ./src -q "retry logic" --budget 4000
go test ./... | shave test
git diff | shave diff --review

The core rules are simple:

  • Everything is a filter on stdin or on a file — composable with pipes.
  • Everything prints pointers or compact summaries, never full dumps, unless you ask.
  • Secrets are redacted by default.
  • Zero network, zero runtime dependencies. One static binary.

Install

Getting started is straightforward:

cd go
go build -o shave ./cmd/shave
sudo mv shave /usr/local/bin/shave

Or use the helper script:

./install.sh

Commands that I use most

Shave has a handful of focused commands, each built around a common “too much context” problem.

Command What it does
shave tokens [file] Count tokens (chars/4) and estimate USD cost for a model
shave logs [file] Dedupe, truncate, redact logs; --errors keeps relevant lines + context
shave test [file] Hide passes, keep failures + context
shave diff [file] Compress a diff; --review keeps only declaration/secret/TODO changes
shave pack <paths...> Fit the most relevant context into an explicit token budget
shave k8s pods Compact pod status table from kubectl get pods -o json
shave k8s events Deduped, compact event list
shave k8s diagnose <kind/name> One report: describe + events + (for pods) tail logs
shave ctx <paths> [-q query] Prune code to declarations/query snippets; --map gives a compact outline
shave run -- <cmd> Run a command; on repeat identical output prints [unchanged] instead

The pattern I like most is the Unix one — pipe noisy output in, get useful context out.


Token savings in practice

The savings add up quickly on real workflows. On my workloads, the typical reductions look like this:

  • kubectl logs (5k lines) → shave logs --errors: ~95%
  • kubectl get pods -o json (50 pods) → shave k8s pods: ~90%
  • Whole-repo paste → shave ctx -q topic: ~80%
  • Re-running a diagnostic command → shave run --: 100% on unchanged runs

Before sending a large payload to a model, I can also sanity check it with:

echo "..." | shave tokens -m claude-sonnet-4

It’s a simple habit, but it makes the cost visible before you hit send.


MCP server mode

Shave can also run as an MCP server over stdio, so agents can call its filters mid-session. It exposes tools like shave_logs, shave_tokens, shave_k8s_pods, shave_k8s_events, shave_ctx, shave_github, shave_test, shave_diff, and shave_pack.

shave mcp

An example OpenCode config looks like this:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "servers": {
      "shave": { "type": "local", "command": ["shave", "mcp"] }
    }
  }
}

One nice detail: repeated identical calls return [unchanged] from a 5-minute result cache, and you can pass refresh: true when you want to bypass it.


Working with Kubernetes

Kubernetes output is a great candidate for shaving. A raw kubectl get pods -o json carries a lot of structure that the model usually doesn’t need. shave k8s pods gives a compact table instead.

For deeper troubleshooting, shave k8s diagnose <kind/name> pulls together a single report — describe, events, and for pods, tail logs. That’s a lot more useful than pasting three separate command outputs into a prompt.

There’s also a sample deployment in k8s/deployment.yaml and a multi-stage Dockerfile. The pod runs sleep infinity, so you can exec into it and use shave against in-cluster outputs:

kubectl apply -f k8s/deployment.yaml
kubectl exec -it deploy/shave -- shave k8s pods -A

Scanning local repos with shave github

Another useful command is shave github. It scans local git clones — no network, no gh token needed — and builds a compact portfolio report.

shave github ~/src --depth 2 --owner rahulkj --top 10 --max 20
shave github ~/src --json > portfolio.json

It can summarize projects, spot shared patterns, detect version skew, and fingerprint normalized file contents to find exact or near-duplicate files. There are also focused modes for specific tasks:

shave github ~/src --find "retry logic"
shave github ~/src --profile
shave github ~/src --audit
shave github ~/src --near --fixes
shave github ~/src --since

I like the --profile and --audit flows in particular — one gives you a compact house-style block, and the other surfaces secret/hygiene findings with paths only. Secrets are redacted before hashing and printing, which is exactly the kind of default you want.


Why I find it useful

Shave isn’t trying to be a big platform. It’s a small utility that does one job well: reduce the noise before it reaches the model.

The combination I care about is pretty simple — stdin-friendly, composable, no network, no runtime dependencies, and safe defaults like secret redaction. That makes it easy to drop into day-to-day debugging, code exploration, and agent workflows without adding another heavyweight tool to the mix.

If you find yourself feeding raw logs or giant command outputs to an AI, give Shave a try.

Enjoy!