Query Claude API usage and cost reports from the command line. Secure macOS Keychain storage for Admin API key. Table/JSON output.
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install claude-cost-cli或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install claude-cost-cli⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/claude-cost-cli/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: claude-cost-cli description: Query Claude API usage and cost reports from the command line. Secure macOS Keychain storage for Admin API key. Table/JSON output. metadata: {"clawdbot":{"emoji":"📊","os":["macos"],"requires":{"bins":["claude-cost","node"]},"install":[{"id":"npm","kind":"shell","command":"npm install -g claude-cost-cli","bins":["claude-cost"],"label":"Install claude-cost-cli via npm"}],"source":"https://github.com/cyberash-dev/claude-cost-cli"}} ---
A CLI for querying Anthropic Admin API usage and cost data. Requires an Admin API key (sk-ant-admin...) from Claude Console → Settings → Admin Keys. Credentials are stored in macOS Keychain.
Requires Node.js >= 18 and macOS. The package is fully open source under the MIT license: https://github.com/cyberash-dev/claude-cost-cli
npm install -g claude-cost-cli
The npm package is published with provenance attestation, linking each release to its source commit via GitHub Actions. You can verify the published contents before installing:
npm pack claude-cost-cli --dry-run
Install from source (if you prefer to audit the code before running):
git clone https://github.com/cyberash-dev/claude-cost-cli.git
cd claude-cost-cli
npm install && npm run build && npm link
After installation the claude-cost command is available globally.
claude-cost config set-key # Interactive prompt: enter Admin API key (masked)
claude-cost usage # Token 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
Store API key (interactive masked prompt, validates sk-ant-admin prefix):
claude-cost config set-key
Show stored key (masked):
claude-cost config show
Remove key from Keychain:
claude-cost config remove-key
claude-cost usage # Last 7 days, daily, grouped by model
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 --model claude-sonnet-4 # Filter by model
claude-cost usage --api-keys apikey_01Rj,apikey_02Xz # Filter by API key IDs
claude-cost usage --group-by model,api_key_id # Group by multiple dimensions
claude-cost usage --bucket 1h # Hourly granularity (1d, 1h, 1m)
JSON output (for scripting):
claude-cost usage --json
claude-cost usage --period 30d --json
Output columns: Date, Model, Input Tokens, Cached Tokens, Output Tokens, Web Searches.
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 output (for scripting):
claude-cost cost --json
claude-cost cost --sum --json
Output columns: Date, Description, Model, Amount (USD), Token Type, Tier.
usage| Flag | Description | Default | |------|-------------|---------| | --from | Start 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 | | --model | Filter by model(s), comma-separated | all | | --api-keys | Filter by API key ID(s), comma-separated | all | | --group-by | Group by model, api_key_id, workspace_id, service_tier | model | | --bucket | Bucket width: 1d, 1h, 1m | 1d | | --json | Output as JSON | false |
cost| Flag | Description | Default | |------|-------------|---------| | --from | Start 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 | Output total cost only | false | | --json | Output as JSON | false |
The following properties are by design and can be verified in the source code:
claude-cost-cli). By design, never written to disk in plaintext. See src/infrastructure/keychain-credential-store.ts for the implementation.api.anthropic.com over HTTPS. No other outbound connections are made. See src/infrastructure/anthropic-usage-repository.ts and src/infrastructure/anthropic-cost-repository.ts.This CLI wraps the Anthropic Admin API:
GET /v1/organizations/usage_report/messagesGET /v1/organizations/cost_reportDocumentation: https://platform.claude.com/docs/en/build-with-claude/usage-cost-api
安装 Claude Cost Cli 后,可以对 AI 说这些话来触发它
Help me get started with Claude Cost Cli
Explains what Claude Cost Cli does, walks through the setup, and runs a quick demo based on your current project
Use Claude Cost Cli to query Claude API usage and cost reports from the command line
Invokes Claude Cost Cli with the right parameters and returns the result directly in the conversation
What can I do with Claude Cost Cli in my data & analytics workflow?
Lists the top use cases for Claude Cost Cli, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/claude-cost-cli/ 目录(个人级,所有项目可用),或 .claude/skills/claude-cost-cli/(项目级)。重启 AI 客户端后,用 /claude-cost-cli 主动调用,或让 AI 根据上下文自动发现并使用。
Claude Cost Cli 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Claude Cost Cli 可免费安装使用。请查阅仓库了解许可证信息。
Query Claude API usage and cost reports from the command line. Secure macOS Keychain storage for Admin API key. Table/JSON output.
Claude Cost Cli 属于「Data & Analytics」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my data & analytics tasks using Claude Cost Cli
Identifies repetitive steps in your workflow and sets up Claude Cost Cli to handle them automatically