微算力 · API 导航与自营网关
API 接入 EN
未登录登录
📊

CodexBar 本地成本分析助手

Model Usage · v1.0.0
专业技能 安全 S 级 榜单 #43 作者 steipete 公开目录收录
34.1k 下载 108 安装 170.4k 收藏 167 浏览

简介

CodexBar CLI 的本地模型成本分析助手,支持 Codex/Claude 的单模型或全模型用量汇总,纯本地处理无数据外泄。

原始描述

Use CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.

通过你的 Agent 添加

点「快速安装」复制一段指令,粘给你正在用的 Agent(Claude Code、Codex、OpenClaw 等),它会自己完成安装。

或者手动安装

Claude Codeunzip -o skill.zip -d ~/.claude/skills/model-usage-14443/
其它 Agent解压到它自己的 skills 目录,目录名用 model-usage-14443

包里是 SKILL.md 加作者附带的文件,解压后目录名就是技能名。 技能申请的权限由作者决定,装之前请确认它能读什么、能执行什么。

中文使用说明 来自收录源

核心功能

model-usage 是一个轻量级的 CLI 封装工具,专为 CodexBar 用户设计,用于解析和汇总本地存储的 AI 模型使用成本数据。它通过调用 codexbar cost --format json 命令获取原始数据,并提供两种分析模式:

  • 当前模式(current):识别最近一日成本最高的模型,快速了解最新使用的主力模型
  • 全模型模式(all):汇总所有历史模型的累计成本,适合长期成本追踪和预算规划

显著优点

  1. 零依赖架构:仅使用 Python 3 标准库(json、subprocess、argparse),彻底规避供应链攻击风险
  2. 本地隐私优先:所有数据处理在本地完成,不触碰任何外部 API,符合 GDPR 本地处理原则
  3. 多格式输出:支持易读的文本表格和结构化的 JSON 输出(--format json --pretty),便于脚本集成
  4. 灵活输入:既可直接调用 codexbar CLI,也支持从文件或 stdin 读取预存 JSON
  5. 开发者可信:由 Peter Steinberger(PSPDFKit 创始人)维护,T2 级可信来源

潜在局限

  • macOS 独占:当前仅支持 Darwin 系统,Linux/Windows 用户需等待官方 CLI 适配
  • 令牌粒度缺失:CodexBar 输出不提供模型级令牌拆分,仅能分析成本维度
  • 错误提示简陋:JSON 解析失败时的错误信息不够详细,对 malformed 输入友好度有限
  • 版本耦合:未内置 codexbar CLI 版本检查,格式变更可能导致兼容性问题

适合人群

  • 使用 CodexBar 监控 OpenAI Codex 或 Anthropic Claude 成本的 macOS 开发者
  • 需要将成本数据集成到自动化工作流或月度报告的工程团队
  • 注重数据隐私、偏好本地处理敏感使用数据的个人用户

常规风险提示

  • 前置依赖:必须预先安装 CodexBar(brew install --cask steipete/tap/codexbar),否则 Skill 将报错
  • subprocess 边界:虽然调用受控,但若 codexbar CLI 本身存在漏洞,可能间接影响 Skill
  • 输入验证:通过 --input 传入不可信 JSON 文件可能导致解析异常,建议仅使用 codexbar 生成的数据

技能正文


name: model-usage description: Use CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON. metadata: {"clawdbot":{"emoji":"📊","os":["darwin"],"requires":{"bins":["codexbar"]},"install":[{"id":"brew-cask","kind":"brew","cask":"steipete/tap/codexbar","bins":["codexbar"],"label":"Install CodexBar (brew cask)"}]}}

Model usage

Overview

Get per-model usage cost from CodexBar's local cost logs. Supports "current model" (most recent daily entry) or "all models" summaries for Codex or Claude.

TODO: add Linux CLI support guidance once CodexBar CLI install path is documented for Linux.

Quick start

  1. Fetch cost JSON via CodexBar CLI or pass a JSON file.
  2. Use the bundled script to summarize by model.
python {baseDir}/scripts/model_usage.py --provider codex --mode current
python {baseDir}/scripts/model_usage.py --provider codex --mode all
python {baseDir}/scripts/model_usage.py --provider claude --mode all --format json --pretty

Current model logic

  • Uses the most recent daily row with modelBreakdowns.
  • Picks the model with the highest cost in that row.
  • Falls back to the last entry in modelsUsed when breakdowns are missing.
  • Override with --model <name> when you need a specific model.

Inputs

  • Default: runs codexbar cost --format json --provider <codex|claude>.
  • File or stdin:
codexbar cost --provider codex --format json > /tmp/cost.json
python {baseDir}/scripts/model_usage.py --input /tmp/cost.json --mode all
cat /tmp/cost.json | python {baseDir}/scripts/model_usage.py --input - --mode current

Output

  • Text (default) or JSON (--format json --pretty).
  • Values are cost-only per model; tokens are not split by model in CodexBar output.

References

  • Read references/codexbar-cli.md for CLI flags and cost JSON fields.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

cost-trackingcli-wrapperlocal-datacodexclaudemacos-onlypython-stdlibprivacy-focused

同类 Skill