Claude Cost Cli — Claude Cost 命令行工具
v1查询 Claude API usage and cost 报告s from the command line. 安全 macOS KeychAIn storage for Admin API key. Table/JSON 输出.
运行时依赖
安装命令
点击复制技能文档
claude-cost-命令行工具
A 命令行工具 for 查询ing Anthropic Admin API usage and cost data. Requires an Admin API key (sk-ant-admin...) from Claude Console → 设置tings → Admin Keys. 凭证s are stored in macOS KeychAIn.
安装ation
Requires Node.js >= 18 and macOS. The package is fully open source under the MIT license: https://github.com/cyberash-dev/claude-cost-命令行工具
npm 安装 -g claude-cost-命令行工具
The npm package is published with provenance attestation, linking each release to its source commit via GitHub Actions. You can 验证 the published contents before 安装ing:
npm pack claude-cost-命令行工具 --dry-运行
安装 from source (if you prefer to 审计 the code before 运行ning):
git clone https://github.com/cyberash-dev/claude-cost-命令行工具.git cd claude-cost-命令行工具 npm 安装 && npm 运行 build && npm link
After 安装ation the claude-cost command is avAIlable globally.
Quick 启动 claude-cost config 设置-key # Interactive prompt: enter Admin API key (masked) claude-cost usage # 令牌 usage for the last 7 days claude-cost cost # Cost breakdown for the last 7 days claude-cost cost --sum # Total spend for the last 7 days
API Key Management
Store API key (interactive masked prompt, 验证s sk-ant-admin prefix):
claude-cost config 设置-key
Show stored key (masked):
claude-cost config show
移除 key from KeychAIn:
claude-cost config 移除-key
Usage 报告s claude-cost usage # Last 7 days, dAIly, grouped by 模型 claude-cost usage --period 30d # Last 30 days claude-cost usage --from 2026-01-01 --to 2026-01-31 # Custom date range claude-cost usage --模型 claude-sonnet-4 # 过滤器 by 模型 claude-cost usage --API-keys APIkey_01Rj,APIkey_02Xz # 过滤器 by API key IDs claude-cost usage --group-by 模型,API_key_id # Group by multiple dimensions claude-cost usage --bucket 1h # Hourly granularity (1d, 1h, 1m)
JSON 输出 (for scripting):
claude-cost usage --json claude-cost usage --period 30d --json
输出 columns: Date, 模型, 输入 令牌s, 缓存d 令牌s, 输出 令牌s, 网页 搜索es.
Cost 报告s claude-cost cost # Last 7 days, grouped by description claude-cost cost --period 30d # Last 30 days claude-cost cost --from 2026-01-01 --to 2026-01-31 # Custom date range claude-cost cost --group-by workspace_id,description # Group by workspace and description claude-cost cost --sum # Total cost only
JSON 输出 (for scripting):
claude-cost cost --json claude-cost cost --sum --json
输出 columns: Date, Description, 模型, Amount (USD), 令牌 Type, Tier.
Flag Reference usage Flag Description Default --from 启动 date (YYYY-MM-DD or ISO) 7 days ago --to End date (YYYY-MM-DD or ISO) now --period Shorthand period (7d, 30d, 90d) 7d --模型 <模型s> 过滤器 by 模型(s), comma-separated all --API-keys 过滤器 by API key ID(s), comma-separated all --group-by Group by 模型, API_key_id, workspace_id, 服务_tier 模型 --bucket Bucket width: 1d, 1h, 1m 1d --json 输出 as JSON false cost Flag Description Default --from 启动 date (YYYY-MM-DD or ISO) 7 days ago --to End date (YYYY-MM-DD or ISO) now --period Shorthand period (7d, 30d, 90d) 7d --group-by Group by workspace_id, description description --sum 输出 total cost only false --json 输出 as JSON false Security and Data Storage
The following properties are by de签名 and can be verified in the source code:
Admin API key: stored exclusively in macOS KeychAIn (服务: claude-cost-命令行工具). By de签名, never written to disk in plAIntext. See src/infrastructure/keychAIn-凭证-store.ts for the implementation. No config files: all 设置tings are passed via 命令行工具 flags. Nothing is stored on disk besides the KeychAIn entry. Network: by de签名, the API key is only sent to API.anthropic.com over HTTPS. No other outbound connections are made. See src/infrastructure/anthropic-usage-仓库.ts and src/infrastructure/anthropic-cost-仓库.ts. Scope: the Admin API key grants read-only 访问 to organization usage and cost data. It cannot modify billing, 创建 API keys, or 访问 conversation content. This is a property of the Anthropic Admin API, not just this 命令行工具. No caching: 查询 结果s are not 缓存d or persisted to disk. The 命令行工具 writes 输出 to stdout only. API Reference
This 命令行工具 wraps the Anthropic Admin API:
Usage: 获取 /v1/organizations/usage_报告/messages Cost: 获取 /v1/organizations/cost_报告
Documentation: https://平台.claude.com/docs/en/build-with-claude/usage-cost-API