Long Run|INEMA.CLUB-PRO

Lesson 7 · 17 min

Measure the session: medir-sessao.py, resume cost, and recall

Without measuring, "the session got expensive" and "the agent forgot" are just impressions. The kit reads the JSONL transcripts from Claude Code and Codex and gives you duration, compactions, tokens and cache per turn, the real cost of resuming, and a search across everything that has been said. In this lesson you measure a known case and then your biggest session.

Start the lesson
Bench oscilloscope showing a clean green wave, with probes on the table.

In this lesson you will

  1. 1Where the Claude and Codex transcripts live
  2. 2medir-sessao.py: summary, --json and --por-turno
  3. 3custo-retomada.py and nota-retomada.py
  4. 4recall: search in 0.02 s through everything that has been said

Goal: measure the duration, compactions, tokens and cache of a session, read the cost of resuming, and find an old decision with recall.

01From transcript to measurement

Four kit tools, Python standard library only, no network.

Click each block in the diagram to see what it does.

What was decided has to be in a file in the project. The transcript is for measuring and for remembering where to look.

02Measure a known case, then your own

The kit's test fixtures give fixed numbers: if your output matches, the tool is working right on your machine.

Terminal · measure the fixtures
K=~/projetos/execucao-longa
python3 $K/tools/medir-sessao.py $K/tests/fixtures/claude_mini.jsonl
python3 $K/tools/medir-sessao.py $K/tests/fixtures/codex_mini.jsonl
python3 $K/tools/medir-sessao.py $K/tests/fixtures/claude_mini.jsonl --json --por-turno
Terminal · your biggest Claude Code session and the cost of resuming
S=$(ls -S ~/.claude/projects/*/*.jsonl | head -1); echo "$S"
python3 ~/projetos/execucao-longa/tools/medir-sessao.py "$S"
python3 ~/projetos/execucao-longa/tools/custo-retomada.py 14
python3 ~/projetos/execucao-longa/tools/nota-retomada.py --relatorio
Terminal · recall on the fixtures (separate index, in /tmp)
K=~/projetos/execucao-longa; R=/tmp/ensaio-recall
rm -rf $R && mkdir -p $R/codex/2026/10/01 $R/claude/-home-voce-projetos-demo $R/arq
cp $K/tests/fixtures/recall_codex.jsonl $R/codex/2026/10/01/rollout-a.jsonl
cp $K/tests/fixtures/recall_claude.jsonl $R/claude/-home-voce-projetos-demo/s1.jsonl
export RECALL_DB=$R/recall.db
python3 $K/tools/recall.py indexar --codex $R/codex --claude $R/claude --arquivo $R/arq
python3 $K/tools/recall.py indexar --codex $R/codex --claude $R/claude --arquivo $R/arq
python3 $K/tools/recall.py PostgreSQL
unset RECALL_DB
Terminal · the real recall (once per machine, Linux)
mkdir -p ~/.local/bin && ln -s ~/projetos/execucao-longa/tools/recall.py ~/.local/bin/recall
recall indexar                      # first time: indexes ~/.claude/projects and ~/.codex/sessions
recall "cleanupPeriodDays" -n 5     # search (options: --projeto X --fonte codex|claude --desde AAAA-MM-DD)
cp ~/projetos/execucao-longa/tools/systemd/recall-indexar.* ~/.config/systemd/user/
sed -i "s#/home/nmaldaner#$HOME#g" ~/.config/systemd/user/recall-indexar.service
systemctl --user daemon-reload && systemctl --user enable --now recall-indexar.timer   # reindexes every hour
Example from the repository
$ medir-sessao.py tests/fixtures/claude_mini.jsonl
…/tests/fixtures/claude_mini.jsonl (claude)
  duração: 7200 s | compactações: 1 | turnos: 2
  tokens de entrada: 2000 | saída: 55 | cache: 45.0%
  cache lido: 900 | escrito: 1085 | saída de ferramenta: 37 bytes
  modelos: claude-opus-5-5, claude-sonnet-5-5

$ medir-sessao.py tests/fixtures/codex_mini.jsonl
…/tests/fixtures/codex_mini.jsonl (codex)
  duração: 3600 s | compactações: 1 | turnos: 2
  tokens de entrada: 3000 | saída: 120 | cache: 60.0%
  cache lido: 1800 | escrito: 0 | saída de ferramenta: 8 bytes
  modelos: gpt-6-astra, gpt-6.1-sol

$ medir-sessao.py tests/fixtures/claude_mini.jsonl --json --por-turno
[{"i": 1, "timestamp": "2026-09-02T08:00:05.000Z", "input": 1000, "cached": 0, "ratio": 0.0, "compactacoes": 0},
 {"i": 2, "timestamp": "2026-09-02T09:00:10.000Z", "input": 1000, "cached": 900, "ratio": 0.9, "compactacoes": 1}]

$ recall indexar … (duas vezes) ; recall PostgreSQL
2 arquivos processados; 8 trechos novos.
0 arquivos processados; 0 trechos novos.
2026-09-10T10:00:03.000Z codex alfa user Quero migrar o banco para PostgreSQL até sexta …/rollout-a.jsonl:4

$ nota-retomada.py --relatorio      (sem medições ainda)
Notas de retomada (últimos 30 dias, 0 medições) — …/notas.jsonl
modo          n  acerto  tokens (mediana)
compactada    0       —                 —
retomada      0       —                 —
continuada    0       —                 —
prime         0       —                 —

Fixtures are small, synthetic transcripts from the kit's tests (model names included); the numbers are for checking the tool, not as a measure of usage. Paths shortened with …

03How to read it and where to note it

One line per run in progress.md, with the tool's numbers.

1. Cache

Between 93% and 99% is the normal measured in long sessions. Much lower than that in a long session, look for pauses longer than the cache or a model switch midway.

Compaction does not drop the cache: it is no reason to cut the session short.

04Practice

First the known case, then your own data.

E16 · The tool matches on your machine

5 min

Measure both fixtures and run the recall rehearsal.

Done when: claude_mini → compactações: 1 | turnos: 2 and cache: 45.0%; codex_mini → cache: 60.0%; recall prints 2 arquivos processados; 8 trechos novos., then 0 arquivos processados and a line with PostgreSQL.

E17 · Your biggest session in progress.md

15 min

Measure the biggest transcript from your Claude Code (or one from Codex in ~/.codex/sessions) and write the line in the progress.md of your run, with the date.

Done when: the progress.md line has input tokens, cache read, output, and compactions equal to those medir-sessao.py printed for the same file.

E18 · Recall on your sessions

15 min

Install the recall command, index, and look for a decision you remember making with the agent in the last week.

Done when: recall indexar → N arquivos processados with N greater than 0, and recall "[term]" --desde [date] returns the line with the file and the conversation line number.

05Lesson quiz

Question 1 of 4

How does medir-sessao.py calculate the cache?skill

06In three sentences

Measure the known firstThe fixtures give fixed numbers; if they match, the tool is right on your machine.
Cost and knowledgecusto-retomada.py tells you how much it cost to come back; nota-retomada.py, how much came back.
Remember without trustingrecall finds where something was said; what counts is in the project file.

Going further

Previous lessonNext lesson