能力标签
Token山羊
🛠
AI工具

Token山羊

基于 Python · 开源免费,本地部署,数据完全自主可控
英文名:token-goat
⭐ 13 Stars 🍴 1 Forks 💻 Python 📄 NOASSERTION 🏷 AI 7.2分
7.2AI 综合评分
token优化成本控制ClaudeAI编程CLI工具
✦ AI Skill Hub 推荐

AI Skill Hub 推荐使用:Token山羊 是一款优质的AI工具。AI 综合评分 7.2 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。

📚 深度解析

Token山羊 是一款基于 Python 的开源工具,在 GitHub 上收获 0k+ Star,是token优化、成本控制、Claude、AI编程领域中的优质开源项目。开源工具的最大优势在于代码完全透明,你可以审计每一行代码的安全性,也可以根据自身需求进行二次开发和定制。

**为什么要使用开源工具而非商业 SaaS?**
对于个人开发者和有隐私需求的用户,本地部署的开源工具意味着数据不离本机,不受第三方服务商的数据政策约束。同时,开源工具通常没有使用次数限制和月度费用,一次安装即可长期使用,对于高频使用场景的总拥有成本(TCO)远低于订阅制商业工具。

**安装与环境准备**
Token山羊 依赖 Python 运行环境。建议通过 pyenv(Python)或 nvm(Node.js)管理 Python 版本,避免全局环境污染。对于新手用户,推荐先创建虚拟环境(python -m venv venv && source venv/bin/activate),再安装依赖,这样即使出现问题也可以随时删除虚拟环境重新开始,不影响系统稳定性。

**社区与维护**
GitHub Issue 和 Discussion 是获取帮助的最快渠道。在提问前建议先检查 Closed Issues(已关闭的问题),大多数常见问题都已有解答。遇到 Bug 时,提供 pip list 的输出、完整错误堆栈和最小可复现示例,能显著提高开发者响应速度。AI Skill Hub 将持续追踪 Token山羊 的版本更新,及时通知重要功能变化。

📋 工具概览

专为Claude Code、Gemini CLI、Cline等AI编程工具设计的Token消耗优化器。通过智能压缩和过滤,显著降低API调用成本,适合频繁使用AI编程助手的开发者和团队节省开支。

Token山羊 是一款基于 Python 开发的开源工具,专注于 token优化、成本控制、Claude 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

GitHub Stars
⭐ 13
开发语言
Python
支持平台
Windows / macOS / Linux
维护状态
轻量级项目,按需更新
开源协议
NOASSERTION
AI 综合评分
7.2 分
工具类型
AI工具
Forks
1

📖 中文文档

以下内容由 AI Skill Hub 根据项目信息自动整理,如需查看完整原始文档请访问底部「原始来源」。

专为Claude Code、Gemini CLI、Cline等AI编程工具设计的Token消耗优化器。通过智能压缩和过滤,显著降低API调用成本,适合频繁使用AI编程助手的开发者和团队节省开支。

Token山羊 是一款基于 Python 开发的开源工具,专注于 token优化、成本控制、Claude 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。

📌 核心特色
  • 开源免费,支持本地部署,数据完全自主可控
  • 活跃的 GitHub 开源社区,持续迭代更新
  • 提供详细文档和使用示例,新手友好
  • 支持自定义配置,灵活适配不同使用环境
  • 可作为基础组件集成进现有技术栈或进行二次开发
🎯 主要使用场景
  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发
以下安装命令基于项目开发语言和类型自动生成,实际以官方 README 为准。
安装命令
# 方式一:pip 安装(推荐)
pip install token-goat

# 方式二:虚拟环境安装(推荐生产环境)
python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install token-goat

# 方式三:从源码安装(获取最新功能)
git clone https://github.com/DFKHelper/token-goat
cd token-goat
pip install -e .

# 验证安装
python -c "import token_goat; print('安装成功')"
📋 安装步骤说明
  1. 访问 GitHub 仓库页面
  2. 按照 README 文档完成依赖安装
  3. 根据系统环境完成初始化配置
  4. 参考官方示例或文档开始使用
  5. 遇到问题可在 GitHub Issues 中查找解答
以下用法示例由 AI Skill Hub 整理,涵盖最常见的使用场景。
常用命令 / 代码示例
# 命令行使用
token-goat --help

# 基本用法
token-goat input_file -o output_file

# Python 代码中调用
import token_goat

# 示例
result = token_goat.process("input")
print(result)
以下配置示例基于典型使用场景生成,具体参数请参照官方文档调整。
配置示例
# token-goat 配置文件示例(config.yml)
app:
  name: "token-goat"
  debug: false
  log_level: "INFO"

