clemensit / experiments
Experiment 009 · Token economics - Claude Code Cost Framework Experiment 009 · Token-Ökonomie - Claude Code Kosten Framework

WHAT YOU ACTUALLY PAY FOR WOFÜR DU WIRKLICH BEZAHLST

Three ways to cut what an AI coding agent costs — and a five-day method to find out which one actually works on your codebase. Drei Wege, die Kosten eines KI-Coding-Agenten zu senken — und eine Fünf-Tage-Methode, um herauszufinden, welcher davon in deiner Codebasis wirklich funktioniert.

cc-cost-framework · Python · Bash · Ollama · MIT

The problem Das Problem

Every request is billed by the token Jede Anfrage wird pro Token abgerechnet

An AI coding agent does not bill you for the question. It bills you for everything it has to carry in order to answer it — the system prompt, the tool definitions, the conversation so far, and every file it pulled in to look at. Ein KI-Coding-Agent rechnet nicht die Frage ab. Er rechnet alles ab, was er mitschleppen muss, um sie zu beantworten — den System-Prompt, die Tool-Definitionen, den bisherigen Gesprächsverlauf und jede Datei, die er dabei eingelesen hat.

System prompt & tool definitionsSystem-Prompt & Tool-Definitionen15%
Conversation so farBisheriger Gesprächsverlauf32%
Injected file contextEingelesener Datei-Kontext38%
Your promptDein Prompt4%
Model outputAntwort des Modells11%

Illustrative shape of a typical agent request — not measured data. The proportions shift with repository size, task type, and how long the session has been running. Beispielhafte Aufteilung einer typischen Agent-Anfrage — keine Messdaten. Die Anteile verschieben sich je nach Repository-Größe, Aufgabentyp und Länge der Sitzung.

The part you typed is the smallest line on the bill. That is why “write shorter prompts” barely moves the number — the cost lives in the context, not in your typing. Der Teil, den du getippt hast, ist die kleinste Position auf der Rechnung. Deshalb bewegt „kürzere Prompts schreiben“ die Zahl kaum — die Kosten stecken im Kontext, nicht in deiner Eingabe.

The approach Der Ansatz

Three levers, three different points of attack Drei Hebel, drei verschiedene Angriffspunkte

The three stages are independent — you can adopt one, two, or all three. Stage 1 shrinks every request that reaches the meter. Stages 2 and 3 stop requests from reaching it at all. Die drei Stufen sind unabhängig voneinander — du kannst eine, zwei oder alle drei einsetzen. Stufe 1 verkleinert jede Anfrage, die abgerechnet wird. Stufe 2 und 3 sorgen dafür, dass Anfragen dort gar nicht erst ankommen.

Request pipeline: compression, then classification into local model, cheaper assistant, or the metered Claude API EVERY REQUESTJEDE ANFRAGE prompt + history + file contextPrompt + Verlauf + Kontext 1 · COMPRESS1 · KOMPRIMIEREN same request, fewer billed tokensgleiche Anfrage, weniger Token CLASSIFYKLASSIFIZIEREN by complexity · stages 2 + 3nach Komplexität · Stufe 2 + 3 TRIVIALTRIVIAL LOCAL MODELLOKALES MODELL stage 3 · unmeteredStufe 3 · ohne Abrechnung ROUTINEROUTINE CHEAPER MODELGÜNST. MODELL stage 2 · lower rateStufe 2 · günstigerer Tarif COMPLEX · MULTI-FILEKOMPLEX · MEHRDATEI CLAUDE API metered per tokenpro Token abgerechnet
billed per tokenpro Token abgerechnet off the metered pathaußerhalb der Abrechnung
Stage 1Stufe 1

Token EfficiencyToken-Effizienz

Compress the contextDen Kontext komprimieren
MechanismMechanismus
rtk compresses tool output before it enters the context. codegraph replaces whole-file reads with a symbol-level map of the repo. headroom trims repeated context and turns on prompt caching.rtk komprimiert Tool-Ausgaben, bevor sie in den Kontext gelangen. codegraph ersetzt das Einlesen ganzer Dateien durch eine Symbol-Karte des Repos. headroom entfernt wiederholten Kontext und aktiviert Prompt-Caching.
TargetsZielt auf
The two largest slices above — injected file context and conversation history.Die beiden größten Anteile oben — eingelesener Datei-Kontext und Gesprächsverlauf.
Claim under testZu prüfende Annahme
The same task produces the same result on measurably fewer billed tokens.Dieselbe Aufgabe liefert dasselbe Ergebnis mit messbar weniger abgerechneten Token.
What it costs youWas es kostet
Another moving part in the toolchain — and compression can strip detail the model actually needed.Ein weiteres bewegliches Teil in der Toolchain — und Kompression kann Details entfernen, die das Modell tatsächlich gebraucht hätte.
Stage 2Stufe 2

Copilot HybridCopilot-Hybrid

Move routine work to a cheaper meterRoutinearbeit günstiger abrechnen
MechanismMechanismus
A written routing policy, not a tool: boilerplate, renames, scaffolding and single-file completions go to the cheaper assistant. Multi-file reasoning, debugging and architecture stay with Claude.Eine schriftliche Routing-Richtlinie, kein Tool: Boilerplate, Umbenennungen, Gerüstcode und Vervollständigungen in einer einzelnen Datei gehen an den günstigeren Assistenten. Mehrdateien-Logik, Debugging und Architektur bleiben bei Claude.
TargetsZielt auf
How many requests reach the expensive meter at all.Wie viele Anfragen überhaupt beim teuren Tarif ankommen.
Claim under testZu prüfende Annahme
A large share of daily work does not need the strongest model.Ein großer Teil der täglichen Arbeit braucht nicht das stärkste Modell.
What it costs youWas es kostet
A human has to make the call. A wrong call costs a retry — and a retry costs more than the request it saved.Ein Mensch muss entscheiden. Eine Fehlentscheidung kostet einen zweiten Versuch — und der kostet mehr als die eingesparte Anfrage.
Stage 3Stufe 3

