DEV Community

Huang振华
Huang振华

Posted on

How Much Are Claude Code, Codex & OpenCode Actually Costing You? (Zero-Dependency Local Spend Auditor)

If you bounce between Claude Code, OpenAI Codex CLI, Google Antigravity, OpenCode, xAI Grok CLI, and Cline / Roo Code, you quickly run into a blind spot: every agent stores local token telemetry in a completely different format — and even uses incompatible prompt-cache accounting rules.

  • Anthropic / Antigravity / OpenCode log uncached input, cache_read, and cache_write as separate additive buckets (total_input = input + cache_read + cache_write).
  • OpenAI / Codex CLI / Grok CLI log cached_tokens as an inclusive subset already inside input_tokens (plus Codex silently compresses older sessions into ~/.codex/archived_sessions/*.jsonl.zst, while OpenCode v2 migrated from JSON files to a local SQLite opencode.db).

To see my real 30-day token burn without uploading a single prompt or file path anywhere, I built a zero-dependency, 100% read-only Python stdlib auditor (audit_ai_spend.py) + an open-source API vs. GPU Break-Even Calculator.

Run It in 1 Command (Zero pip install, 100% Local Read-Only)

curl -fsSL https://ai-cost-radar-nlu.pages.dev/audit_ai_spend.py | python3 - --days 30 --lang en --region global
Enter fullscreen mode Exit fullscreen mode

(Security tip: you can inspect the script first with curl -fsSL https://ai-cost-radar-nlu.pages.dev/audit_ai_spend.py | less — it uses only Python's standard library json, sqlite3 in ?mode=ro read-only URI mode, and in-memory zstd decoding.)

Supported Local Coding & Agent Clients

Client Local Telemetry Source Accounting Nuance Handled
Claude Code ~/.claude/projects/**/*.jsonl Streaming message.id dedupe + additive cache math
OpenAI Codex ~/.codex/sessions/**/*.jsonl + archived_sessions/*.jsonl.zst In-memory .zst decode + response_id retry dedupe (skips duplicate event_msg:token_count)
Google Antigravity ~/.gemini/antigravity/brain/*/.system_generated/logs/transcript.jsonl Reads PLANNER_RESPONSE steps & skips transcript_full.jsonl to prevent 2x double-counting
OpenCode ~/.local/share/opencode/opencode.db + legacy JSON Read-only SQLite ?mode=ro with per-row timestamp cutoff + legacy JSON ID dedupe
xAI Grok CLI ~/.grok/sessions/*/*/updates.jsonl + summary.json Filters turn_completed events with inclusive inputTokens + cacheCreationTokens
Cline / Roo Code globalStorage/.../tasks/*/ui_messages.json Extracts api_req_started cost & additive cache reads/writes
WorkBuddy / Qwen ~/.workbuddy, ~/.codebuddy, ~/.qwen, ~/.qoder Multi-turn JSONL & read-only SQLite session aggregation

3 Surprises From Auditing 47,000+ Real Local Agent Calls

  1. Codex .jsonl.zst archives hide most of your 30-day history: Scanning only uncompressed ~/.codex/sessions missed over 60% of my 30-day Codex calls that had been rotated into .jsonl.zst.
  2. 90%+ prompt-cache hit rates completely change the API vs. Self-Hosted GPU math: Naive token calculators multiply total context tokens by full uncached input rates, overestimating agent bills by 4x–6x. Once you account for real cache read discounts, renting a dedicated 24GB GPU pod (e.g., RTX 4090 / A100 on RunPod) only beats Pay-As-You-Go APIs when post-cache spend crosses ~$125/month — below that, Pay-As-You-Go or a lightweight ~$5/month LiteLLM semantic-cache proxy wins.
  3. A single runaway debug loop can eat 25% of your monthly budget: In the companion web tool, you can drag-and-drop multiple .jsonl / .csv logs locally in your browser (zero server upload) and toggle "Exclude #1 Spike Session" to compare your steady-state daily burn and export a zero-code LiteLLM config.yaml.

Try the Interactive Calculator & Source Code

(Transparency note: the open-source repo has zero trackers; selected cloud host cards on the web directory may carry partner referral links at identical official catalog prices.)

If your daily-driver coding CLI stores token logs in another path or schema, drop a comment below and I'll add exact parser support for it!

Top comments (0)