Skip to content

thedotmack/claude-mem / plugin/skills/agent-cost-report

agent-cost-report

Verified

Believable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.

FileKindSize
.gitignoreother100 B
CHECKSUMS.txtmarkdown2.1 KB
SKILL.mdskill md21.3 KB
VERIFICATION.mdmarkdown12.3 KB
scripts/acr.pyexecutablescript12.2 KB
scripts/acr/__init__.pyscript105 B
scripts/acr/behavior.pyscript17.5 KB
scripts/acr/classify.pyscript5.5 KB
scripts/acr/costs.pyscript6.3 KB
scripts/acr/devices.pyscript5.4 KB
scripts/acr/evidence.pyscript9.2 KB
scripts/acr/labels.pyscript7.6 KB
scripts/acr/measure.pyscript5.6 KB
scripts/acr/mistakes.pyscript23.1 KB
scripts/acr/owner.pyscript2.9 KB
scripts/acr/patterns.pyscript26.0 KB
scripts/acr/period.pyscript3.8 KB
scripts/acr/prices.pyscript5.0 KB
scripts/acr/render.pyscript52.7 KB
scripts/acr/rollup.pyscript31.7 KB
scripts/acr/rules.jsonconfig3.5 KB
scripts/acr/rules.pyscript4.5 KB
scripts/acr/sample.pyscript3.6 KB
scripts/acr/snapshot.pyscript2.0 KB
scripts/acr/sync.pyscript3.7 KB
scripts/acr/transcripts.pyscript7.4 KB
scripts/acr/wins.pyscript21.0 KB
scripts/tests/_db.pyscript3.6 KB
scripts/tests/_paths.pyscript337 B
scripts/tests/fixtures/codex/sessions/2026/09/18/rollout-codex-1.jsonlother664 B
scripts/tests/fixtures/make_report_fixtures.pyscript2.0 KB
scripts/tests/fixtures/prices_sample.jsonconfig611 B
scripts/tests/fixtures/projects/-workspace-proj-a/sess-aaaa.jsonlother2.9 KB
scripts/tests/fixtures/projects/-workspace-proj-b/sess-bbbb.jsonlother537 B
scripts/tests/fixtures/report-1day.jsonconfig20.1 KB
scripts/tests/fixtures/report-30day.jsonconfig48.1 KB
scripts/tests/fixtures/report-7day.jsonconfig29.1 KB
scripts/tests/fixtures/report-empty.jsonconfig13.8 KB
scripts/tests/fixtures/report-session.jsonconfig16.6 KB
scripts/tests/test_behavior.pyscript29.6 KB
scripts/tests/test_devices.pyscript5.9 KB
scripts/tests/test_labels.pyscript8.6 KB
scripts/tests/test_measure.pyscript6.8 KB
scripts/tests/test_period.pyscript7.0 KB
scripts/tests/test_prices.pyscript5.3 KB
scripts/tests/test_render.pyscript12.1 KB
scripts/tests/test_render_encoding.pyscript1.5 KB
scripts/tests/test_rollup.pyscript20.0 KB
scripts/tests/test_snapshot.pyscript2.8 KB
scripts/tests/test_sync.pyscript2.5 KB
scripts/tests/test_transcript_encoding.pyscript2.7 KB
scripts/tests/test_transcripts.pyscript8.1 KB
scripts/tests/test_wins.pyscript15.7 KB
verification/precision-2026-09-26.jsonconfig308 B

scripts/acr/prices.py

View on GitHub
"""OpenRouter public price list and per-model rate lookup (plan Phase 1.5).

fetch() copied from /workspace/weekly-cost-workflow/fetch_prices.py:3-7 (extended with
cache_write_1h); norm()/rate() copied from weekly_report.py:23-42 with the PRICE-TABLE
fallback dropped (hard-coded path, plan Phase 0 A) and one rule change for 1h cache writes.
Never prices silently at zero: a failed fetch without --prices is an error.
"""
import datetime as dt
import json
import os
import re
import urllib.request

SOURCE_URL = "https://openrouter.ai/api/v1/models"
PRICES_FILE = "prices.json"


class PriceError(RuntimeError):
    pass


def fetch(url=SOURCE_URL, timeout=60):
    """GET the public model list (no key) -> {fetched, source, models}. USD per 1M tokens.
    The response is read as a stream into json.load; only the pricing fields are kept."""
    try:
        with urllib.request.urlopen(url, timeout=timeout) as resp:
            # copied from fetch_prices.py:4: d = json.load(urllib.request.urlopen(URL))["data"]
            d = json.load(resp)["data"]
    except Exception as ex:
        raise PriceError(f"could not fetch {url}: {ex}") from ex
    # copied from fetch_prices.py:5-7, plus cache_write_1h (pricing.input_cache_write_1h, live on some Anthropic models)
    f = lambda v: None if v in (None, "") else float(v) * 1e6
    out = {m["id"]: dict(input=f((m.get("pricing") or {}).get("prompt")), output=f((m.get("pricing") or {}).get("completion")),
           cache_read=f((m.get("pricing") or {}).get("input_cache_read")), cache_write=f((m.get("pricing") or {}).get("input_cache_write")),
           cache_write_1h=f((m.get("pricing") or {}).get("input_cache_write_1h"))) for m in d}
    del d
    # copied from fetch_prices.py:9 (fetched / source / models shape)
    return dict(fetched=dt.datetime.now().astimezone().isoformat(), source=url, models=out)


