← 返回 Skills 市场
oztenbot

AgentMeter

作者 oztenbot · GitHub ↗ · v0.6.4
cross-platform ✓ 安全检测通过
449
总下载
2
收藏
1
当前安装
13
版本数
在 OpenClaw 中安装
/install agent-meter
功能描述
Track API spend with intent-level attribution. Shows where your tokens go by project and purpose. Invoke with /meter for spend summary.
使用说明 (SKILL.md)

/meter — API Spend Tracker

When the user invokes /meter, run a SINGLE bash command that handles everything: setup check, backfill, and summary. One prompt, one approval.

Execution

Run this single bash command:

bash "$(for d in "$HOME/.claude/skills/agent-meter" "$HOME/.claude/skills/meter" ".claude/skills/meter" ".claude/skills/agent-meter"; do [ -f "$d/meter.sh" ] && echo "$d/meter.sh" && break; done)"

If meter.sh is not found, tell the user the script wasn't found and suggest reinstalling.

Format the output as a clean markdown summary for the user.

If the user passes arguments like /meter --by model or /meter --last 7d, append them: bash .../meter.sh --last 7d

Setup

Install from ClawHub into your project:

clawhub install agent-meter --dir .claude/skills

Then run /meter — it handles everything automatically:

  • Copies the session-end hook to .claude/hooks/
  • Creates or updates .claude/settings.json with the Stop hook
  • Backfills any existing Claude Code sessions
  • Shows your spend summary

That's it. Future sessions are tracked automatically via the Stop hook.

Dashboard sync (optional)

To sync spend data to the hosted dashboard at dashboard.agentmeter.io:

bash .claude/skills/agent-meter/meter-sync.sh --setup

The setup wizard will prompt for your API key and agent name. Get a key from the dashboard's Machines page. After setup, sync anytime with:

bash .claude/skills/agent-meter/meter-sync.sh

