Show HN: Lowfat – 可插拔的CLI过滤器,为我省下了91.8%的LLM令牌

Hacker News Top 工具

摘要

Lowfat是一个轻量级的CLI过滤器,通过在被代理工具接收前剔除不必要的输出来降低AI令牌成本,声称可节省高达91.8%的令牌。它提供Shell集成、插件支持,以及针对Claude Code和OpenCode等工具的透明重写功能。

Hi HN,<p>不确定是否有人会感兴趣。<p>但只是想分享一下,我一直在维护一个叫做'lowfat'的小工具,它能帮我过滤一些冗长的CLI输出。<p>它是一个单一二进制文件,可以作为代理钩子或Shell包装器使用。 它有一个插件系统,可以根据命令自定义过滤器。<p>想法很简单:代理不需要完整的kubectl get -o yaml或任何1万行转储来做出决策。 因此lowfat位于中间,剔除噪声,只传递关键信息。<p>以下是我个人使用2个月后的真实报告:<p>lowfat history --all<p><pre><code> lowfat plugin candidates ───────────────────────────────────────────────────────── # command runs avg raw cost savings source status 1 kubectl get 101x 14.4K 1.5M 93.9% plugin good 2 grep 103x 13.5K 1.4M 96.2% plugin good 3 git diff 81x 995 80.6K 57.9% built-in good 4 kubectl 90x 485 43.6K 33.6% plugin good 5 docker 127x 5.5K 693.6K 96.1% built-in good 6 ls 489x 117 57.3K 56.2% built-in good 7 find 30x 16.5K 495.0K 95.5% plugin good 8 git show 63x 490 30.9K 38.0% built-in good 9 git 177x 368 65.2K 76.1% built-in good 10 git log 86x 556 47.8K 78.5% built-in good 11 kubectl logs 5x 3.6K 17.8K 43.0% plugin good 12 git status 86x 152 13.1K 58.0% built-in good 13 docker ps 20x 467 9.3K 52.8% plugin good 14 kubectl describe 6x 656 3.9K 1.2% plugin weak 15 docker images 9x 940 8.5K 61.8% built-in good 16 k get 2x 2.1K 4.2K 35.9% plugin good 17 terraform 10x 395 3.9K 32.1% plugin good 18 git commit 32x 77 2.5K 0.0% built-in weak 19 docker build 8x 487 3.9K 37.6% built-in good 20 docker compose 22x 979 21.5K 89.4% built-in good total: 4.4M raw → 4.1M saved (91.8%) </code></pre> 上面的工具集有限,但对我来说运行良好,没有任何中断 帮助我不超过公司Bedrock的令牌限制,并持续优化节省以备后续使用。<p>但是,为什么不选择替代方案(<a href="https://github.com/zdk/lowfat#alternatives" rel="nofollow">https://github.com/zdk/lowfat#alternatives</a>)? 原因是: - 我的目标是让核心轻量但可通过插件扩展,即不试图将每个命令都捆绑到安装的二进制文件中,让用户拥有自己的输出过滤器。 - 可通过插件或过滤管道按用例自定义,就像我使用自己的工具集一样。 - 可为非公开的CLI工具自定义,例如,某些企业可能有内部CLI工具,公众无法访问。 - 用户应该拥有自己的数据。因此设计是本地优先的,永无遥测。 - 我有点喜欢UNIX风格的可组合管道,因此lowfat-filter实现了这种风格。 - 能够调整过滤器的激进程度,以便控制不会剔除代理所需的内容。<p>GitHub: <a href="https://github.com/zdk/lowfat" rel="nofollow">https://github.com/zdk/lowfat</a><p>无论如何,如果有人感兴趣,欢迎反馈和提问!<p>谢谢!
查看原文
查看缓存全文

缓存时间: 2026/06/05 14:08

zdk/lowfat

源码: https://github.com/zdk/lowfat

lowfat 是一个轻量级 CLI 工具,通过过滤到达智能体之前的不必要 CLI 输出来降低 AI token 成本。

核心特色

  • 轻量级 — 单个小型二进制文件,核心小巧但可扩展。
  • 本地优先 — 无遥测;你的数据归你所有。
  • 可组合 — UNIX 风格管道,混合内建和你自己的过滤器,不搞黑魔法。
  • 用户自主lowfat history 展示你运行最多的命令,让你根据使用场景自定义。

安装

cargo install lowfat
# 或者
brew install zdk/tools/lowfat

GitHub Releases 提供预编译二进制文件 (https://github.com/zdk/lowfat/releases)。

配置

任选其一:

Claude Code hook — 添加到 .claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [{ "type": "command", "command": "lowfat hook" }]
      }
    ]
  }
}

Shell 集成 — 在智能体环境中自动激活 (CLAUDECODE=1, CODEX_ENV),或设置 LOWFAT_ENABLE=1 以在任何 shell 中强制启用:

echo 'eval "$(lowfat shell-init zsh)"' >> ~/.zshrc
# 或者 ~/.bashrc

OpenCode 插件 — 一条命令,无需编辑配置:

lowfat opencode install
# 写入 ~/.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
# 状态徽标 + 活跃过滤器
lowfat info git
# 适用于 `git` 的管道
lowfat info --config
# 完整解析后的配置

# 查看 lowfat 为你节省了多少
lowfat stats
# 累计 token 节省量
lowfat stats --audit
# 最近的插件执行记录
lowfat history
# 按潜在节省量排序的命令排名

# 调整过滤激进程度
lowfat level ultra
# 最大压缩
LOWFAT_LEVEL=lite lowfat git log
# 一次性覆盖

# 编写一个插件
lowfat plugin new terraform
# 生成脚手架 ~/.lowfat/plugins/terraform/
lowfat plugin doctor
# 检查插件(并预安装任何 Python 依赖)

# 在不安装的情况下用样本测试插件
cat samples/git-diff-full.txt | lowfat filter --explain ./filter.lf --sub=diff --level=ultra

了解更多

  • docs/ARCHITECTURE.md — 高层架构图:CLI、Runner、Plugins、Builtins
  • docs/CONFIG.md.lowfat 文件、环境变量、管道 DSL、内建处理器、history 排名
  • docs/PLUGINS.md — lf-filter(.lf 插件 DSL)、shell 转义逃生口、PEP 723 + uv、AI 代理提示词

替代品

  • rtk (https://github.com/rtk-ai/rtk)
  • context-mode (https://github.com/mksglu/context-mode)
  • lean-ctx (https://github.com/yvgude/lean-ctx)
  • tokf (https://github.com/mpecan/tokf)
  • tamp (https://github.com/sliday/tamp)
  • ecotokens (https://github.com/hansipie/ecotokens)
  • token-enhancer (https://github.com/xelektron/token-enhancer)

许可证

Apache-2.0

AI 声明

本项目使用了多个 AI 工具。

相似文章

将 hf CLI 设计为适合 Hub 使用的 Agent 优化工具

Hugging Face Blog

Hugging Face 重新设计了其 `hf` CLI,使其同时面向人类用户和 Claude Code、Codex 等 AI 编程 Agent 进行优化,具备 Agent 感知的输出渲染能力,基准测试显示在复杂任务上相比不使用 CLI 的方案最高可节省 6 倍的 token 消耗。