Skip to content

dwylq/aicost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aicost

PyPI Python 3.9+ License: MIT

Universal AI coding cost analyzer — scan Claude Code, Cline, Roo Code, Cursor, Codex CLI, and more for token usage and costs. No API key required. Try it now at aicost.pages.dev.

Why aicost?

If you use multiple AI coding tools (Claude Code + Cursor + others), ccusage only covers Claude Code. aicost scans all your AI coding sources in one pass and produces a unified cost report.

aicost ccusage
Claude Code Yes Yes
Cline Yes No
Roo Code Yes No
Cursor Yes No
GitHub Copilot Yes No
Codex CLI Yes No
Cache-aware pricing Yes Partial
HTML dashboard Yes No
CSV export Yes No
Cost alerting Yes No
Budget tracking Yes No
Monthly comparison Yes No
JSONL export Yes No
Multi-source unified report Yes No
Web analyzer Yes No

Quick Start

pip install aicost

# Analyze all detected sources
aicost scan

# Analyze Claude Code sessions
aicost scan --source claude

# Analyze Cline tasks (auto-detected)
aicost scan --source cline

# Analyze Roo Code tasks (auto-detected)
aicost scan --source roo

# Analyze Cursor (export data from Cursor API first)
aicost scan --source cursor --cursor-export ./cursor-export.json

# Analyze GitHub Copilot (export usage from GitHub settings)
aicost scan --source copilot --copilot-export ./copilot-usage.json

# Generate HTML report
aicost scan --html report.html

# Export as JSONL (pipe to other tools)
aicost scan --jsonl

# Analyze Codex CLI sessions (auto-detected at ~/.codex/state)
aicost scan --source codex

# Export as CSV
aicost scan --csv report.csv

# Alert if cost exceeds $50
aicost scan --alert 50

# Track monthly budget with burn rate projection
aicost scan --budget 100

# Compare this month vs last month
aicost scan --compare

# Combine budget tracking + comparison
aicost scan --budget 100 --compare

# View pricing reference
aicost pricing
aicost pricing claude-sonnet-4-20250514

Features

  • No API key needed — reads local files only, no telemetry
  • Multi-source support — Claude Code JSONL, Cline, Roo Code, Cursor API exports, GitHub Copilot, Codex CLI SQLite
  • Web analyzer — instant cost analysis at aicost.pages.dev, no installation needed
  • Cache-aware pricing — accounts for cache read/write costs that most tools miss
  • Budget tracking — set a monthly budget, see burn rate and month-end projection
  • Monthly comparison — this month vs last month with per-project/model deltas
  • Terminal report — instant cost breakdown with rich formatting
  • HTML dashboard — optional visual report with Chart.js graphs
  • Cost alerting — terminal + JSON alerts when spending exceeds threshold
  • Cost trends — see daily spending over time
  • Built-in pricing database — Anthropic, OpenAI, Google, Qwen, DeepSeek, Mistral

Supported Data Sources

Source Format Notes
Claude Code JSONL Auto-detected at ~/.claude/projects/
Cline JSON Auto-detected at ~/.cline/state/taskHistory.json
Roo Code JSON Auto-detected at VS Code extension globalStorage
Cursor JSON/JSONL export Export from Cursor API or dashboard
GitHub Copilot JSON export Export from GitHub Copilot settings
Codex CLI SQLite Auto-detected at ~/.codex/state

Cursor Export

Cursor stores token usage data via their web API (not locally). To analyze Cursor usage:

  1. Export usage data from Cursor's dashboard or API
  2. Save as JSON/JSONL — any file in the Cursor API response format
  3. Run: aicost scan --cursor-export ./cursor-usage.json

The parser accepts:

  • Single event JSON: {"timestamp": ..., "model": ..., "tokenUsage": {...}}
  • API response JSON: {"usageEventsDisplay": [...]}
  • JSONL: one event per line

GitHub Copilot Export

GitHub Copilot usage data can be exported from your Copilot settings:

  1. Export usage data from GitHub Copilot settings
  2. Save as JSON — the exported file contains usage events with token counts
  3. Run: aicost scan --source copilot --copilot-export ./copilot-usage.json

