AI Skill Hub 推荐使用:Token山羊 是一款优质的AI工具。AI 综合评分 7.2 分,在同类工具中表现稳健。如果你正在寻找可靠的AI工具解决方案,这是一个值得深入了解的选择。
专为Claude Code、Gemini CLI、Cline等AI编程工具设计的Token消耗优化器。通过智能压缩和过滤,显著降低API调用成本,适合频繁使用AI编程助手的开发者和团队节省开支。
Token山羊 是一款基于 Python 开发的开源工具,专注于 token优化、成本控制、Claude 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
专为Claude Code、Gemini CLI、Cline等AI编程工具设计的Token消耗优化器。通过智能压缩和过滤,显著降低API调用成本,适合频繁使用AI编程助手的开发者和团队节省开支。
Token山羊 是一款基于 Python 开发的开源工具,专注于 token优化、成本控制、Claude 等核心功能。作为 GitHub 开源项目,它拥有活跃的社区支持和持续的版本迭代,代码完全透明可审计,支持本地部署以保护数据隐私。无论是个人使用还是集成到企业工作流,都能提供稳定可靠的解决方案。
# 方式一: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('安装成功')"
# 命令行使用
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"
<p align="center"> <img src="assets/logo.png" alt="Token-Goat" width="700"> </p>
<p align="center"> <b>85%</b> smaller reads · <b>97.4%</b> image compression · <b>130+</b> bash output filters · <b>94–99%</b> skill overhead cut · 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 KB copy reaches the model instead of 10 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> · <a href="#cli">CLI</a> · <a href="#what-gets-installed">What gets installed?</a> · <a href="#stats-display">Stats</a> · <a href="#security-privacy-and-uninstall">Security & uninstall</a> </p>
---
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.
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.
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/)
| Path | What |
|---|---|
~/.claude/settings.json | Hook 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.md | A 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.md | The token-goat skill — the same routing guidance in skill form. |
Worker autostart (one of the following, picked by platform)
| Platform | Entry |
|---|---|
| Windows | HKCU\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)
| Platform | Entry |
|---|---|
| Windows | Scheduled task token-goat-update (schtasks). |
| Linux / macOS | A crontab line tagged with # token-goat-autoupdate. |
Data directory (created on first run)
| Platform | Path |
|---|---|
| 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)
| Path | What |
|---|---|
~/.codex/config.toml | Hooks block with Codex-specific matchers (view_image|Bash, apply_patch, web_search). Existing hooks preserved. |
~/.codex/AGENTS.md | A delimited block (` … `) with the same routing guidance, adapted for Codex tool names. |
With --opencode (opencode plugin)
| Path | What |
|---|---|
~/.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)
| Path | What |
|---|---|
~/.openclaw/plugins/token-goat-bridge.ts | TypeScript bridge plugin. Fires on before_tool_call and after_tool_call. Covers image shrinking, post-edit indexing, and pre-fetch denial. |
~/.openclaw/openclaw.json | Plugin entry added under plugins.entries. Existing entries preserved. |
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.
```powershell
if (-not (Get-Command token-goat -ErrorAction SilentlyContinue)) { uv tool install token-goat }
$doctor = token-goat doctor 2>&1 | Out-String if ($doctor -match 'Pillow codecs:.*(MISSING|FAIL)') { uv tool install --reinstall --force token-goat }
command -v token-goat >/dev/null 2>&1 || uv tool install token-goat
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
Scripts for non-interactive setup. No prompts.
#### Windows (PowerShell) ```powershell
if (-not (Get-Command wt.exe -ErrorAction SilentlyContinue)) { winget install --id Microsoft.WindowsTerminal -e --silent }
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
No telemetry. No analytics. No background reporting or silent outbound connections.
Outbound network is reserved to three explicit cases:
token-goat semantic call downloads the embedding model (~130 MB) into the data directory. Offline after that.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.
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
token-goat install --codex
The --codex flag patches both Claude Code and Codex CLI in one pass.
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.
创新的Token优化工���,针对AI编程成本痛点。支持多个主流平台,实用性强。但项目规模小,需积累更多用户验证其稳定性和效果。
该工具使用 NOASSERTION 协议,商用场景请仔细阅读协议条款,必要时咨询法律意见。
AI Skill Hub 为第三方内容聚合平台,本页面信息基于公开数据整理,不对工具功能和质量作任何法律背书。
建议在沙箱或测试环境中充分验证后,再部署至生产环境,并做好必要的安全评估。
📄 NOASSERTION — 请查阅原始协议条款了解具体使用限制。
总体来看,Token山羊 是一款质量良好的AI工具,在同类工具中具备一定竞争力。AI Skill Hub 将持续追踪其更新动态,建议收藏备用,结合自身场景选择合适时机引入使用。
| 原始名称 | 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 |
收录时间:2026-06-08 · 更新时间:2026-06-11 · License:NOASSERTION · AI Skill Hub 不对第三方内容的准确性作法律背书。