def load(path):
    """A saved prices.json (from `acr.py prices`), for offline runs and the Phase 8 comparison."""
    try:
        with open(path, encoding="utf-8-sig") as fh:      # a saved or hand-edited table; tolerate an editor BOM
            p = json.load(fh)
    except OSError as ex:
        raise PriceError(f"could not read --prices file {path}: {ex}") from ex
    except ValueError as ex:
        raise PriceError(f"--prices file {path} is not valid JSON: {ex}") from ex
    if not isinstance(p, dict) or not isinstance(p.get("models"), dict):
        raise PriceError(f"--prices file {path} has no 'models' table")
    p.setdefault("source", SOURCE_URL)
    p.setdefault("fetched", None)
    p["loaded_from"] = os.path.abspath(path)
    return p


def write(prices, outdir):
    os.makedirs(outdir, exist_ok=True)
    path = os.path.join(outdir, PRICES_FILE)
    with open(path, "w", encoding="utf-8") as fh:
        json.dump(prices, fh, indent=1)
    return path


def ensure(outdir, prices_file=None, url=SOURCE_URL):
    """Use --prices <file> when given, else fetch live. Writes <outdir>/prices.json. Raises PriceError."""
    p = load(prices_file) if prices_file else fetch(url)
    return write(p, outdir), p


# copied from weekly_report.py:23-30; the PRICE-TABLE alias map (hard-coded path) is replaced by an optional dict
def norm(model, aliases=None):
    m = (aliases or {}).get(model, model)
    if "/" not in m:
        m = re.sub(r"-(\d{8})$", "", m)                       # drop date suffix
        m = re.sub(r"(\d)-(\d)$", r"\1.\2", m)                # 5-1 -> 5.1, 4-5 -> 4.5
        pref = "anthropic/" if m.startswith("claude") else "openai/" if m.startswith("gpt") else "google/" if m.startswith("gemini") else ""
        m = pref + m
    return m


# copied from weekly_report.py:31-42 (the PRICE-TABLE branch at :39-41 is dropped: hard-coded path).
# One change (plan 1.5): 1h cache write = explicit cache_write_1h when listed, else 2 x input
# (the old rule at weekly_report.py:95). price_source records which rule fired for each derived field.
def rate(model, models, aliases=None):
    """Returns dict(key, input_usd_per_mtok, output_usd_per_mtok, cache_read, cache_write, cache_write_1h,
    source, price_source) in USD / 1M tokens, or None (unpriced)."""
    if not model or model.startswith("<"): return None
    k = norm(model, aliases)
    if k in models and models[k].get("input") is not None:
        r = models[k]; i = r["input"]; src = {}
        if r.get("cache_read") is not None: cache_read = r["cache_read"]; src["cache_read"] = "listed"
        else: cache_read = i * 0.1; src["cache_read"] = "input*0.1"
        if r.get("cache_write") is not None: cache_write = r["cache_write"]; src["cache_write"] = "listed"
        else: cache_write = i * 1.25; src["cache_write"] = "input*1.25"
        if r.get("cache_write_1h") is not None: cache_write_1h = r["cache_write_1h"]; src["cache_write_1h"] = "listed"
        else: cache_write_1h = i * 2; src["cache_write_1h"] = "input*2"
        return dict(key=k, input_usd_per_mtok=i, output_usd_per_mtok=r.get("output"),
                    cache_read=cache_read, cache_write=cache_write, cache_write_1h=cache_write_1h,
                    source="openrouter-public-list", price_source=src)
    return None
deprecation-and-migrationaddyosmani/agent-skillsManages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
performance-optimizationaddyosmani/agent-skillsOptimizes application performance across frontend, backend, queries, and databases. Use when performance requirements exist, when you suspect performance regressions, when Core Web Vitals or load times need improvement, when N+1 query patterns need fixing, or when profiling reveals bottlenecks.Stars: 119kUpdated Claude CodeCodexVerifiedInstall
agent-cost-reportthedotmack/claude-memBelievable agent cost report for any period, default the last 7 full days PT, not counting today. Measured tokens from Claude Code transcripts priced at OpenRouter list prices (ESTIMATED), measured provider spend when a sanctioned source exists, note-taker cost separate, Timing-style HTML/PDF plus report.json, line-items.csv, evidence.json.Stars: 118kUpdated Claude CodeCodexVerifiedInstall
backup-setupthedotmack/claude-memSet up, check, or restore local claude-mem database snapshots. Use when the user says "set up backups", "back up my memories", "backup status", or "restore my database".Stars: 118kUpdated Claude CodeCodexVerifiedInstall