Fixing Codex Cache Double-Counting: Auditing Local AI Agent Tokens Across Host & WSL2

1 min read

How Agent Usage Radar audits Codex, Claude Code, and local AI tokens across Host and WSL2 with lock-free SQLite WAL and Zero-PII output.

Fixing Codex Cache Double-Counting: Auditing Local AI Agent Tokens Across Host & WSL2
On this page

When you run OpenAI Codex, Claude Code, Cursor, Antigravity, and Hermes side by side across macOS, Windows, and WSL2, tracking real AI spend gets messy fast. Most naive local usage trackers simply sum input\\\\\\\_tokens and cached\\\\\\\_input\\\\\\\_tokens as separate numbers — and end up silently inflating token totals and distorting cache hit ratios.

The Inclusive vs. Disjoint Cache Accounting Trap

OpenAI Codex reports input\\\\\\\_tokens inclusively (it already contains cached\\\\\\\_input\\\\\\\_tokens and cache writes), while Anthropic Claude Code and Hermes report cache reads as a disjoint bucket. Treating both schemas identically double-counts cached tokens on every heavy coding session.

Agent Usage Radar (v1.1.2) solves this by normalizing each adapter's exact token buckets before aggregation:

\\\\- OpenAI Codex: subtracts cached\\\\\\\_input\\\\\\\_tokens + cache\\\\\\\_write\\\\\\\_input\\\\\\\_tokens from input\\\\\\\_tokens, diffs cumulative total\\\\\\\_token\\\\\\\_usage snapshots, and handles compaction segment resets cleanly.

\\\\- Claude Code: deduplicates streaming JSONL updates by message.id + requestId and splits uncached input, cache reads, cache writes, and output into four separately priced buckets.

\\\\- Honest unsplit & unknown-SKU boundaries: pruned aggregate-only threads stay explicitly unsplit, and unverified models remain unpriced rather than fabricating ratios or rates.

Lock-Free SQLite WAL Reads & Zero-PII Architecture

Built purely on Node.js 24 (node:sqlite) with zero npm dependencies, Agent Usage Radar reads live local databases across Host and WSL2 without SQLITE\\\\\\\_BUSY lock contention or file copying. Every exported JSON report, offline HTML dashboard, and stdio MCP response passes through a strict Zero-PII projection (projectPublicReport + assertZeroPii) that strips paths, hostnames, emails, prompts, and credentials.

Quick Start (100% Local Read-Only)

Run a forever-free MIT CLI audit with date-range filtering:

npx agent-usage-radar scan --from 2026-11-01 --to 2026-11-30

Or launch the local loopback dashboard (127.0.0.1) with interactive date presets and live USD/CNY FX conversion:

npx agent-usage-radar ui

You can also connect the built-in zero-dependency stdio MCP server (npx -y agent-usage-radar mcp) so coding agents can inspect their own spend via get\\\\\\\_ai\\\\\\\_usage\\\\\\\_summary, get\\\\\\\_model\\\\\\\_cost\\\\\\\_breakdown, and check\\\\\\\_daily\\\\\\\_token\\\\\\\_budget.

GitHub (78/78 tests passing, 100/100 HOL Plugin Scanner): https://github.com/augustfu-droid/agent-usage-radar

npm: https://www.npmjs.com/package/agent-usage-radar

Benchmark & Docs: https://kestreldevtools.site/radar.html

HOL Registry Listing: https://hol.org/registry/plugins/augustfu-droid%2Fagent-usage-radar

All articles

Keep exploring

The engineering desk continues across the ecosystem: security research on shipping agents safely, and plugins that put the standards to work.