openclaw 网盘下载
OpenClaw

技能详情(站内镜像,无评论)

首页 > 技能库 > OpenClaw Cost Guard (Budgets + Token-Saving Playbook)

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…

开发与 DevOps

作者:CodingPenguin44 @dasweltall

许可证:MIT-0

MIT-0 ·免费使用、修改和重新分发。无需归因。

版本:v0.1.0

统计:⭐ 4 · 2.5k · 6 current installs · 6 all-time installs

4

安装量(当前) 6

🛡 VirusTotal :良性 · OpenClaw :良性

Package:dasweltall/openclaw-cost-guard

安全扫描(ClawHub)

  • VirusTotal :良性
  • OpenClaw :良性

OpenClaw 评估

The skill is internally consistent: it only reads local OpenClaw/Clawdbot session JSONL logs, summarizes cost/token usage, optionally estimates costs from PRICE_* env vars, and provides budget exit codes — nothing in the files requests unrelated credentials, network exfiltration, or elevated persistence.

目的

Name/description (cost guard, budgets, token-saving playbook) align with the provided files. The script reads session JSONL files under ~/.openclaw and ~/.clawdbot, extracts usage/cost, aggregates by day/session, and implements budget checks and JSON/text output — exactly what the skill claims.

说明范围

SKILL.md instructs the agent to read the specified session log paths and run the included Python script with various flags; the instructions do not ask the agent to read unrelated paths, harvest environment secrets, or post data to external endpoints. The doc suggests wiring alerts to a channel (e.g., Telegram) but explicitly warns not to embed secrets and leaves implementation to the user.

安装机制

No install spec and only a single Python script are included. There are no downloads or third-party installs, and the script is plain Python (no hidden binaries or archives). This is low-risk and proportionate for the described functionality.

证书

No required env vars or credentials are declared. Optional PRICE_* env vars are reasonable and explicitly documented for cost estimation fallback. The script does not request unrelated secrets or cloud credentials.

持久

The skill is not always-enabled and makes no changes to agent/system configuration. It runs as a user-level script reading files under the user's home directory and returns nonzero exit codes for budget breaches as documented.

综合结论

This skill appears to do what it says: read OpenClaw/Clawdbot session logs and report costs. Before installing/running: confirm the session log paths (~/.openclaw and ~/.clawdbot) are where you expect logs to live, review file permissions (these logs can contain chat content), and run the included script locally to inspect output. If you wire budget alerts to external services (Telegram, email, etc.), avoid embedding API tokens in the script o…

安装(复制给龙虾 AI)

将下方整段复制到龙虾中文库对话中,由龙虾按 SKILL.md 完成安装。

请把本段交给龙虾中文库(龙虾 AI)执行:为本机安装 OpenClaw 技能「OpenClaw Cost Guard (Budgets + Token-Saving Playbook)」。简介:Track OpenClaw/Clawdbot token and cost usage from session JSONL logs (prefer re…。
请 fetch 以下地址读取 SKILL.md 并按文档完成安装:https://raw.githubusercontent.com/openclaw/skills/refs/heads/main/skills/dasweltall/openclaw-cost-guard/SKILL.md
(来源:yingzhi8.cn 技能库)

SKILL.md

打开原始 SKILL.md(GitHub raw)

---
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.
---

# 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)
```bash
python3 {baseDir}/scripts/extract_cost.py --last-days 7
```

### Today / yesterday
```bash
python3 {baseDir}/scripts/extract_cost.py --today
python3 {baseDir}/scripts/extract_cost.py --yesterday
```

### Top expensive sessions
```bash
python3 {baseDir}/scripts/extract_cost.py --top-sessions 10
```

### JSON output (for dashboards)
```bash
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:

```bash
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**:

```bash
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:

```bash
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."