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.pyscript19.3 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/tests/test_prices.py

View on GitHub
import json
import os
import shutil
import subprocess
import sys
import tempfile
import unittest

import _paths
from acr import prices

SAMPLE = os.path.join(_paths.FIXTURES, "prices_sample.json")


class Norm(unittest.TestCase):
    def test_norm_rules(self):
        self.assertEqual(prices.norm("claude-fable-5-1"), "anthropic/claude-fable-5.1")
        self.assertEqual(prices.norm("claude-sonnet-4-5-20250929"), "anthropic/claude-sonnet-4.5")
        self.assertEqual(prices.norm("gpt-5-codex"), "openai/gpt-5-codex")
        self.assertEqual(prices.norm("gemini-2.5-pro"), "google/gemini-2.5-pro")
        self.assertEqual(prices.norm("anthropic/claude-opus-5.5"), "anthropic/claude-opus-5.5")
        self.assertEqual(prices.norm("alias-x", aliases={"alias-x": "vendor/real"}), "vendor/real")


class Rate(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.models = prices.load(SAMPLE)["models"]

    def test_explicit_cache_write_1h_is_used(self):
        r = prices.rate("anthropic/claude-opus-5.5", self.models)
        self.assertEqual(r["cache_write_1h"], 30.0)
        self.assertEqual(r["price_source"]["cache_write_1h"], "listed")
        self.assertEqual(r["price_source"], {"cache_read": "listed", "cache_write": "listed", "cache_write_1h": "listed"})

    def test_cache_write_1h_falls_back_to_2x_input(self):
        r = prices.rate("claude-fable-5-1", self.models)
        self.assertEqual(r["key"], "anthropic/claude-fable-5.1")
        self.assertEqual(r["input_usd_per_mtok"], 10.0)
        self.assertEqual(r["output_usd_per_mtok"], 50.0)
        self.assertEqual(r["cache_read"], 0.25)
        self.assertEqual(r["cache_write"], 12.5)
        self.assertEqual(r["cache_write_1h"], 20.0)
        self.assertEqual(r["price_source"]["cache_write_1h"], "input*2")
        self.assertEqual(r["source"], "openrouter-public-list")

    def test_cache_read_and_write_fallbacks(self):
        r = prices.rate("claude-sonnet-4-5-20250929", self.models)
        self.assertAlmostEqual(r["cache_read"], 0.3)
        self.assertAlmostEqual(r["cache_write"], 3.75)
        self.assertEqual(r["cache_write_1h"], 6.0)
        self.assertEqual(r["price_source"], {"cache_read": "input*0.1", "cache_write": "input*1.25", "cache_write_1h": "input*2"})

    def test_unpriced(self):
        self.assertIsNone(prices.rate("<synthetic>", self.models))
        self.assertIsNone(prices.rate("", self.models))
        self.assertIsNone(prices.rate(None, self.models))
        self.assertIsNone(prices.rate("unknown-model-9", self.models))
        self.assertIsNone(prices.rate("gpt-5-codex", self.models))  # listed but input is null


class Files(unittest.TestCase):
    def setUp(self):
        self.tmp = tempfile.mkdtemp(prefix="acr-prices-")

    def tearDown(self):
        shutil.rmtree(self.tmp, ignore_errors=True)

    def test_ensure_with_saved_prices_writes_outdir_copy(self):
        path, p = prices.ensure(self.tmp, prices_file=SAMPLE)
        self.assertEqual(path, os.path.join(self.tmp, "prices.json"))
        with open(path) as fh:
            d = json.load(fh)
        self.assertEqual(d["models"]["anthropic/claude-fable-5.1"]["input"], 10.0)
        self.assertEqual(d["source"], prices.SOURCE_URL)
        self.assertEqual(d["loaded_from"], os.path.abspath(SAMPLE))

    def test_offline_fetch_is_an_error_not_zero(self):
        with self.assertRaises(prices.PriceError):
            prices.ensure(self.tmp, url="http://127.0.0.1:9/models")  # nothing listens here
        self.assertFalse(os.path.exists(os.path.join(self.tmp, "prices.json")))

    def test_bad_prices_file(self):
        bad = os.path.join(self.tmp, "bad.json")
        with open(bad, "w") as fh:
            fh.write('{"nope": 1}')
        with self.assertRaises(prices.PriceError):
            prices.load(bad)
        with self.assertRaises(prices.PriceError):
            prices.load(os.path.join(self.tmp, "missing.json"))


class Cli(unittest.TestCase):
    def setUp(self):
        self.tmp = tempfile.mkdtemp(prefix="acr-cli-")

    def tearDown(self):
        shutil.rmtree(self.tmp, ignore_errors=True)

    def run_acr(self, *argv):
        return subprocess.run([sys.executable, _paths.ACR_PY, *argv], capture_output=True, text=True)

    def test_prices_offline_exits_nonzero_with_clear_error(self):
        r = self.run_acr("prices", "--out", self.tmp, "--url", "http://127.0.0.1:9/models")
        self.assertNotEqual(r.returncode, 0)
        self.assertIn("could not fetch", r.stderr)
        self.assertIn("--prices", r.stderr)

    def test_prices_from_saved_file(self):
        r = self.run_acr("prices", "--out", self.tmp, "--prices", SAMPLE)
        self.assertEqual(r.returncode, 0, r.stderr)
        self.assertIn("4 models", r.stdout)
        self.assertTrue(os.path.exists(os.path.join(self.tmp, "prices.json")))

    def test_every_subcommand_is_wired(self):
        r = self.run_acr("--help")
        for cmd in ("collect", "prices", "rollup", "review", "render", "pdf", "measure-openrouter", "sync-check"): self.assertIn(cmd, r.stdout, cmd)

    def test_collect_rejects_session_with_period(self):
        r = self.run_acr("collect", "--session", "x", "--start", "2026-09-18", "--out", self.tmp)
        self.assertNotEqual(r.returncode, 0)
        self.assertIn("--session", r.stderr)


if __name__ == "__main__":
    unittest.main()
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