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”是一款全新的轻量级命令行(CLI)工具,旨在通过过滤冗长的命令行输出来减少大语言模型(LLM)的令牌消耗。它作为 Shell 包装器或代理钩子,能够在 `kubectl` 或 `docker` 等命令发送给 LLM 之前,剔除其中不必要的干扰信息。 开发者报告称,在两个月的使用过程中,该工具将令牌使用量降低了 91.8%。其主要功能包括: * **插件化架构:** 用户可以针对特定命令创建自定义过滤器,非常适合专有或内部命令行工具。 * **类 UNIX 的组合性:** 支持基于管道的工作流和可调的过滤强度,使用户能够在节省令牌与避免误删关键诊断信息(如堆栈跟踪)之间取得平衡。 * **本地优先设计:** 该工具注重隐私,不包含任何遥测数据,并承诺确保用户数据留存在本地。 尽管用户担心删除必要数据可能带来风险,但 Lowfat 为开发者提供了一种可定制的方式来优化 LLM 交互,在不牺牲实用性的前提下控制使用限额。该项目现已在 GitHub 上线。
相关文章

原文

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