cost-tracking
Was er macht
Dieses Tool zeigt dir, wie viel Geld du mit Claude Code ausgegeben und wie viele Tokens du verbraucht hast. Es liest eine Protokolldatei aus, die automatisch erstellt wird, wenn du eine Sitzung beendest.
Wann du ihn nutzt
- ✓Wenn du fragst, wie viel du ausgegeben oder verbraucht hast.
- ✓Wenn du die Kosten nach Modell oder nach Tag sehen möchtest.
- ✓Wenn du Budgets oder Ausgabenlimits erwähnst.
Link zum Skill
https://github.com/affaan-m/ECC/blob/main/skills/cost-tracking/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Wie viel habe ich diese Woche mit Claude Code ausgegeben?”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Das Tool prüft eine spezielle Datei namens „costs.jsonl“, die Claude Code erstellt. Es liest die neuesten Informationen aus jeder Sitzung aus und berechnet daraus die Summe.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
Cost Tracking
Use this skill to analyze Claude Code cost and usage history from the metrics log
that ECC's stop:cost-tracker hook writes.
Where the data lives
The tracker appends one JSON object per session-stop to
~/.claude/metrics/costs.jsonl. Each row is a cumulative snapshot for that
session, so to total spend you take the latest row per session_id and
sum across sessions — summing every row multiply-counts.
ECC also maintains internal per-session files under
~/.claude/metrics/cost-snapshots/ so runtime hooks can read the current
session total without rescanning all history. Treat those files as a
rebuildable cache; each snapshot stores a byte cursor so only newly appended
rows are scanned. Stable reads are O(1), while updates are O(new bytes). Stale
entries are pruned after 30 days or when the directory exceeds 512 sessions.
Cold catch-up work is limited to 16 MiB per hook invocation, and malformed
unterminated rows larger than 1 MiB are discarded with a resumable cursor.
Reports and exports should continue to use costs.jsonl.
Row schema:
| Field | Meaning |
|---|---|
timestamp |
ISO timestamp of the snapshot |
session_id |
Claude Code session identifier |
transcript_path |
Path to the session transcript |
model |
Model used |
input_tokens / output_tokens |
Token counts |
cache_write_tokens / cache_read_tokens |
Prompt-cache token counts |
estimated_cost_usd |
Precomputed cumulative cost in USD for the session |
Prefer estimated_cost_usd over hand-calculating pricing — model and cache
prices change, and the tracker is the source of truth.
When to Use
- The user asks "how much have I spent?", "what did this session cost?", or "what is my token usage?"
- The user mentions budgets, spending limits, overruns, or cost controls.
- The user wants a cost breakdown by model, session, or date, or a CSV export.
How It Works
First verify the log exists (use node, not sqlite3 — the tracker writes
JSONL, and node is cross-platform):
node -e 'const fs=require("fs"),os=require("os"),p=require("path");const f=p.join(os.homedir(),".claude","metrics","costs.jsonl");console.log(fs.existsSync(f)?"cost log found":"cost log not found: "+f)'
If the log is missing, do not fabricate usage data. Tell the user that cost
tracking populates after the first session ends with the stop:cost-tracker
hook enabled.
Example — summary, by model, last 7 days
node -e '
const fs=require("fs"),os=require("os"),path=require("path");
const f=path.join(os.homedir(),".claude","metrics","costs.jsonl");
if(!fs.existsSync(f)){console.log("cost log not found: "+f);process.exit(0);}
const rows=fs.readFileSync(f,"utf8").split(/\r?\n/).filter(Boolean).map(l=>{try{return JSON.parse(l)}catch{return null}}).filter(Boolean);
const bySession=new Map();
for(const r of rows){const k=r.session_id||r.transcript_path||r.timestamp;const p=bySession.get(k);if(!p||String(r.timestamp)>String(p.timestamp))bySession.set(k,r);}
const latest=[...bySession.values()];
const cost=r=>Number(r.estimated_cost_usd)||0, day=r=>String(r.timestamp||"").slice(0,10), sum=a=>a.reduce((s,r)=>s+cost(r),0), f4=n=>"$"+n.toFixed(4);
const today=new Date().toISOString().slice(0,10), yest=new Date(Date.now()-864e5).toISOString().slice(0,10);
console.log("today: "+f4(sum(latest.filter(r=>day(r)===today)))+" | yesterday: "+f4(sum(latest.filter(r=>day(r)===yest)))+" | total: "+f4(sum(latest))+" ("+latest.length+" sessions)");
const m=new Map();for(const r of latest){const k=r.model||"(unknown)";m.set(k,(m.get(k)||0)+cost(r));}
console.log("by model:");[...m.entries()].sort((a,b)=>b[1]-a[1]).forEach(([k,v])=>console.log(" "+f4(v)+" "+k));
'
For a session drilldown or CSV export, iterate the same latest set (or the raw
rows for CSV) and print the fields you need.
Reporting Guidance
When presenting cost data, include today's spend vs yesterday, total across all sessions, a by-model breakdown, and session count. Format sub-dollar amounts with four decimals, larger amounts with two.
Anti-Patterns
- Do not sum every row — they are cumulative per session; reduce to the latest
row per
session_idfirst. - Do not estimate costs from raw token counts when
estimated_cost_usdis present. - Do not assume the log exists without checking.
- Do not hard-code current model pricing in user-facing answers.
…
Häufige Fragen
Was sind „Tokens“?
Tokens sind Textbausteine, mit denen Claude Code Text versteht und erzeugt. Mehr Text bedeutet mehr Tokens.
Warum ist die Datei „costs.jsonl“ wichtig?
Dort werden alle Kosten- und Nutzungsdaten gespeichert. Ohne sie kann das Tool deine Ausgaben nicht anzeigen.
Was ist, wenn ich keine Kosten sehe?
Das Kostenprotokoll wurde vielleicht noch nicht erstellt. Es erscheint erst, nachdem du deine erste Sitzung mit aktiviertem Tracker beendet hast.
Details
Originalbeschreibung des Autors
Track and report Claude Code token usage, spending, and budgets from the local ECC cost-tracker metrics log. Use when the user asks about costs, spending, usage, tokens, budgets, or cost breakdowns by model, session, or date.
repo: affaan-m/ECC
Beliebtheit
- GitHub-Sterne
- 280k
- Platz im Ranking
- #289
- Lizenz
- MIT
- Aktualisiert
- 15.10.2026
Kommentare
- …
Weitere Skills aus diesem Repository
accessibility
280kHilft deinem Agenten, barrierefreie Oberflächen zu bauen. Websites und Apps werden so auch für Blinde und Menschen mit eingeschränkter Mobilität gut nutzbar.
agent-architecture-audit
280kLässt deinen Agenten prüfen, ob alles richtig läuft. Er findet und behebt Probleme in KI-Systemen, damit sie wie erwartet arbeiten.
agent-eval
280kHilft deinem Agenten, verschiedene KI-Coding-Tools zu vergleichen. Er misst, welches für bestimmte Aufgaben schneller, günstiger und zuverlässiger ist.
agent-harness-construction
280kMacht deinen Agenten besser darin, Aufgaben zu lösen. Er optimiert die Tools und Anweisungen, die er nutzt, damit er mit höherer Wahrscheinlichkeit erfolgreich ist.
Ähnliche Skills
knowledge-capture
394kBringt deinem Agenten bei, Entscheidungen, Vorlieben und wichtige Fakten als kurze Notizen mit Quellenangabe in deinem Knowledge-Vault zu speichern.
knowledge-claim-consolidation
394kHilft deinem Agenten, einen Knowledge-Vault aufzuräumen: doppelte Aussagen zusammenführen, auf die richtigen Themenseiten verschieben, veraltete ausrangieren.
knowledge-correct
394kLässt deinen Agenten auf Wunsch eine bestimmte gespeicherte Knowledge-Aussage oder Seite korrigieren oder zurückziehen und den Änderungsverlauf festhalten.