The parser accepts:

  • Array of events: [{"model": "...", "prompt_tokens": N, "completion_tokens": N}]
  • Wrapped response: {"data": [...]}
  • JSONL: one event per line

Cline

Cline stores task history as a JSON array in ~/.cline/state/taskHistory.json (CLI) or the VS Code extension globalStorage directory. Each task record includes token counts, cache usage, and cost:

  • Auto-detected — run aicost scan --source cline or aicost scan (all sources)
  • Custom pathaicost scan --source cline --path /custom/taskHistory.json

The parser reads: tokensIn, tokensOut, cacheWrites, cacheReads, totalCost, modelId, and project path.

Roo Code

Roo Code (forked from Cline) stores task history in the same format at its VS Code extension globalStorage directory:

  • Auto-detected — run aicost scan --source roo or aicost scan (all sources)
  • Custom pathaicost scan --source roo --path /custom/path

Both Cline and Roo Code use identical HistoryItem schema, so one parser covers both tools.

Codex CLI

Codex CLI stores thread metadata in a SQLite database at ~/.codex/state:

  • Auto-detected — run aicost scan --source codex or aicost scan (all sources)
  • Custom pathaicost scan --source codex --path /custom/state

Note: Codex stores total tokens_used without input/output split. We estimate 70% input / 30% output (typical for coding agents) and calculate cost from model pricing.

Web Analyzer

No installation? No problem. Visit aicost.pages.dev to:

  • Upload your AI tool data files (JSON/JSONL)
  • Paste raw data directly
  • Instant analysis with cost breakdown by project and model
  • Export CSV for spreadsheets
  • 100% client-side — your data never leaves your browser

Output

AI Coding Cost Report
=====================
Period: 2026-04-01 to 2026-04-16

Total Cost: $12.34
Total Tokens: 1,234,567
  Input:    987,654
  Output:   246,913

By Project:
  pr-explainer-action    $4.56  (37.0%)
  ogpixel                $3.21  (26.0%)

By Model:
  qwen3.6-plus    $8.90  (72.1%)
  sonnet          $2.34  (19.0%)

Daily Trend:
  2026-04-14  $3.45  ████████████████
  2026-04-15  $5.67  ██████████████████████████
  2026-04-16  $3.22  ███████████████

Pricing

Pricing database includes: Anthropic Claude, OpenAI GPT/o-series, Google Gemini, Qwen, DeepSeek, Mistral.

See all pricing reference: aicost pricing Look up a specific model: aicost pricing claude-sonnet-4-20250514

Cost Alerting

Set a spending threshold to catch cost overruns:

aicost scan --alert 50

If your total cost exceeds $50, aicost prints a red alert and outputs a structured JSON alert to stderr for piping to monitoring tools.

JSONL Export

Export individual usage entries as JSONL for use in other tools (spreadsheets, monitoring, custom dashboards):

aicost scan --jsonl > usage.jsonl

Each line is a JSON object with timestamp, model, project, token counts, and cost.

CSV Export

Export your usage data as a CSV file for analysis in spreadsheets:

aicost scan --csv report.csv

The CSV includes: timestamp, model, project, source, token counts, and cost. Plus summary sections for totals, by-project, and by-model breakdowns.

Budget Tracking

Set a monthly budget to track spending, see your daily burn rate, and get a projected month-end cost:

aicost scan --budget 100

Output includes:

  • Remaining budget — how much you have left
  • Daily burn rate — average daily spend
  • Projected month-end — estimated total if current pace continues
  • Status indicator — green (under), yellow (warning at >75%), red (over budget)

Monthly Comparison

Compare this month's AI coding costs against last month:

aicost scan --compare

Shows:

  • Cost delta — absolute and percentage change
  • Token delta — usage volume change
  • Per-project changes — which projects cost more/less
  • Per-model changes — spending shift across models

About

Universal AI coding cost analyzer — scan Claude Code, Cursor, and more for token usage and costs

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors