Communitygithub.com

Kosten-Tracking

Verfolge und berichte über Claude Code Token-Nutzung, Ausgaben und Budgets aus der lokalen ECC-Kosten-Tracker-Metrik-Datei. Verwende dies, wenn der Benutzer nach Kosten, Ausgaben, Nutzung, Tokens, Budgets oder Kostenaufschlüsselungen nach Modell, Sitzung oder Datum fragt.

Was ist Kosten-Tracking?

Diese Fähigkeit ermöglicht es einem KI-Agenten (wie Claude Code), Kosten und Nutzungsdaten aus dem lokalen Metrik-Log zu analysieren, das von ECCs `stop:cost-tracker`-Hook geschrieben wird. Sie ist nützlich, um Benutzern eine schnelle, genaue Antwort auf Fragen zu ihren Ausgaben, Token-Verbrauch oder Budgetlimits zu geben, ohne externe APIs oder manuelle Berechnungen. Der Agent liest eine JSONL-Datei unter `~/.claude/metrics/costs.jsonl`, reduziert die Daten auf die neueste Zeile pro Sitzung (da jede Zeile einen kumulativen Snapshot darstellt) und berechnet dann Summen nach Zeitraum, Modell oder Sitzung. Die Fähigkeit enthält vorgefertigte Node.js-Codebeispiele für Zusammenfassungen, Aufschlüsselungen nach Modell und Exporte und bietet umfassende Anleitungen zur Berichterstattung, um Fallstricke wie mehrfaches Zählen von Zeilen zu vermeiden. Sie funktioniert plattformübergreifend über Node.js und ist nahtlos in Claude Code integriert, ohne zusätzliche Abhängigkeiten.

Funktioniert mit✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/cost-tracking

In Ihrer bevorzugten KI fragen

Öffnet einen neuen Chat, in dem dieser Agent-Skill bereits geladen ist.

Dokumentation

Was macht Kosten-Tracking?

Verwende diese Fähigkeit, um die Kosten- und Nutzungshistorie von Claude Code aus dem Metrik-Log zu analysieren, das ECCs stop:cost-tracker-Hook schreibt.

Wo die Daten leben

Der Tracker hängt ein JSON-Objekt pro Sitzungsende an ~/.claude/metrics/costs.jsonl an. Jede Zeile ist ein kumulativer Snapshot für diese Sitzung. Um die Gesamtausgaben zu ermitteln, nimm die letzte Zeile pro session_id und summiere über alle Sitzungen hinweg – das Summieren jeder Zeile würde Mehrfachzählungen verursachen.

Zeilen-Schema:

FeldBedeutung
timestampISO-Zeitstempel des Snapshots
session_idClaude Code Sitzungskennung
transcript_pathPfad zum Sitzungsprotokoll
modelVerwendetes Modell
input_tokens / output_tokensToken-Anzahlen
cache_write_tokens / cache_read_tokensPrompt-Cache-Token-Anzahlen
estimated_cost_usdVorberechnete kumulative Kosten in USD für die Sitzung

Bevorzuge estimated_cost_usd gegenüber manueller Preisberechnung – Modell- und Cache-Preise ändern sich, und der Tracker ist die Quelle der Wahrheit.

Wann zu verwenden

  • Der Benutzer fragt: „Wie viel habe ich ausgegeben?“, „Was hat diese Sitzung gekostet?“ oder „Wie hoch ist mein Token-Verbrauch?“
  • Der Benutzer erwähnt Budgets, Ausgabenlimits, Überschreitungen oder Kostenkontrollen.
  • Der Benutzer möchte eine Kostenaufschlüsselung nach Modell, Sitzung oder Datum oder einen CSV-Export.

Wie es funktioniert

Überprüfe zunächst, ob das Log existiert (verwende node, nicht sqlite3 – der Tracker schreibt JSONL, und node ist plattformübergreifend):

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)?"Kostenlog gefunden":"Kostenlog nicht gefunden: "+f)'

Wenn das Log fehlt, erfinde keine Nutzungsdaten. Teile dem Benutzer mit, dass das Kosten-Tracking nach der ersten beendeten Sitzung mit aktiviertem stop:cost-tracker-Hook befüllt wird.

Beispiel – Zusammenfassung, nach Modell, letzte 7 Tage

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("Kostenlog nicht gefunden: "+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("heute: "+f4(sum(latest.filter(r=>day(r)===today)))+" | gestern: "+f4(sum(latest.filter(r=>day(r)===yest)))+

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

Verwandte Skills