Skip to content

About

Local CLI & Flight Recorder for AI coding tools (Claude Code, Codex) — token costs, 5h rate-limit burn windows, prompt-cache efficiency, stray key guard, and drifted instruction sync.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

agentmeter

Your AI coding tools keep their receipts on your own disk and never show them to you. agentmeter reads those logs and answers the questions the tools won't: what did that cost, why did I run out, and what did the agent get wrong.

Runs entirely locally. Reads log files, writes nothing but its own config, sends nothing anywhere. Zero dependencies.


Install

git clone https://github.com/ARAVINDHRAJA123/agentmeter.git
cd agentmeter
bash install.sh

That creates a private virtualenv for the tool and links it onto your PATH, so agentmeter works from any directory. It does not touch your system Python and does not edit your shell profile.

Verify:

agentmeter --version
agentmeter --help      # lists every command with examples

Homebrew Python refuses pip install --user (PEP 668), which is why the installer uses a dedicated virtualenv — the same approach pipx takes.

To uninstall: rm $(command -v agentmeter) and delete this folder.


Step 1 — see what it can read

agentmeter tools
TOOL         STATE          NOTES
claude-code  usage tracked  per-message token counts
codex        usage tracked  cumulative per-session token counts
antigravity  partial        sessions and models only -- not priced
cursor       not installed  not installed

Start here. It tells you which tools agentmeter found and how completely each one can be measured — so you know what the later numbers do and don't cover.

