可插拔的CLI过滤器通过智能裁剪输入,被证实能减少超90%的LLM调用成本,对频繁使用LLM的开发者直接省钱。
lowfat 是一个轻量级 CLI 工具,通过在 AI Agent 处理之前过滤 CLI 输出和文件内容来降低 AI token 成本。
轻量 — 单个小二进制文件,核心轻量;但可扩展。
本地优先 — 无遥测;你拥有你的数据。
可组合 — UNIX 风格的管道,混合使用内置过滤器和自定义过滤器;无魔法。
用户可控 — lowfat history 显示你运行最频繁的命令;让你可以根据用例进行定制。
git status 的完整级别 — 相同的信号,更少的噪声。
前 — 原始的 git status:
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: crates/lowfat-cli/src/commands/plugin.rs
modified: crates/lowfat-cli/src/main.rs
Untracked files:
(use "git add <file>..." to include in what will be committed)
plugins/git/git-compact/samples/
no changes added to commit (use "git add" and/or "git commit -a")
后 — lowfat git status:
On branch main
Changes not staged for commit:
modified: crates/lowfat-cli/src/commands/plugin.rs
modified: crates/lowfat-cli/src/main.rs
Untracked files:
plugins/git/git-compact/samples/
在捆绑样本上测量的原始命令输出的减少量(crates/lowfat-plugin/embedded/*/samples/)。用 cat <sample> | lowfat filter <plugin>/filter.lf --sub=<sub> --level=<level> 复现:
这些百分比是单个命令输出的减少量,而不是你的端到端 agent token 使用量。节省取决于有多少上下文是命令输出,以及你选择的压缩级别有多激进 — 更高级别会丢弃更多内容,所以要验证你的 agent 仍然拥有它需要的内容。把这个表格视为输出片的上限,而不是总体的保证。
cargo install lowfat
# or
brew install zdk/tools/lowfat
GitHub Releases 上有预构建的二进制文件。
Claude Code hook — 添加到 .claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "lowfat hook" }]
}
],
"PostToolUse": [
{
"matcher": "Read",
"hooks": [{ "type": "command", "command": "lowfat post-read" }]
}
]
}
}
PreToolUse 通过 lowfat 过滤器重写 Bash 命令。PostToolUse 在 Read 之后压缩文件内容 — 移除注释、折叠函数体、总结锁文件。
Anthropic 推荐的过滤模式,但通过 lowfat 实现。
Shell 集成 — 在 agent 环境中自动激活(CLAUDECODE=1、CODEX_ENV),或设置 LOWFAT_ENABLE=1 在任何 shell 中强制启用:
echo 'eval "$(lowfat shell-init zsh)"' >> ~/.zshrc # or ~/.bashrc
OpenCode plugin — 一条命令,无需编辑配置:
lowfat opencode install # writes ~/.config/opencode/plugins/lowfat.ts
重启 OpenCode;命令在运行前会透明地被重写。用 lowfat opencode uninstall 卸载。
直接使用 — 在任何命令前加前缀:
lowfat git status
lowfat docker ps
lowfat ls -la
Pi agent — 在 ~/.pi/agent/settings.json 中:
{ "shellCommandPrefix": "eval \"$(lowfat shell-init zsh)\"; " }
# 查看配置了什么以及每个过滤器的噪声有多大
lowfat info # status badge + active filters
lowfat info git # pipeline for `git`
lowfat info --config # full resolved config
# 查看 lowfat 为你节省了什么
lowfat stats # lifetime token savings
lowfat stats --audit # recent plugin executions
lowfat history # rank commands by potential savings
# 调整攻击性
lowfat level ultra # max compression
LOWFAT_LEVEL=lite lowfat git log # one-off override
# 编写 plugin
lowfat plugin new terraform # scaffold ~/.lowfat/plugins/terraform/
lowfat plugin doctor # check plugins (and pre-install any Python deps)
# 测试 plugin 对样本的效果而不安装它
cat samples/git-diff-full.txt | lowfat filter --explain ./filter.lf --sub=diff --level=ultra
文件内容压缩(post-read)
当 Claude 读取文件时,lowfat post-read 在内容进入上下文前对其进行压缩:
压缩级别遵循 LOWFAT_LEVEL(lite/full/ultra)。节省少于 10% 的文件会原样通过。
docs/ARCHITECTURE.md — 高级图表:CLI、Runner、Plugins、Builtins
docs/CONFIG.md — .lowfat 文件、环境变量、管道 DSL、内置处理器、历史排名
docs/PLUGINS.md — lf-filter(.lf plugin DSL)、shell escape hatches、PEP 723 + uv、AI agent prompt
rtk 是最接近的工具但理念不同:rtk 是开箱即用;lowfat 是一个你自己扩展的最小化核心。
Token 节省对比
相同的命令、相同的仓库、相同的 cwd、通过两个工具运行。输出 token 用 tiktoken(cl100k_base)计数;节省是相对于原始命令输出:
坦白地说:lowfat 对 git 压缩得更硬;rtk 在 find 上略占上风;ls 接近。find 仅在 lowfat 的 ultra 级别才启动。rtk 的 --ultra-compact 在这里给出了与其默认值接近的数字,所以显示的是默认值。这是在一个仓库上的单次小型运行 — 方向性的,不是基准;在相信任何数字之前,在你自己的工作负载上进行测试。
此项目使用了多个 AI 工具。