# 运行时指定配置文件
token-goat --config config.yml

# 或通过环境变量配置
export TOKEN_GOAT_API_KEY="your-key"
export TOKEN_GOAT_OUTPUT_DIR="./output"
📑 README 深度解析 真实文档 完整度 44/100 查看 GitHub 原文 →
以下内容由系统直接从 GitHub README 解析整理,保留代码块、表格与列表结构。

简介

<p align="center"> <img src="assets/logo.png" alt="Token-Goat" width="700"> </p>

<p align="center"> <b>85%</b> smaller reads &nbsp;·&nbsp; <b>97.4%</b> image compression &nbsp;·&nbsp; <b>130+</b> bash output filters &nbsp;·&nbsp; <b>94–99%</b> skill overhead cut &nbsp;·&nbsp; compaction memory </p>

<p align="center"><b>Reduces AI token use/costs by 40–90%, and improves its focus. Fully automated, always online.</b></p>

<p align="center"><b>Your AI re-reads the same file three times. Every compaction causes amnesia. Every build log buries the one line that matters. You pay for all of it. Token-Goat fixes all of it — automatically.</b></p>

<p align="center"> Token-Goat sits silently between your AI and your tools. Re-read a file? It gets a one-line hint and a narrow-slice suggestion instead of the full file again. Grab a screenshot? A 100&nbsp;KB copy reaches the model instead of 10&nbsp;MB. Run <code>pytest</code>, <code>npm install</code>, <code>docker build</code>, or <code>cargo</code>? The thousands of progress bars and passing-test names are stripped to the failures before the output even reaches the context window. Compact a long session? It gets a clean structured manifest of edited files and key symbols so nothing important is forgotten. Sessions drop 40–90%+ in cost. You change nothing about how you work. </p>

<p align="center"> Works with <b>Claude Code</b>, <b>Gemini CLI</b>, <b>Codex CLI</b>, <b>Aider</b>, <b>Cursor</b>, <b>Cline</b>, <b>Windsurf</b>, <b>Copilot CLI</b>, OpenCode, and OpenClaw. </p>

<p align="center"> <b>Ask your AI to install it fully (give it this GitHub link), or install in one command (install UV first if needed):</b> </p>

uv tool install token-goat && token-goat install

<p align="center"> Restart your AI sessions. Run <code>token-goat stats</code> a couple of minutes after your next session to see the massive savings. It also doubles as a great tracker of your work. Welcome to token efficiency. </p>

<p align="center"> <a href="https://pypi.org/project/token-goat/"><img src="https://img.shields.io/pypi/v/token-goat?label=PyPI&logo=pypi&logoColor=white" alt="PyPI version"></a> <a href="https://github.com/DFKHelper/token-goat/actions/workflows/ci.yml"><img src="https://github.com/DFKHelper/token-goat/actions/workflows/ci.yml/badge.svg" alt="CI status"></a> <a href="https://pypi.org/project/token-goat/"><img src="https://img.shields.io/pypi/pyversions/token-goat?logo=python&logoColor=white" alt="Python 3.12 | 3.13"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/license-PolyForm%20Noncommercial-lightgrey" alt="PolyForm Noncommercial"></a> </p>

<p align="center"> <img src="https://img.shields.io/badge/Windows-10%20%7C%2011-0078d4?logo=windows&logoColor=white" alt="Windows 10 | 11"> <img src="https://img.shields.io/badge/Linux-including%20WSL-FCC624?logo=linux&logoColor=black" alt="Linux including WSL"> <img src="https://img.shields.io/badge/macOS-untested-lightgrey?logo=apple&logoColor=white" alt="macOS (untested)"> <img src="https://img.shields.io/badge/requires-uv-6340ac" alt="requires uv"> </p>

<p align="center"> Built and continually improved, free, by one person. If it saves you tokens, drop a ⭐️ at the top of this page. One click. Makes my day. Also, if you'd like anything added, drop me a line. </p>

<p align="center"> <a href="#install">Install</a> &nbsp;·&nbsp; <a href="#cli">CLI</a> &nbsp;·&nbsp; <a href="#what-gets-installed">What gets installed?</a> &nbsp;·&nbsp; <a href="#stats-display">Stats</a> &nbsp;·&nbsp; <a href="#security-privacy-and-uninstall">Security & uninstall</a> </p>

---

About