Tool Reads Token counts
Claude Code ~/.claude/projects/**/*.jsonl Full, per message
Codex ~/.codex/sessions/**/rollout-*.jsonl Full, per session
Antigravity ~/.gemini/antigravity/conversations/*.db No — protobuf-encoded
Cursor detection only Not implemented

Antigravity's token counts sit inside protobuf blobs that can't be decoded without the schema, so its sessions are counted but never priced. Cursor wasn't installed on the machine this was built against, so rather than ship a parser written from guesswork it reports only whether Cursor is present.


Step 2 — where the money went

agentmeter usage

Defaults to the last 30 days, grouped by tool. Change either:

agentmeter usage --days 7                 # last week
agentmeter usage --days 0                 # all time
agentmeter usage --by model               # which model costs most
agentmeter usage --by project             # which repo costs most
agentmeter usage --by session --top 10    # the 10 most expensive runs
agentmeter usage --by day                 # daily trend

API-EQUIV is not a bill. On a subscription you were not charged this. It is what the same tokens would have cost at pay-as-you-go rates — the value you drew from your plan. A model with no price on file is reported as unpriced and excluded from totals, never silently counted as free.

Export for a spreadsheet:

agentmeter usage --days 0 --by project --csv > usage.csv

Step 3 — why you ran out

This is the part no other tool does.

agentmeter limits --days 0
WHEN              TOKENS BEFORE    WORTH  SESSIONS  PROJECT
2026-08-09 00:33         164.9M  $108.03         2  ats-checker
2026-08-11 14:20         156.8M   $83.12         3  repurpose-ai
...
20 rate limit(s). Median burn before a refusal: 89.8M

Claude Code records every 429 it receives. agentmeter finds them and shows the usage in the 5 hours before each one — the window your limits are actually scoped to. After a few refusals you can see roughly where your ceiling sits.

agentmeter never claims to know your plan's limit. It isn't written anywhere on disk. Showing you "68% of your limit" would be the most useful-looking lie the tool could tell. What you get instead is your own burn next to the moments you were genuinely refused.

Then see the shape of it:

agentmeter burn --days 7
BLOCK START       TOKENS   WORTH  SESS  429
Mon 07 Sep 00:00   89.3M  $41.56     3    1  ################
Mon 07 Sep 15:00  137.7M  $79.72     2    -  ########################

Usage per rolling 5-hour block, with a bar chart. Blocks containing a recorded rate limit are marked in red. Use it to spot the pattern — running three sessions in parallel is usually what precedes a refusal.

agentmeter burn --hours 1 --days 1      # finer grain
agentmeter burn --limit 50              # more history

Step 4 — why it's expensive

agentmeter cache --days 0 --by model
KEY                HIT RATE  FROM CACHE  CACHE WRITES  FRESH IN       SAVED
claude-opus-5           98%       2.26B         53.0M     10.8K  $10,110.77
claude-sonnet-4-6        0%           0         42.0K         3      $-0.03

Cache reads cost 10% of full input rate; cache writes cost 125%. So:

  • High hit rate (>80%) — healthy. Your prompt prefix is stable and being reused.
  • Low hit rate — the prefix keeps changing, so every turn re-pays full price for context it already sent. This is the most expensive thing that can silently go wrong.
  • Negative saving — you paid the 25% write premium to build a cache nothing ever read back. Shown in red.

Step 5 — are you on the right plan

agentmeter value --days 30
claude-code
  Tokens used were worth $1,900.95 at API rates, per 30 days
  PLAN       PRICE   RATIO
  Max 20x  $200.00   9.50x  plan is cheaper than API
codex
  Tokens used were worth $0.27 at API rates, per 30 days
  Plus      $20.00   0.01x  API would be cheaper

Every tier is shown with its ratio rather than one being recommended, because plan tiers are rate-limited, not token-metered — token counts tell you what your usage was worth, not which tier your rate limits require.


Step 6 — catch the expensive mistakes

Stray API keys

agentmeter keyguard

A leftover ANTHROPIC_API_KEY in your shell profile bills every session at API rates while the subscription you already pay for sits idle — and nothing tells you until the invoice. This checks your environment, your shell startup files, your project's .env files, and each tool's own auth state.

It also flags a .env holding a key that git does not ignore — one commit from being published.

Key values are never printed, stored, or transmitted. Findings show a fingerprint like sk-ant...4f2a — enough to identify which key, not enough to use it.

Hallucinated and undeclared imports

agentmeter lint                        # whole project
agentmeter lint --changed              # only your uncommitted diff
agentmeter lint /path/to/repo

Checks every import against what is actually resolvable: the standard library, the project's own virtualenv, its declared dependencies, and its own modules — including code under backend/, cli/ and similar that tests import by bare name.

It verifies resolvability, not existence. An unresolved import is either a package the agent invented or a dependency nobody declared; both are worth fixing and the finding doesn't pretend to know which. Imports guarded by try/except ImportError are reported at low severity.

For imports your host runtime provides:

# pyproject.toml
[tool.agentmeter]
lint_ignore = ["airflow", "pendulum"]   # supplied by the scheduler image

or agentmeter lint --ignore airflow,pendulum.

Drifted instruction files

agentmeter memsync                          # report
agentmeter memsync --from CLAUDE.md         # dry run
agentmeter memsync --from CLAUDE.md --apply # write

Every agent reads a different file for the same information — CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, .github/copilot-instructions.md. This reports the ones that look like copies that diverged (≥60% identical but no longer the same).

Files that merely differ are left alone: keeping a short CLAUDE.md and a long GEMINI.md is a legitimate setup, not a defect.

--apply requires an explicit --from, writes a .bak beside anything it overwrites, and prints the plan first. Add --create to also create files that don't exist yet.


Multi-IDE agent & rule context audit

agentmeter context                     # current repo
agentmeter context /path/to/repo --json

Audits agent, rule, skill, and hook files across VS Code Copilot, Claude Code, Cursor, OpenAI Codex, and Windsurf for silent-skip traps and context bloat:

  • Plain .md files in .cursor/rules/ (Cursor ignores them; requires .mdc)
  • Windsurf rules exceeding the hard 12,000-character truncation limit
  • AGENTS.md over Codex's 32 KiB project_doc_max_bytes budget (Codex truncates the rest) or heavy always-loaded context (> 24 KB)
  • Skills only in .github/skills/ (Claude Code reads .claude/skills/, Codex reads .agents/skills/) and mirrored skill copies that have drifted apart
  • Invalid .claude/agents/*.md or .github/agents/*.agent.md frontmatter and SKILL.md mismatches
  • Dead local file references in root instruction files and malformed hook JSON configs

Step 7 — the visual version

The tool is a command-line program, but it can write a report you open in a browser:

agentmeter report --open

One self-contained .html file (~14 KB) with the totals, a burn chart, cache efficiency, and your rate limits. No server, no network, no JavaScript — it works offline, and it follows your system light/dark theme.

agentmeter report --days 90 -o ~/Desktop/september.html

Your usage data stays inside the file. Nothing is uploaded.


Step 8 — all of it at once

agentmeter doctor
Tools: claude-code, codex, antigravity*
Last 30 days: 22 sessions, 4.77B tokens, $1,923.32 at API rates
Rate limited 12 time(s); typically after 87.5M tokens in 5 hours.
Caching saved $12,766.13

Stray API keys
  HIGH  GEMINI_API_KEY is exported from a shell startup file
        ~/.zshrc:4

Run this weekly. It's the whole tool in one screen.


Using it in CI

Exit codes are stable:

Code Meaning
0 clean
1 at least one high-severity finding
2 usage error (bad flag, or --changed outside a git repo)
- run: pip install -e . && agentmeter lint --changed

--changed fails loudly rather than silently scanning everything if the diff can't be determined — otherwise CI would gate on files you never touched while claiming it only looked at your diff.

Every command supports --json for scripting:

agentmeter limits --json | jq '.rate_limits[].tokens_in_prior_5h'

Two accounting traps

Both were found by checking against a real 412 MB corpus, and both produce believable wrong answers rather than obvious ones. If you write your own tooling against these logs, you will hit them.

Claude Code duplicates usage records. Sidechains, resumed sessions and compaction replay earlier turns into the transcript. In the corpus, 34,310 usage records held only 15,789 unique (message.id, requestId) pairs — summing them over-reports by 117%. agentmeter dedupes on that pair.

Codex token counts are cumulative. Each token_count event restates the session total: one real rollout ran 23,223 → 48,188 → … → 1,182,826 across 25 events. Adding them inflates that session about twelvefold. agentmeter takes the final reading per session.

There is a third, subtler one: Codex's input_tokens is inclusive of cached_input_tokens. Pricing them separately without subtracting charges cached tokens at 10× their real rate.

All three are pinned by tests in tests/test_adapters.py.


Configuration

Prices are a bundled snapshot with the date they were verified. Override them — and plan prices — in ~/.config/agentmeter/pricing.json:

{
  "models": {
    "gpt-6-astra": { "input": 5.0, "output": 25.0, "cache_read": 0.5 }
  },
  "subscriptions": {
    "claude-code": [["Max 20x", 200.0]]
  }
}

cache_read defaults to 10% of input and cache_write to 125% if omitted.


Development

python3 -m venv .venv && .venv/bin/pip install pytest
PYTHONPATH=src .venv/bin/python -m pytest tests/ -q

109 tests. The ones in test_adapters.py and test_analyse.py are the ones that matter — they pin the accounting behaviour against wrong answers that look right.


Limitations

Stated plainly, because a measurement tool that hides its gaps is worse than no tool:

  • Antigravity token counts and Cursor usage are unavailable. Visible in agentmeter tools, not hidden behind a plausible number.
  • OpenAI long-context surcharges are not modelled. Requests over 272K input tokens bill at 2× input / 1.5× output; those are under-reported.
  • Prices are a snapshot. Verify against vendor pricing pages before treating any figure as authoritative.
  • value compares worth, not entitlement. It cannot tell you which plan tier your rate limits require.
  • limits only sees refusals a tool wrote down. Claude Code records them; the others may not.
  • lint overlaps with ruff and tsc for pure Python/TS projects. Its distinct value is cross-checking against the project's declared dependencies and its own venv, which those don't do.
  • Subscription usage is not billed per token. Every dollar figure here is a comparison, never an invoice.

About

Local CLI & Flight Recorder for AI coding tools (Claude Code, Codex) — token costs, 5h rate-limit burn windows, prompt-cache efficiency, stray key guard, and drifted instruction sync.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages