技能 人工智能 AI 代理成本追踪账本

AI 代理成本追踪账本

v20261022
cost-ledger
该工具提供 Claude、Codex 和 Grok 等 AI 代理的统一成本视图。通过读取本地日志计算支出、Token 用量及缓存命中率,支持按时间、项目和提供商筛选。自动标记未定价模型,支持 JSON 或 Markdown 输出。数据完全本地处理,确保隐私安全,适用于审计 AI 使用成本及对比不同提供商的定价。
获取技能
101 次下载
概览

Cost Ledger

Reads the logs the agents already wrote (~/.claude/projects, $CODEX_HOME or ~/.codex) and prices them from data/prices.json (dated, editable).

Run

node ${CLAUDE_PLUGIN_ROOT}/scripts/ledger.mjs --since 7d
node ${CLAUDE_PLUGIN_ROOT}/scripts/ledger.mjs --provider codex --format json

One mission, or one project

--from and --to (ISO times) cut the window and --project <absolute path> keeps one project's rows; the console's mission page uses them for a mission's spend. An explicit --from/--to replaces the default 7-day look-back.

Read the result correctly

  • USD and Codex credits are never added. GPT-6 Codex models are priced in credits; their cached-input rate is unpublished, so the figure is an upper bound.
  • Estimates at list price, not bills. Subscriptions bill by window, not by token. /usage is authoritative for the live Claude session; the Console or provider dashboard is authoritative for invoices.
  • Unpriced models are listed, never counted as $0. Say so, and offer to add them to data/prices.json.
  • Counting rules (why numbers differ from naive sums): Claude messages are de-duplicated by message.id + requestId; Codex uses deltas of the running total_token_usage (never also last_token_usage), cached input is a subset of input, and forked rollouts are de-duplicated.
  • Claude transcript output tokens can under-count streamed output.

If the log directory is missing, say so; do not invent numbers.

信息
分类 人工智能
名称 cost-ledger
版本 v20261022
大小 1.94KB
更新时间 2026-10-23
语言