claude-cost-cliQuery Claude API usage and cost reports from the command line. Secure macOS Keychain storage for Admin API key. Table/JSON output.
Install via ClawdBot CLI:
clawdbot install cyberash-dev/claude-cost-cliInstall claude-cost-cli via npm:
Install claude-cost-cli via npmRequires:
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
Generated Mar 1, 2026
A freelance developer uses the CLI to monitor API usage and costs for multiple client projects, ensuring they stay within budget and can invoice accurately. By filtering by API key IDs and grouping by model, they track expenses per client and model type, with JSON output for automated reporting.
A startup offering a SaaS product integrated with Claude uses the CLI to analyze usage patterns and costs over the last 30 days, optimizing resource allocation. They use custom date ranges and grouping by workspace to identify high-cost features and adjust pricing tiers accordingly.
An enterprise IT team uses the CLI to audit Claude API usage across departments for compliance and cost control. They leverage hourly granularity and filtering by model to detect anomalies, with secure Keychain storage ensuring sensitive API keys are protected on macOS systems.
A university research team uses the CLI to track Claude API costs for a long-term AI study, using period flags and sum outputs to manage grant funds. They rely on JSON output for integration with budgeting tools and ensure no data is cached for security.
A digital marketing agency uses the CLI to generate cost reports for clients using Claude-powered services, customizing outputs with group-by flags for transparency. They automate reports via scripting with JSON flags and verify installation via provenance attestation for trust.
Offer a free tier with basic usage tracking and charge for advanced features like custom date ranges, multi-group reporting, or automated alerts. Revenue comes from subscription upgrades as users scale their Claude API monitoring needs.
Provide consulting services to help businesses integrate the CLI into their workflows, offering custom scripts, training, and support. Revenue is generated through hourly rates or project-based fees for setup and optimization.
License the CLI as a white-label tool for large organizations to rebrand and use internally, with added features like enhanced security audits or API extensions. Revenue comes from licensing fees and ongoing maintenance contracts.
💬 Integration Tip
Use the --json flag for easy integration with data pipelines or dashboards, and ensure Node.js >= 18 is installed on macOS for compatibility.
Remote-control tmux sessions for interactive CLIs by sending keystrokes and scraping pane output.
Command-line tool to manage Google Workspace services including Gmail, Calendar, Drive, Sheets, Docs, Slides, Contacts, Tasks, People, Groups, and Keep.
Runs shell commands inside a dedicated tmux session named claw, captures, and returns the output, with safety checks for destructive commands.
A modern text-based browser. Renders web pages in the terminal using headless Firefox.
Write robust, portable shell scripts. Use when parsing arguments, handling errors properly, writing POSIX-compatible scripts, managing temp files, running commands in parallel, managing background processes, or adding --help to scripts.
NotebookLM CLI wrapper via `node {baseDir}/scripts/notebooklm.mjs`. Use for auth, notebooks, chat, sources, notes, sharing, research, and artifact generation/download.