What the scripts do

  • meter.sh — Single entry point for /meter. Checks hook installation, backfills if needed, shows spend summary. All in one script, one permission prompt.

  • meter-session-end.sh (Stop hook): Parses the current session's transcript for per-message token usage. Detects model (opus/sonnet/haiku), calculates cost with model-specific pricing including cache tier pricing, writes a single session_summary record. Deduplicates by session_id — safe across session pause/resume. No network calls, no secrets access, jq dependency only.

  • meter-parse-claude-sessions.sh (backfill): Scans all Claude Code transcripts in ~/.claude/projects/*/*.jsonl. Extracts the same usage data as the hook. Deduplicates against existing records by session_id. Safe to re-run — only processes new sessions. No network calls, no secrets access, jq dependency only.

Query Examples

SPEND="$HOME/.agent-meter/spend.jsonl"

# Spend by project
jq -s 'group_by(.project) | map({project: .[0].project, cost: (map(.cost_usd) | add), sessions: length}) | sort_by(-.cost)' "$SPEND"

# Spend by model
jq -s 'group_by(.model) | map({model: .[0].model, cost: (map(.cost_usd) | add), sessions: length}) | sort_by(-.cost)' "$SPEND"

# Today's spend
jq -s "[.[] | select(.ts | startswith(\"$(date -u +%Y-%m-%d)\"))] | map(.cost_usd) | add" "$SPEND"

# Top 10 most expensive sessions
jq -s 'sort_by(-.cost_usd) | .[:10] | .[] | "\(.cost_usd | . * 100 | round / 100) \(.project) \(.total_calls) calls \(.ts | split("T")[0])"' "$SPEND" -r

Schema

All records are session_summary type in ~/.agent-meter/spend.jsonl.

Field Required Description
type yes Always session_summary
ts yes ISO 8601 timestamp (session start)
api yes api.anthropic.com
model yes Model identifier (e.g. claude-opus-4-6)
session_id yes Claude Code session UUID
project yes Project directory name
total_calls yes Number of assistant messages
tokens_in yes Input tokens (non-cached)
tokens_out yes Output tokens
cache_creation yes Cache creation input tokens
cache_read yes Cache read input tokens
cost_usd yes Estimated cost (model-aware pricing)
source yes hook or session_parse
purpose no Human-readable intent (manual tag)
intent no Machine tags (manual)

Cost Calculation

Per-1M-token pricing:

Model Input Output Cache Create Cache Read
Opus $15 $75 $18.75 (1.25x) $1.50 (0.1x)
Sonnet $3 $15 $3.75 (1.25x) $0.30 (0.1x)
Haiku $0.25 $1.25 $0.3125 (1.25x) $0.025 (0.1x)
安全使用建议
This skill appears to do what it claims, but review and consent to the local changes before installing: 1) Back up .claude/settings.json (the script will modify or create it to add a Stop hook). 2) Inspect the included scripts (meter-session-end.sh, meter-parse-claude-sessions.sh, meter.sh, meter-sync.sh) yourself — they read ~/.claude/projects transcripts and write ~/.agent-meter/spend.jsonl. 3) The optional meter-sync.sh will upload spend records to api.agentmeter.io using an API key you provide; only enter a key if you trust that endpoint. 4) Ensure jq (and curl for sync) are available. 5) If you want to be cautious, run meter.sh / meter-parse-claude-sessions.sh in dry-run modes or inspect the created ~/.agent-meter files before enabling sync.
功能分析
Type: OpenClaw Skill Name: agent-meter Version: 0.6.4 The agent-meter skill bundle is a utility designed to track and estimate Anthropic API costs for Claude Code sessions. It functions by parsing local session transcripts in `~/.claude/projects` to extract token usage metadata and installing a 'Stop' hook in `.claude/settings.json` to automate future tracking. While the `meter-sync.sh` script allows for data exfiltration to an external dashboard (`api.agentmeter.io`), it is an optional feature requiring manual setup, and the transmitted data is limited to usage statistics (token counts, model IDs, and project names) rather than the actual content of the transcripts or source code.
能力评估
Purpose & Capability
Name/description (API spend tracking for Claude sessions) align with the scripts: they scan ~/.claude/projects for transcripts, install a session-end hook, compute token costs, and write records to ~/.agent-meter/spend.jsonl. Required files accessed and operations are appropriate for the stated goal.
Instruction Scope
SKILL.md directs the agent to run the included meter.sh which installs a Stop hook (copies meter-session-end.sh -> .claude/hooks/) and backfills transcripts. Those actions modify .claude/settings.json and write to ~/.agent-meter; this is expected for hooking/tracking but is a permanent local change the user should consent to. The hook and backfill parse full session transcripts (including user content) — that's necessary for per-message token accounting.
Install Mechanism
No remote install/downloads or obscure URLs. The skill is instruction-only (no external installer). All code is included in the bundle and runs locally; no extract-from-URL or third-party package installs are present.
Credentials
The skill requests no environment variables or credentials. The optional sync feature asks the user interactively for a dashboard API key which is stored locally at ~/.agent-meter/sync.json (chmod 600). That credential is proportional to the optional uploading feature.
Persistence & Privilege
The skill writes files to ~/.agent-meter, copies a hook into .claude/hooks/, and edits/creates .claude/settings.json to register the Stop hook. These are required for ongoing capture but do grant the skill persistent local presence and the ability to read session transcripts. always:false (not force-included) and model invocation is normal.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install agent-meter
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /agent-meter 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.6.4
Fix display name on ClawHub
v0.6.3
Fix null field crash on sync (default totalCalls/tokensIn/tokensOut/costUsd to 0); remove chmod requirement from docs (use bash prefix instead)
v0.6.2
Fix ARG_MAX crash when syncing 1000+ sessions — pipe payload via stdin instead of CLI arg. Restores full SKILL from v0.6.0 after accidental overwrite in v0.3.1.
v0.3.1
Fix ARG_MAX crash when syncing 1000+ sessions — pipe payload via stdin instead of CLI arg
v0.6.1
Fix display name from Meter to AgentMeter
v0.6.0
Add dashboard sync docs to SKILL.md, meter.sh hints about sync when unconfigured, chmod instructions
v0.5.0
Auto-create settings.json Stop hook on first /meter run. Simplified install docs to single clawhub command.
v0.4.0
Add meter-sync.sh for hosted backend sync, remove dev-mode auth fallback
v0.3.0
v0.3.0: Single-script entry point (meter.sh), fixed model detection, session dedup, backfill from Claude Code transcripts, removed dead meter-capture.sh dependency
v0.2.0
Major: session-end hook now parses Claude Code transcript for real session spend. Captures all token usage (input, output, cache creation, cache read) with cost estimation. No longer limited to explicit curl commands — every Claude Code session gets metered.
v0.1.2
Auto-install hooks on first /meter invocation. Detects missing hooks, copies from bundled scripts, merges into settings.json. No manual setup needed.
v0.1.1
Bundle all scripts (meter-capture.sh, meter-session-end.sh, meter-parse-sessions.sh) into the skill package. Update SKILL.md to reference bundled files instead of external paths. Add script descriptions explaining what each hook does.
v0.1.0
Initial release: automatic API spend capture with intent-level attribution. PostToolUse hooks for Claude Code, session JSONL parser for OpenClaw. All runtimes write to ~/.agent-meter/spend.jsonl. Use /meter for spend summary.
元数据
Slug agent-meter
版本 0.6.4
许可证
累计安装 1
当前安装数 1
历史版本数 13
常见问题

AgentMeter 是什么?

Track API spend with intent-level attribution. Shows where your tokens go by project and purpose. Invoke with /meter for spend summary. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 449 次。

如何安装 AgentMeter?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install agent-meter」即可一键安装,无需额外配置。

AgentMeter 是免费的吗?

是的,AgentMeter 完全免费(开源免费),可自由下载、安装和使用。

AgentMeter 支持哪些平台?

AgentMeter 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 AgentMeter?

由 oztenbot(@oztenbot)开发并维护,当前版本 v0.6.4。

💬 留言讨论