openclaw-cost-guard
Track OpenClaw/Clawdbot token and cost usage from session JSONL logs (prefer real usage.cost when present), generate daily/weekly summaries and top expensive sessions, and run budget checks (exit code on breach). Use to monitor spend, enforce budgets via cron/alerts, and apply a token-saving playbook to reduce output/tool-call cost.
- License 许可
- MIT
- 最近更新
- 2026-04-05
- Stars
- ★ 7
- Forks
- 1
01 前言 Front Matter
- name
- openclaw-cost-guard
- description
- Track OpenClaw/Clawdbot token and cost usage from session JSONL logs (prefer real usage.cost when present), generate daily/weekly summaries and top expensive sessions, and run budget checks (exit code on breach). Use to monitor spend, enforce budgets via cron/alerts, and apply a token-saving playbook to reduce output/tool-call cost.
02 资源文件 3
- 参考文档_meta.json328 B
- 参考文档README.md1.4 KB
- 脚本scripts/extract_cost.py9.7 KB
03 SKILL.md 正文
OpenClaw Cost Guard
Use this skill when you need:
- accurate cost reports (daily/weekly/lifetime)
- top expensive sessions
- guardrails to reduce token burn (without changing config unless user asks)
1) Data source (important)
Prefer session JSONL logs (they contain per-call usage, often with real USD cost):
- OpenClaw:
~/.openclaw/agents/*/sessions/*.jsonl - Legacy/compat:
~/.clawdbot/agents/*/sessions/*.jsonl
Do not estimate from “current context window” style token fields.
2) Quick commands
Daily costs (last 7 days)
python3 {baseDir}/scripts/extract_cost.py --last-days 7
Today / yesterday
python3 {baseDir}/scripts/extract_cost.py --today
python3 {baseDir}/scripts/extract_cost.py --yesterday
Top expensive sessions
python3 {baseDir}/scripts/extract_cost.py --top-sessions 10
JSON output (for dashboards)
python3 {baseDir}/scripts/extract_cost.py --last-days 30 --json
3) If cost is missing (fallback estimate)
Some providers may omit usage.cost. You can provide per-1M-token prices:
export PRICE_INPUT=1.75
export PRICE_OUTPUT=14
export PRICE_CACHE_READ=0.175
export PRICE_CACHE_WRITE=0
python3 {baseDir}/scripts/extract_cost.py --last-days 7
4) Budget alerts
The extractor can run as a budget check:
python3 {baseDir}/scripts/extract_cost.py --today --budget-usd 5
- If budget is exceeded, it prints an ALERT and exits with code 2 (default).
- For non-failing checks:
python3 {baseDir}/scripts/extract_cost.py --today --budget-usd 5 --budget-mode warn
Wiring it to a cron alert (recommended)
Run it daily (or hourly) and if exit code is 2, send yourself a Telegram message. (Implementation depends on your OpenClaw channel setup; do not embed secrets in scripts.)
5) Token-saving playbook (teach the AI)
When the user says “use as few tokens as possible”, apply:
- Default response budget: 1–6 lines, bullets > paragraphs
- Ask 1 question max (only if truly blocking)
- Progressive disclosure: offer details only if asked
- Tool calls: batch; avoid repeated
status/browser calls - No log dumps into chat; summarize + point to file path
- Hard limits: max 3 web iterations (search/fetch) per task
Optional phrasing to keep yourself in check:
"Answer in <=6 lines. If more is needed, ask permission."
04 同仓库更多 Skills
zyfai
Earn yield on any Ethereum wallet on Base, Arbitrum, and Plasma. Use when a user wants passive DeFi yield on their funds. Deploys a non-custodial subaccount (Safe) linked to their EOA, enables automated yield optimization, and lets them deposit/withdraw anytime.
zerion-api
暂无简介
zerion-api-skill
暂无简介
zerion-api-mcp
暂无简介
yahoo-finance-forex
Fetches real-time FOREX news and market data from Yahoo Finance for major currency pairs (EUR/USD, GBP/USD, USD/JPY, etc.). Analyzes sentiment and provides trading context.
yahoo-finance
This skill should be used when the user asks to "get stock prices", "check stock quotes", "look up earnings", "get financial data", "find trending stocks", or needs stock market data from Yahoo Finance.