Use when the user explicitly asks to analyze token waste, costs, or API bills. Finds duplicate tool calls, context bloat, model mismatch, and heartbeat waste...
编程
Token Cost Guard
试用Monitor agent token usage and model cost from the active ecosystem's own records, compare the current run with the previous snapshot, and send an alert repor...
它能做什么
Monitor agent token usage and model cost from the active ecosystem's own records, compare the current run with the previous snapshot, and send an alert repor...
技能文档
Token Cost Guard
Use this skill to compute agent token costs from the current runtime's own usage records and warn in Chinese reports when spend has increased too much since the previous run.
Quick Start
Run a one-shot check for today:
python3 skills/token-cost-guard/scripts/token_cost_guard.py --threshold-cny 20
Force a source when needed:
python3 skills/token-cost-guard/scripts/token_cost_guard.py --source hermes --threshold-cny 20
python3 skills/token-cost-guard/scripts/token_cost_guard.py --source openclaw --threshold-cny 20
When installed by Hermes and running from the skill directory:
python3 scripts/token_cost_guard.py --threshold-cny 20
Initialize a baseline without alerting:
python3 skills/token-cost-guard/scripts/token_cost_guard.py --init-only
Run every 60 seconds:
python3 skills/token-cost-guard/scripts/token_cost_guard.py --watch-interval 60 --threshold-cny 20
Check the previous hour and stay silent unless the hour exceeds 10 CNY:
python3 skills/token-cost-guard/scripts/token_cost_guard.py \
--period previous-hour \
--alert-mode total \
--threshold-cny 10 \
--quiet-ok \
--alert-exit-zero
Send an alert through OpenClaw when the threshold is exceeded:
python3 skills/token-cost-guard/scripts/token_cost_guard.py \
--threshold-cny 20 \
--send-openclaw \
--channel feishu \
--target
OpenClaw hourly command alert example:
python3 ~/.openclaw/skills/token-cost-guard/scripts/token_cost_guard.py \
--source openclaw \
--period previous-hour \
--alert-mode total \
--threshold-cny 10 \
--quiet-ok \
--alert-exit-zero \
--send-openclaw \
--channel feishu \
--target
Hermes hourly script alert example:
~/.hermes/scripts/hermes_hourly_alert.sh
Behavior
--source autoselects Hermes when running under Hermes (HERMES_*environment or~/.hermes/skillspath), otherwise OpenClaw.- OpenClaw source reads
~/.openclaw/agents/*/sessions/*.jsonland prefers native cost fields such asusage.cost.total,usage.costCny, orusage.costUsdbefore estimating from token prices. - Hermes source reads
~/.hermes/logs/agent.log*API-call usage lines and uses Hermesstate.dbsession costs (actual_cost_usdorestimated_cost_usd) when present, allocated across log calls by token share. It falls back tostate.dbsession aggregates when logs have no matching records. - Defaults to today's Asia/Shanghai date.
- Supports
--period day,--period current-hour, and--period previous-hour; useprevious-hourfor hourly cron alerts. - Computes cost by model and by runtime group (
Agentsfor OpenClaw,Hermes Sourcessuch ascron,weixin, orclifor Hermes). - Compares current total cost with the previous snapshot in the selected runtime's
token-cost-guard/state.json. - Alerts when either condition is true:
- absolute cost delta is greater than
--threshold-cny - percentage delta is greater than
--threshold-percent
- absolute cost delta is greater than
- With
--alert-mode total, alerts when the current time window's known cost is greater than--threshold-cny; this is the recommended mode for "last hour exceeded budget" cron jobs. - With
--quiet-ok, prints nothing when the run is OK; this is useful for Hermescron --no-agent --scriptdelivery. - With
--alert-exit-zero, returns exit code 0 even when an alert fires; use it for cron jobs so a successful alert is not marked as a failed run. - Writes Chinese Markdown reports to the selected runtime's
token-cost-guard/reports/.
Hermes Compatibility
The bundled script is stdlib-only and can run under Codex, OpenClaw, Hermes, cron, or a plain shell.
Environment variables:
OPENCLAW_STATE_DIRorOPENCLAW_HOME: override the OpenClaw state directory.HERMES_HOME: override the Hermes home directory; defaults to~/.hermes.OPENCLAW_TOKEN_COST_GUARD_STATE_DIR: override state/report storage.HERMES_STATE_DIRorHERMES_DATA_DIR: when present and source is Hermes, default state/report storage goes under/token-cost-guard.OPENCLAW_TOKEN_COST_THRESHOLD_CNY: default absolute alert threshold.OPENCLAW_TOKEN_COST_THRESHOLD_PERCENT: default percent alert threshold.TOKEN_COST_GUARD_USD_CNYorTOKEN_REPORT_USD_CNY: USD/CNY conversion for Hermesstate.dbcosts and any OpenClaw native USD cost fields.
Hermes tap metadata lives in skill.json; ClawHub/OpenClaw marketplace metadata lives in clawhub.json.
Pricing
Cost source priority is: runtime-native billing fields first, then the price table after applying any --pricing-file overrides.
The script embeds current DeepSeek official CNY prices per 1M tokens:
deepseek-v4-pro: cache hit 0.025, cache miss 3, output 6deepseek-v4-flash: cache hit 0.02, cache miss 1, output 2deepseek-chatanddeepseek-reasonerare treated as v4-flash compatibility aliases.
Known local CNY estimates are included for Kimi models. Unknown models are listed as unpriced unless OpenClaw or Hermes recorded a usable native cost.
Use --pricing-file to override or add prices. JSON shape:
{
"provider/model-or-model-id": {
"cache_hit_cny_per_million": 0.02,
"cache_miss_cny_per_million": 1.0,
"output_cny_per_million": 2.0
}
}
Output Contract
When reporting results, include:
- current total known cost
- previous total and delta when available
- alert status and threshold
- top models by cost
- top agents by cost
- unpriced models, if any
相关技能
Know exactly where your AI tokens go. Multi-provider tracking, budget alerts, and a local REST API—all in one dashboard. It reads Claude Code's own credential file to query Anthropic usage, calls provider usage APIs, and (opt-in) parses local session transcripts. Serves a REST API on localhost. See Permissions, Data Flow & Consent.
Agent token usage optimizer. Input usage logs, transcript excerpts, model bills, or runtime traces; output token/cost breakdown, waste patterns, context comp...
把 OpenClaw 每次模型调用的 token 用量与费用落到 SQLite 的审计型账本。
Token 守护者是面向 AI Agent 的 token 成本优化系统,针对"压缩过度损失质量、语义缓存命中率低、缺乏模型路由、预算不可见不可控"四大高频痛点而设计。它用三层缓存(精确匹配/语义匹配/模式匹配)+ 自适应压缩 + 模型路由 + 预算守护,在不牺牲响应质量的前提下降低 50-80% 的 token...
Estimate LLM task token usage, cost, and duration using rule-based classification and optional local profile data without external dependencies.