Local RouterLokaler Router

Take work off the meter entirelyArbeit ganz aus der Abrechnung nehmen
MechanismMechanismus
A local FastAPI service classifies each incoming request and sends the low-complexity ones to a quantized model running on the developer’s own machine through Ollama. Everything else passes straight through to Claude.Ein lokaler FastAPI-Dienst klassifiziert jede eingehende Anfrage und leitet die einfachen an ein quantisiertes Modell weiter, das über Ollama auf dem Rechner der Entwicklerin läuft. Alles andere wird direkt an Claude durchgereicht.
TargetsZielt auf
Metered requests again — but here the cheap tier costs nothing per token.Erneut die abgerechneten Anfragen — nur kostet die günstige Stufe hier nichts pro Token.
Claim under testZu prüfende Annahme
Local models are good enough for the bottom tier of real work.Lokale Modelle sind gut genug für die einfachste Stufe echter Arbeit.
What it costs youWas es kostet
Hardware, latency, and a model that is weaker than people assume. Below roughly 3 GB of usable memory it is not viable at all.Hardware, Latenz und ein Modell, das schwächer ist als viele annehmen. Unterhalb von etwa 3 GB nutzbarem Speicher ist es gar nicht praktikabel.
The method Die Methode

Why this is an experiment, not an opinion Warum das ein Experiment ist und keine Meinung

Any of these three can be made to look good with a hand-picked example. The protocol removes that freedom: the task set is fixed first, the unmodified baseline is measured before anything is installed, and then the identical tasks run again under each stage. Jede dieser drei Stufen lässt sich mit einem passend gewählten Beispiel gut aussehen lassen. Das Protokoll nimmt diese Freiheit: Der Aufgabensatz wird zuerst festgelegt, die unveränderte Baseline wird gemessen, bevor irgendetwas installiert wird, und danach laufen dieselben Aufgaben erneut unter jeder Stufe.

Five-day protocol: day zero baseline, then one stage per day, then repeat and decide DAY 0TAG 0 DAY 1TAG 1 DAY 2TAG 2 DAY 3TAG 3 DAY 4TAG 4 DAY 5TAG 5 BASELINE STAGE 1STUFE 1 STAGE 2STUFE 2 STAGE 3STUFE 3 REPEATWIEDERHOLEN DECIDEENTSCHEIDEN before any installvor der Installation compressionKompression hybrid routingHybrid-Routing local routerlokaler Router stress the candidateKandidat unter Last scorecardScorecard identical task set, one stage at a timeidentischer Aufgabensatz, eine Stufe nach der anderen
The gateDie Hürde

No baseline, no result. If the baseline was not captured before installation, every number that follows is a guess with decimal places. Keine Baseline, kein Ergebnis. Wurde die Baseline nicht vor der Installation erfasst, ist jede folgende Zahl eine Schätzung mit Nachkommastellen.

The output Das Ergebnis

Four columns decide it Vier Spalten entscheiden

Each stage is scored on the same four measurements, taken from the same tasks. Three of them are about cost and speed. The fourth is the one that can veto a result. Jede Stufe wird an denselben vier Messwerten gemessen, aus denselben Aufgaben. Drei davon betreffen Kosten und Tempo. Der vierte kann ein Ergebnis kippen.

MeasurementMesswert What it tells youWas er aussagt Wins whenGewinnt, wenn
tokens / taskToken / Aufgabe How much context each task actually consumedWie viel Kontext eine Aufgabe tatsächlich verbraucht hat ↓ lower↓ niedriger
cost / taskKosten / Aufgabe The line that actually appears on the invoiceDie Position, die tatsächlich auf der Rechnung steht ↓ lower↓ niedriger
wall-clock / taskLaufzeit / Aufgabe Whether the saving is being paid for in waitingOb die Einsparung mit Wartezeit bezahlt wird ↓ or flat↓ oder gleich
tasks passing acceptancebestandene Abnahmen Whether the output still does what it was supposed to doOb das Ergebnis noch das tut, was es tun sollte → unchanged→ unverändert

A stage only wins if it cuts cost without moving the last row. A cheaper run that fails acceptance is not cheaper — it is a retry you have not paid for yet. Eine Stufe gewinnt nur, wenn sie die Kosten senkt, ohne die letzte Zeile zu verändern. Ein günstigerer Lauf, der die Abnahme nicht besteht, ist nicht günstiger — er ist ein zweiter Versuch, den du noch nicht bezahlt hast.

Limits Grenzen

What this page does not claim Was diese Seite nicht behauptet

Nothing here reports a measured saving. The figures in the first diagram describe a mechanism, not a result — and this framework exists precisely because savings get quoted that nobody measured. Nichts hier berichtet eine gemessene Einsparung. Die Zahlen im ersten Diagramm beschreiben einen Mechanismus, kein Ergebnis — und dieses Framework existiert genau deshalb, weil ständig Einsparungen zitiert werden, die niemand gemessen hat.

Hardware, task mix and repository size change every one of these outcomes. That is why the protocol runs on your repositories and your real tasks rather than on a demo — and why the honest answer for some teams will be that none of the three stages is worth adopting. Hardware, Aufgabenmix und Repository-Größe verändern jedes dieser Ergebnisse. Deshalb läuft das Protokoll auf deinen Repositories und deinen echten Aufgaben statt auf einer Demo — und deshalb wird die ehrliche Antwort für manche Teams lauten, dass sich keine der drei Stufen lohnt.