cost
Skill2 starsChanged 5 months agoMITView on GitHub
Report token usage and USD cost for AI agent sessions by parsing logs from pi, Claude Code, OpenAI Codex, opencode, and Hermes Agent. Prices are auto-refreshed weekly from the LiteLLM catalog. Use when the user asks about cost, spend, token usage, "how much did this session cost", or invokes /cost.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- SethGammon/Citadeltheir own version, first seen Sep 20, 2026
- NotHarshhaa/devops-skillstheir own version, first seen Sep 19, 2026
- jamillazarev/opsinisttheir own version, first seen Jul 31, 2026
- DaeSeokSong/oh-my-ouroborostheir own version, first seen Jul 23, 2026
- srafis/skillstheir own version, first seen May 13, 2026
- H-mmer/pentest-agentstheir own version, first seen May 6, 2026
Used with
Projects with it also use learn.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
genomewalkerSkilllearn
Learn from web sources, generate SKILL.md, and store key patterns in soul memory. Trigger keywords: learn, skill-gen, web-learn, documentation, tutorial.
Also in 3 projects that use this
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- H-mmer/pentest-agents★ 984same name
- SethGammon/Citadel★ 922same name
- Houseofmvps/ultraship★ 123same name
- maxvaega/awesome-skills★ 40same name
- NotHarshhaa/devops-skills★ 8same name
- jamillazarev/opsinist★ 2same name
- srafis/skills★ 2same name
- DaeSeokSong/oh-my-ouroboros★ 1same name
- gioe/tusk★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
4 rules. 0 are common, 2 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 116
When invoked via /cost:
- Distinctive: line 118
Run the script with the arguments the user supplied (default to none).
- Very specific: line 121
If the output lists any unpriced models, suggest python3 cost.py --refresh-prices.
- Distinctive: line 123
Do not fabricate numbers — always rely on the script's output.
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
cost — Multi-Harness Token Cost Report
Reads session usage records written by AI agent harnesses on this machine
and reports persisted token usage plus a public-rate USD estimate per session. Prices come
from BerriAI/litellm's canonical
model_prices_and_context_window.json catalog and auto-refresh weekly.
Supported harnesses
Auto-detected from ~:
| Harness | Session storage |
| pi | ~/.pi/agent/sessions/**/*.jsonl |
| Claude Code | ~/.claude/projects/**/*.jsonl |
| OpenAI Codex | ~/.codex/sessions/**/*.jsonl |
| opencode | ~/.local/share/opencode/**/*.jsonl |
| Hermes Agent | $HERMES_HOME/state.db |
Hermes is read through SQLite in mode=ro. The parser queries only sessions
and session_model_usage; it never reads transcript rows from messages.
Adding a new line-oriented harness = one small parse_* function in cost.py.
Run
# [default] the newest logical session across all harnesses
python3 cost.py
# Latest session per harness in current cwd
python3 cost.py --latest
# Every session across every harness
python3 cost.py --all --list
# Today only, per-model breakdown
python3 cost.py --today --by-model
# Since a date, one harness only
python3 cost.py --since 2026-07-01 --harness claude-code
python3 cost.py --harness hermes
# Filter by working directory or session id substring
python3 cost.py --cwd "$PWD"
python3 cost.py --session 019f4e66
# Machine-readable
python3 cost.py --json
# Prices
python3 cost.py --refresh-prices # force a refresh now
python3 cost.py --offline # skip any network accessEnvironment:
SKILL_COST_MAX_AGE_DAYS=N— refresh threshold (default 7)SKILL_COST_NO_AUTO_REFRESH=1— disable auto-refresh entirely
Pricing model
For each (model, session) bucket, cost = sum of
input_tokens * input_price
+ output_tokens * output_price
+ cache_read_tokens * cache_read_price (fallback: 0.10 * input_price)
+ cache_write_tokens * cache_creation_price (fallback: 1.25 * input_price)Rates come from LiteLLM's catalog per token; fallbacks match Anthropic's public rate card for ephemeral-5m cache.
Cache hits
A long agent session is overwhelmingly cache reads, and a cache read is billed at a fraction of the input rate (a tenth, on Anthropic's card). A six-figure token count next to a three-figure total therefore looks wrong until you can see that split, so every session prints it:
cache: 98.8% of 46,703,358 prompt tokens served from cache · saved $207.74 vs the same tokens as fresh input
spend: in $0.00 · out $1.91 · cache read $23.08 · cache write $3.36- hit rate —
cache_read / (input + cache_read + cache_write). Every prompt token is billed as exactly one of those three, so they are the honest denominator. Output tokens are not prompt tokens and are excluded. - saved — the counterfactual: what those cached tokens would have cost as ordinary input, minus what they did cost. It is a saving against not caching, not a discount off the invoice.
- spend — the same total, split by billing component, so a surprising number can be attributed to a component rather than guessed at.
The run-level footer carries the same two figures across every session shown. Both are
in --json as totals.cache_hit_rate, spend_usd, and cache_savings_usd.
Sessions mixing several models sum each component at that model's own rate. A model the
catalog cannot price contributes nothing rather than being guessed at, and is still named
in the unpriced note.
Presenting results to the user
When invoked via /cost:
- Run the script with the arguments the user supplied (default to none).
- Show the script's stdout verbatim in a fenced block.
- Summarize the grand-total cost and which harness/session it covers.
- If the output lists any
unpricedmodels, suggestpython3 cost.py --refresh-prices. - Do not fabricate numbers — always rely on the script's output.
Hermes' built-in /usage and hermes insights remain the best live telemetry
for Hermes itself. This skill complements them by applying one LiteLLM price
catalog consistently across the active Hermes profile and other harnesses,
historical sessions, project filters, and combined reports. To inspect a named
profile, invoke the script with that profile's HERMES_HOME; profiles are never
scanned implicitly.
Files
cost.py— parser + pricer, stdlib onlyprices.json— pruned LiteLLM catalog (auto-refreshed weekly by CI and on-demand at runtime). Includes a_metaentry with source/license/fetch-time.
Attribution
Prices are sourced from
BerriAI/litellm's
model_prices_and_context_window.json
catalog (MIT). We prune it to the fields we need and ship the pruned copy
as prices.json. Every catalog refresh writes a _meta block with the
source URL, license, and fetch timestamp so the provenance always travels
with the data. If a model is missing or mispriced, the fix belongs
upstream in LiteLLM — that corrects every tool that reads the catalog.
Part of the Gaia Skill Tree — an open registry of AI agent skills. · Powered by Gaia.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

