Show HN: Lowfat – 一个即插即用的 CLI 过滤器,帮我节省了 91.8% 的 LLM token
Show HN: Lowfat – pluggable CLI filter that saved 91.8% of my LLM tokens

原始链接: https://github.com/zdk/lowfat

**lowfat** 是一款轻量级的本地优先命令行工具,旨在通过在 CLI 输出传送到 AI 智能体之前过滤掉不必要的内容,从而最大限度地降低 AI Token 成本。通过精简冗长的命令响应,它确保你的 Token 只用于关键数据。 **核心功能:** * **可组合且可扩展:** 遵循 UNIX 风格的管道设计哲学,允许用户将内置过滤器与自定义插件结合使用。 * **以用户为中心:** 提供透明的历史记录追踪,让你能够监控节省的成本,并根据特定工作流自定义过滤器。 * **通用集成:** 可与 Claude Code、OpenCode 和 Pi agent 等工具无缝协作。通过直接前缀、Shell 初始化或智能体特定的配置钩子即可使用。 * **精细化控制:** 可调整压缩强度(从“轻量”到“极致”),并利用专用 DSL 轻松开发自定义插件。 * **注重隐私:** 完全在本地运行,无任何遥测数据,确保你对数据拥有完全的所有权。 通过 `cargo` 或 Homebrew 即可轻松安装。无论你是要优化 CI/CD 流水线还是处理日常终端任务,`lowfat` 都能提供必要的洞察力和控制力,让你的 AI 交互保持高效且经济。

**Lowfat** 是一款可插拔的命令行过滤器,旨在通过剔除命令行输出(如 `kubectl`、`git`、`docker`)中的冗余噪声来降低 LLM 的 Token 消耗。开发者报告称,在两个月的个人使用中,原始 Token 用量降低了 91.8%。 **主要特性包括:** * **可扩展的插件系统:** 与其他工具不同,它保持了核心二进制文件的轻量化,允许用户针对特定工作流程定义自定义的过滤流水线。 * **本地优先设计:** 它作为 shell 包装器或代理钩子运行,不包含任何遥测功能,优先保障数据所有权。 * **可调节的过滤强度:** 用户可以调整过滤级别,以确保关键信息(如堆栈跟踪)不会被意外删除。 **社区讨论:** Hacker News 社区对此反响不一,既有兴趣也有质疑。批评者怀疑过滤输出可能会无意中损害代理的推理能力或上下文质量。一些人认为,“阿姆达尔定律”(Amdahl’s Law)使得 91.8% 的说法在项目整体 Token 成本方面具有误导性。另一些人则建议,指导代理使用更精确的查询(如 `jsonpath`)比事后过滤更为有效。作者承认,该工具需要手动调试,目前最适合希望优化特定操作工作流程的技术娴熟用户使用。
相关文章

原文

lowfat logo

lowfat is a lightweight CLI tool that reduces AI token costs by filtering unnecessary CLI output before it reaches your agent.

lowfat demo: git diff before and after

  • Lightweight — Small single binary, small core; but extensible.
  • Local-first — No telemetry; you own your data.
  • Composable — UNIX-style pipes, mix built-ins and your own filters; not magic.
  • User-ownedlowfat history shows what you run most; allow you to customize for your usecase.
cargo install lowfat
# or
brew install zdk/tools/lowfat

Pre-built binaries on GitHub Releases.

Pick one of:

Claude Code hook — add to .claude/settings.json:

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

Shell integration — auto-activates inside agent environments (CLAUDECODE=1, CODEX_ENV), or set LOWFAT_ENABLE=1 to force it on any shell:

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

OpenCode plugin — one command, no config editing:

lowfat opencode install   # writes ~/.config/opencode/plugins/lowfat.ts

Restart OpenCode; commands are rewritten transparently before they run. Remove it anytime with lowfat opencode uninstall.

Direct usage — prefix any command:

lowfat git status
lowfat docker ps
lowfat ls -la

Pi agent — in ~/.pi/agent/settings.json:

{ "shellCommandPrefix": "eval \"$(lowfat shell-init zsh)\"; " }
# See what's configured and how loud each filter is being
lowfat info                       # status badge + active filters
lowfat info git                   # pipeline for `git`
lowfat info --config              # full resolved config

# See what lowfat has saved you
lowfat stats                      # lifetime token savings
lowfat stats --audit              # recent plugin executions
lowfat history                    # rank commands by potential savings

# Dial the aggressiveness
lowfat level ultra                # max compression
LOWFAT_LEVEL=lite lowfat git log  # one-off override

# Write a plugin
lowfat plugin new terraform       # scaffold ~/.lowfat/plugins/terraform/
lowfat plugin doctor              # check plugins (and pre-install any Python deps)

# Test a plugin against a sample without installing it
cat samples/git-diff-full.txt | lowfat filter --explain ./filter.lf --sub=diff --level=ultra
  • docs/ARCHITECTURE.md — high-level diagram: CLI, Runner, Plugins, Builtins
  • docs/CONFIG.md.lowfat file, env vars, pipeline DSL, built-in processors, the history ranking
  • docs/PLUGINS.md — lf-filter (the .lf plugin DSL), shell escape hatches, PEP 723 + uv, AI agent prompt

Apache-2.0

Multiple AI tools were used for this project

联系我们 contact @ memedata.com