I built this because long Claude Code and Codex sessions on my machine kept burning context in the same ways: screenshots landing at 2-3 MB, the agent re-reading a file it parsed hours earlier in the same conversation, compactions that forgot which functions were edited. Each felt preventable.

This is a solo project. I use it daily on Windows 11. Tests run across Python 3.12 and 3.13.

Install

Easiest install: paste this repo's URL into your AI and ask it to install token-goat properly. It will handle uv, run the commands, check codecs, and confirm everything is working.

Windows requirements: Windows 10 or 11 · Python 3.12 or 3.13 · uv (winget install astral-sh.uv)

Linux / WSL requirements: Python 3.12 or 3.13 · uv (curl -LsSf https://astral.sh/uv/install.sh | sh)

macOS requirements (untested): Python 3.12 or 3.13 · uv (curl -LsSf https://astral.sh/uv/install.sh | sh)

uv tool install token-goat
token-goat install
token-goat doctor          # confirms image codecs (WebP/JPEG/PNG) are available

Three commands. Done. Hooks register, a background worker starts at logon and stays out of the way. No terminal popups, no tray icon, no service to babysit.

Important — image codecs are part of the install. The biggest single win (~39% smaller than JPEG, ~97% smaller than raw PNG) comes from WebP encoding. Pillow ships with WebP/JPEG/PNG support on Windows and macOS out of the box, but Linux/WSL minimal images sometimes lack the system libraries (libwebp, libjpeg, zlib). token-goat doctor will report image_codecs: ok when everything is present; if it flags any codec as missing, follow the Image support section below before considering the install complete. AI agents performing this install: run token-goat doctor after token-goat install and resolve any missing codecs as part of the same task — do not treat it as a follow-up.

Two things change how Claude Code sessions behave: hooks fire automatically (image shrink, re-read dedup, compact manifests), and a block written to ~/.claude/CLAUDE.md plus a registered skill tell the agent to prefer token-goat read / symbol / section over full-file reads. A Bash(token-goat:*) allowlist entry in settings.json lets the agent run those commands without a per-call approval prompt.

On Linux and WSL, the worker registers as a systemd user service when systemd is available. On WSL without systemd, and on macOS, the SessionStart hook ensures the worker is running at the start of every Claude Code session.

What gets installed?

token-goat install writes the following on your machine — nothing else, anywhere. Every entry is reversed by token-goat uninstall. Run token-goat doctor at any time to see which of these are currently present.

Claude Code integration (~/.claude/)

PathWhat
~/.claude/settings.jsonHook entries for SessionStart, PreToolUse (Read/Grep/Bash, Drive/WebFetch), PostToolUse (Edit/Write/MultiEdit, Read/Grep/Glob, Bash, WebFetch, Skill), and PreCompact. Plus a Bash(token-goat:*) permission allowlist entry. Existing hooks are preserved; a timestamped .bak is written before any change.
~/.claude/CLAUDE.mdA delimited block (`) telling the agent to prefer token-goat read / symbol / section over Read / Grep`. Any existing content is preserved.
~/.claude/skills/token-goat/SKILL.mdThe token-goat skill — the same routing guidance in skill form.

Worker autostart (one of the following, picked by platform)

PlatformEntry
WindowsHKCU\Software\Microsoft\Windows\CurrentVersion\Run\token-goat-worker. No admin rights required.
Linux (with systemd --user)~/.config/systemd/user/token-goat-worker.service, enabled.
Linux (no systemd, incl. WSL)~/.config/autostart/token-goat-worker.desktop. On WSL without systemd, the SessionStart hook also starts the worker on every Claude Code session.
macOS (untested)~/Library/LaunchAgents/com.dfkhelper.token-goat-worker.plist, loaded via launchctl.

The autostart command is pythonw -m token_goat.cli worker --daemon from Token-Goat's uv tool venv. No PyInstaller-style launcher .exe is dropped; AV/EDR products do not behavior-flag this invocation pattern.

Weekly auto-update (Sunday 03:00 local time, runs uv tool upgrade token-goat)

PlatformEntry
WindowsScheduled task token-goat-update (schtasks).
Linux / macOSA crontab line tagged with # token-goat-autoupdate.

Data directory (created on first run)

PlatformPath
Windows%LOCALAPPDATA%\dfk-helper\token-goat\
Linux / WSL~/.local/share/token-goat/
macOS~/Library/Application Support/dfk-helper/token-goat/

Contains the symbol index (global.db, per-project .db files), session cache, shrunken-image cache, cached skill bodies (5 MB cap, LRU-evicted), embedding model (~130 MB, downloaded on the first semantic call), logs, locks, and the dirty-file queue. Nothing outside this directory and ~/.claude/ is written.

With --codex (Codex CLI integration)

PathWhat
~/.codex/config.tomlHooks block with Codex-specific matchers (view_image|Bash, apply_patch, web_search). Existing hooks preserved.
~/.codex/AGENTS.mdA delimited block (``) with the same routing guidance, adapted for Codex tool names.

With --opencode (opencode plugin)

PathWhat
~/.config/opencode/plugins/token-goat.ts (Linux/macOS) or %APPDATA%\opencode\plugins\token-goat.ts (Windows)TypeScript bridge plugin. Fires on tool.execute.before, tool.execute.after, and experimental.session.compacting. Covers image shrinking, post-edit indexing, and compact assist.

With --openclaw (openclaw plugin)

PathWhat
~/.openclaw/plugins/token-goat-bridge.tsTypeScript bridge plugin. Fires on before_tool_call and after_tool_call. Covers image shrinking, post-edit indexing, and pre-fetch denial.
~/.openclaw/openclaw.jsonPlugin entry added under plugins.entries. Existing entries preserved.

AI automated setup

Non-interactive snippets agents can run unattended. Each one is idempotent: it checks current state before changing anything, and re-runs token-goat doctor at the end so the agent can verify success from the output.

Windows (PowerShell)

```powershell

1. Verify token-goat is reachable; reinstall if not

if (-not (Get-Command token-goat -ErrorAction SilentlyContinue)) { uv tool install token-goat }

2. If doctor flags any image codec, reinstall the bundled Pillow wheel

$doctor = token-goat doctor 2>&1 | Out-String if ($doctor -match 'Pillow codecs:.*(MISSING|FAIL)') { uv tool install --reinstall --force token-goat }

1. Verify token-goat is reachable; reinstall if not

command -v token-goat >/dev/null 2>&1 || uv tool install token-goat

2. If doctor flags any image codec, install platform packages then reinstall

need_fix=$(token-goat doctor 2>&1 | grep -E 'Pillow codecs:.*(MISSING|FAIL)' || true) if [[ -n "$need_fix" ]]; then OS="$(uname -s)" if [[ "$OS" == "Darwin" ]]; then command -v brew >/dev/null 2>&1 && brew install webp jpeg-turbo libpng elif [[ "$OS" == "Linux" ]]; then if command -v apt-get >/dev/null 2>&1; then sudo apt-get update && sudo apt-get install -y libwebp-dev libjpeg-turbo8-dev libpng-dev elif command -v dnf >/dev/null 2>&1; then sudo dnf install -y libwebp-devel libjpeg-turbo-devel libpng-devel elif command -v pacman >/dev/null 2>&1; then sudo pacman -S --noconfirm libwebp libjpeg-turbo libpng elif command -v apk >/dev/null 2>&1; then sudo apk add libwebp-dev libjpeg-turbo-dev libpng-dev fi fi uv tool install --reinstall --force token-goat fi

AI automated setup

Scripts for non-interactive setup. No prompts.

#### Windows (PowerShell) ```powershell

1. Install Windows Terminal if absent

if (-not (Get-Command wt.exe -ErrorAction SilentlyContinue)) { winget install --id Microsoft.WindowsTerminal -e --silent }

Install a complete font

if [[ "$OS" == "Darwin" ]]; then command -v brew &>/dev/null && brew install --cask font-jetbrains-mono-nerd-font elif [[ "$OS" == "Linux" ]]; then command -v apt-get &>/dev/null && sudo apt-get install -y fonts-jetbrains-mono command -v pacman &>/dev/null && sudo pacman -S --noconfirm ttf-jetbrains-mono-nerd fi

Security, privacy, and uninstall

No telemetry. No analytics. No background reporting or silent outbound connections.

Outbound network is reserved to three explicit cases:

  • First token-goat semantic call downloads the embedding model (~130 MB) into the data directory. Offline after that.
  • Google Drive API calls, only if you already authorized Drive in Claude Code. Token-goat never prompts for its own auth.
  • Image fetches from URLs: either explicit via token-goat fetch-image <url>, or when the AI agent issues a WebFetch call that returns image content — the hook intercepts and shrinks the image. The URL always originates from the agent's work, not from token-goat itself.

Security reports. See SECURITY.md. Email token-goat@dfkhelper.com; do not file as a GitHub issue. Reports are acknowledged within 7 days; coordinated disclosure with a 90-day default window.

Windows Defender (optional, Windows only). Real-time scanning slows indexing. To exclude the data folder, open PowerShell as administrator:

Add-MpPreference -ExclusionPath "$env:LOCALAPPDATA\dfk-helper\token-goat"

0x800106ba means the prompt is not elevated; reopen as administrator. On enterprise-managed Windows (domain-joined / Intune), Defender exclusions may be locked by Group Policy. The command will fail; that is expected and harmless.

Uninstall.

token-goat uninstall

Reverses everything in What gets installed?: the scheduled task or systemd unit, the registry value or .desktop or .plist, the hook entries in settings.json, the CLAUDE.md block, the skill directory. Add --codex, --gemini, --opencode, or --openclaw to also strip those integrations. Add --purge to also delete the data directory (cache, index, models, logs). Nothing else on the system depends on it.

Token-savings examples

Concrete before/after for the four interception points. Token counts use the ~4-chars-per-token rule of thumb.

1. Image — screenshot interception

``` $ ls -lh screenshot.png -rw-r--r-- 1 user user 1.2M screenshot.png

Codex CLI users

token-goat install --codex

The --codex flag patches both Claude Code and Codex CLI in one pass.

Gemini CLI users

token-goat install --target gemini

This writes hook entries into ~/.gemini/settings.json using Gemini CLI's BeforeTool / AfterTool / SessionStart / PreCompress event names. Token-goat translates between Gemini's snake_case tool names (run_shell_command, read_file, grep_search, etc.) and its internal format automatically. Image shrinking, session hints, post-edit indexing, compact assist, and bash output compression all work. To remove: token-goat uninstall --gemini.

🎯 aiskill88 AI 点评 B 级 2026-06-08

创新的Token优化工���,针对AI编程成本痛点。支持多个主流平台,实用性强。但项目规模小,需积累更多用户验证其稳定性和效果。

📚 实用指南(长尾问题)
适合谁
  • 需要 token-goat 解决具体问题的开发者与运营人员
最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境
部署方案
  • CLI:直接 npm install -g / pip install,命令行调用
  • 云端托管:可放在 Vercel / Railway / Fly.io 等 PaaS 平台
相关搜索
token-goat 中文教程token-goat 安装报错怎么办token-goat 与同类工具对比token-goat 最佳实践token-goat 适合谁用

⚡ 核心功能

👥 适合谁
  • 需要 token-goat 解决具体问题的开发者与运营人员
⭐ 最佳实践
  • 先在测试环境跑通最小用例,再接入生产数据
⚠️ 常见错误
  • API key 直接提交到 git 仓库(请用 .env 并加入 .gitignore)
  • Python 依赖冲突:建议用 venv / uv 隔离环境

👥 适合人群

AI 技术爱好者研究人员和学生开发者和工程师技术创业者

🎯 使用场景

  • 本地部署运行,保护数据隐私,满足合规要求
  • 自定义集成到现有系统,扩展技术栈能力
  • 作为开源基础组件进行商业化二次开发

⚖️ 优点与不足

✅ 优点
  • +完全开源免费,无授权费用
  • +本地部署,数据完全自主可控
  • +开发者社区支持,遇问题可查可问
⚠️ 不足
  • 安装和初始配置可能需要一定技术基础
  • 功能完整性通常不如成熟商业产品
  • 技术支持主要依赖开源社区,响应速度不稳定
⚠️ 使用须知

该工具使用 NOASSERTION 协议,商用场景请仔细阅读协议条款,必要时咨询法律意见。

AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。

建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。

📄 License 说明

📄 NOASSERTION — 请查阅原始协议条款了解具体使用限制。

🔗 相关工具推荐

🧩 你可能还需要
基于当前 Skill 的能力图谱,自动补全的工具组合

❓ 常见问题 FAQ

支持Claude Code、Codex、Gemini CLI、Cline、Windsurf、Aider等主流AI编程工具。
💡 AI Skill Hub 点评

总体来看,Token山羊 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。

📚 深入学习 Token山羊
查看分步骤安装教程和完整使用指南,快速上手这款工具
🌐 原始信息
原始名称 token-goat
原始描述 开源AI工具:Token burn reducer for Claude Code, Codex, Gemini CLI, Cline, Windsurf, Aider, C。⭐13 · Python
Topics token优化成本控制ClaudeAI编程CLI工具
GitHub https://github.com/DFKHelper/token-goat
License NOASSERTION
语言 Python
🔗 原始来源
🐙 GitHub 仓库  https://github.com/DFKHelper/token-goat

收录时间:2026-06-08 · 更新时间:2026-06-11 · License:NOASSERTION · AI Skill Hub 不对第三方内容的准确性作法律背书。