Guía de ClaudeNivel 5 · Cuando se te va de las manosLevel 5 · When it gets out of hand
Medir el gastoMeasuring spend
Un script que lee mis transcripciones, escribe una fila por semana y me deja comparar sin acordarme de nada.A script that reads my transcripts, writes one row per week and lets me compare without having to remember anything.
Después de quedarme sin cuota entendí algo incómodo: el gasto se puede medir, y yo no lo estaba midiendo. Tenía una sensación (“esta semana gasté mucho”) y ninguna regla para decidir si esa sensación era cierta. Una sensación no se compara con la de la semana pasada, y un número sí.
De dónde salen los datos
Claude Code guarda en mi computadora una transcripción de cada sesión. Es un archivo de texto con cada turno, el modelo que se usó, cuánto leyó y cuánto escribió. No hace falta ninguna herramienta externa ni pedirle nada a Claude: los datos ya están ahí, esperando que alguien los sume.
El script se llama gasto_tokens.py. Es Python simple, sin IA, sin tokens. Recorre las transcripciones de una semana, suma y escribe una fila.
Las columnas
Una fila por semana, en un archivo CSV, con estas nueve columnas:
desdeyhasta: el rango de fechas de la semana.peso: el gasto total, estimado con la proporción de precios de cada modelo. Sirve para comparar semanas, no es el porcentaje real del límite.turnosysesiones: cuánto se trabajó.pct_opus: qué porcentaje del peso fue Opus.ctx_promedio: el contexto promedio por turno.pct_releer: cuánto del gasto fue releer la conversación.pct_subagentes: cuánto se llevaron los subagentes.
Son pocas a propósito. Con más columnas el archivo se vuelve un tablero, y los tableros se miran una vez y se abandonan. Con nueve alcanza para ver una semana de un vistazo.
La comparación
Mi newsletter de los miércoles corre el script, agrega la fila nueva al CSV y compara con la semana anterior. No necesito acordarme ni abrir nada: aparece en la misma edición que ya leo, como una tarea programada más. Si algo se va de la meta, aparece ahí, sin que yo lo busque.
Las metas son tres, escritas antes de mirar los datos para no acomodarlas después:
- Opus por debajo del 40 %.
- Contexto promedio por debajo de 90 k.
- Ninguna sesión por encima del 8 % del gasto semanal.
Lo que mide y lo que no
Mide cuánto gasté, no si lo gasté bien. Una semana cara puede ser una semana en la que terminé algo importante. Los números no entienden de eso, y por eso mi conclusión semanal la escribo yo y no el script.
Tampoco es una cuenta exacta del plan: solo ve lo que corre en Claude Code en mi computadora, no la web ni el celular. Es una aproximación que alcanza para ver tendencias, que es lo que necesitaba.
En el kit dejé una plantilla del CSV con las nueve columnas, vacía, para que empieces desde cero.
El prompt
Escribí un script de Python, sin usar IA, que lea las transcripciones locales de Claude Code de la última semana y agregue una fila a un archivo CSV con estas columnas: desde, hasta, peso, turnos, sesiones, pct_opus, ctx_promedio, pct_releer, pct_subagentes. Antes de escribirlo, mostrame dónde están las transcripciones en mi computadora y cómo está armado un turno. Que el script imprima la comparación con la fila anterior y marque en qué columnas me paso de estas metas: Opus menos del 40 %, contexto menos de 90 k, ninguna sesión sobre el 8 % del total. Usá rutas absolutas. No guardes nada sin que lo apruebe.
After running out of quota I understood something uncomfortable: spend can be measured, and I wasn't measuring it. I had a feeling (“I spent a lot this week”) and no rule to decide whether that feeling was true. A feeling can't be compared with last week's, and a number can.
Where the data comes from
Claude Code stores a transcript of every session on my computer. It's a text file with each turn, the model that was used, how much it read and how much it wrote. No external tool is needed and I don't have to ask Claude for anything: the data is already there, waiting for someone to add it up.
The script is called gasto_tokens.py. It's plain Python, no AI, no tokens. It goes through a week's transcripts, adds things up and writes a row.
The columns
One row per week, in a CSV file, with these nine columns:
desdeandhasta: the week's date range.peso: total spend, estimated with each model's price ratio. It's for comparing weeks, not the real percentage of the limit.turnosandsesiones: how much work got done.pct_opus: what percentage of the weight was Opus.ctx_promedio: the average context per turn.pct_releer: how much of the spend was rereading the conversation.pct_subagentes: how much the subagents took.
They're few on purpose. With more columns the file turns into a dashboard, and dashboards get looked at once and abandoned. Nine is enough to see a week at a glance.
The comparison
My Wednesday newsletter runs the script, adds the new row to the CSV and compares it with the previous week. I don't have to remember or open anything: it shows up in the same edition I already read, as one more scheduled task. If something drifts past the target, it shows up there, without my going looking.
There are three targets, written down before looking at the data so I couldn't fudge them afterward:
- Opus under 40%.
- Average context under 90k.
- No session above 8% of the weekly spend.
What it measures and what it doesn't
It measures how much I spent, not whether I spent it well. An expensive week can be a week in which I finished something important. The numbers don't understand that, which is why I write the weekly conclusion myself and the script doesn't.
Nor is it an exact account of the plan: it only sees what runs in Claude Code on my computer, not the web or the phone. It's an approximation that's good enough to see trends, which is what I needed.
In the kit I left a template of the CSV with the nine columns, empty, so you can start from scratch.
The prompt
Write a Python script, without using AI, that reads the local Claude Code transcripts from the last week and adds a row to a CSV file with these columns: desde, hasta, peso, turnos, sesiones, pct_opus, ctx_promedio, pct_releer, pct_subagentes. Before writing it, show me where the transcripts are on my computer and how a turn is structured. Have the script print the comparison with the previous row and flag which columns go over these targets: Opus under 40%, context under 90k, no session over 8% of the total. Use absolute paths. Don't save anything until I approve it.