Long Run|INEMA.CLUB-PRO

Lesson 4 · 16 min

Cache and idle time: what the October numbers show

Going back to a large session that has sat idle for two hours can cost hundreds of thousands of tokens in a single message. It's not a bug: the cache expired. With the numbers measured in October 2026, you'll understand the timeline of an idle session and decide, with real math, between resending and starting clean.

Start the lesson
Glass hourglass on a dark circuit board, with a digital thermometer beside it.

In this lesson you will

  1. 1What happens at 45, ~54 and 60 min idle
  2. 2The measured numbers: cache, compactions and resumption
  3. 3The gate that holds the first message after the pause
  4. 4When to resend and when to /clear + /prime

Goal: read the timeline of an idle session (45, 54, 60 min) and choose between resending and /clear + /prime using the measured numbers.

01The timeline of an idle session

Claude Code, 1 h cache, context above ~200k tokens, hook-longrun 1.9.6 on.

Scroll the page: each step below lights up its part of the diagram.

  1. 1/6

    0 min

    On the Stop event, with context ≥ 200k and the handoffs/ folder in the project, the hook schedules a timer (systemd-run --user, one per session, reset on every response). If you send another message, the clock starts over.

  2. 2/6

    3–12 min

    If you switch focus, Claude Code writes an away_summary into the conversation. Since 1.8.6 this (and local commands like /exit) no longer counts as "the session moved": before, 7 sessions on 10/16 were left without a handoff because of it.

  3. 3/6

    45 min

    If the session is still idle, with no handoff from this session saved within 5 min of the last reply, and the cache is still valid (< 55 min), the hook saves the handoff on a COPY of the session: same model, warm cache, allowed to run only handoff-grava.py and read files. The open session is not touched.

  4. 4/6

    ~54 min

    Claude Code compacts on its own after about 55 min without a reply, only above ~200k tokens, before the cache expires. In the records from Oct 7 to 15, 2026, all 93 compactions came 53–58 min after the last reply. But it doesn't always happen: on Oct 18, a 480k session did not compact.

  5. 5/6

    60 min

    The next message rereads the whole conversation with no cache. With more than 150k in context, the hook holds that first message once and explains: resending continues; /clear + /prime starts clean from this session's handoff.

  6. 6/6

    The protection is the handoff

    Compaction is a bonus when it comes. The handoff at 45 min, saved while the cache is warm, is what guarantees the return has a cheap path.

Why 45 and not 50: idle-time compaction comes between 53 and 58 min, and the copy takes 30–60 s plus startup. At 45 there's some slack; the cost is the same at any time before 1 h.

02The math, in four numbers

All from the execucao-longa kit, with the date and sample size.

1. Warm × cold

With a warm cache (up to ~1 h since the last reply), rereading the conversation costs ~10% of the input price. Expired, it reprocesses everything and writes the cache again, ~2×: about 20× a message with a warm cache.

On a subscription this doesn't turn into money, but it comes out of the 5 h and weekly quota. And you pay once: the following messages are cheap again.

03The pause gate, in rehearsal

Same ensaio-hook.sh from lesson 3: fake transcript with 220k tokens and the last reply 120 min ago.

Terminal · 2 h pause and resend
rm -rf /tmp/ensaio-hook
bash ensaio-hook.sh 220000 120 UserPromptSubmit   # 1ª mensagem depois da pausa
bash ensaio-hook.sh - - UserPromptSubmit          # reenviar a mesma
bash ensaio-hook.sh 250000 0 Stop                 # fim de resposta: agenda o handoff por ociosidade
cat /tmp/ensaio-hook/agenda.jsonl
Hook variables (in the Claude Code environment)
LONGRUN_PAUSA_MIN=60          # minutos parado antes de segurar a mensagem
LONGRUN_PAUSA_TOKENS=150000   # contexto mínimo para segurar; 0 desliga a trava
LONGRUN_OCIOSO_MIN=45         # minutos parado antes de gravar o handoff (não passe de ~45)
LONGRUN_OCIOSO_TOKENS=200000  # contexto mínimo para gravar; 0 desliga
LONGRUN_CACHE_MIN=55          # depois disso a cópia não roda (o cache já estaria frio)
Example from the repository
$ bash ensaio-hook.sh 220000 120 UserPromptSubmit
{"decision": "block", "reason": "Sessão parada há 2h00: o cache venceu e esta mensagem
 vai reprocessar ~220 mil tokens do seu limite. Para continuar aqui, reenvie a mensagem.
 Para começar limpo: NENHUM handoff desta sessão foi gravado: antes do /clear, peça para
 gravar (skill session-handoff), senão o /prime não terá o caminho deste trabalho."}

$ bash ensaio-hook.sh - - UserPromptSubmit

$ bash ensaio-hook.sh 250000 0 Stop

$ cat /tmp/ensaio-hook/agenda.jsonl
{"unidade": "longrun-ocioso-ensaio", "minutos": 45, "cmd": ["/usr/bin/python3",
 ".../execucao-longa/tools/hook-longrun.py", "--ocioso", "ensaio", ...]}

With LONGRUN_AGENDAR_ARQ the hook only records the scheduling in a file, instead of creating the real timer. It's the same variable the kit's tests use.

04Practice

Rehearsal at no cost, and a tweak that protects your transcripts.

E8 · The pause gate

10 min

Run the 2-hour pause block. Then run it with 90000 tokens instead of 220000, in a clean folder, to see the 150k limit.

Done when: the 1st call prints "decision": "block" with cache venceu; the resend (-) prints nothing; with 90k there is no block; agenda.jsonl shows "minutos": 45.

E9 · Transcripts for a year

5 min

Claude Code deletes transcripts after cleanupPeriodDays (default 30). Without them, there is no measurement and no recall (lesson 7). Set 365 in settings.json.

Done when: python3 -c "import json,os;print(json.load(open(os.path.expanduser('~/.claude/settings.json'))).get('cleanupPeriodDays'))" → 365.

05Lesson quiz

Question 1 of 4

Why does the hook write the handoff on idle time at 45 min, and not at 58?skill

06In three sentences

45, 54, 60Handoff on the copy with a warm cache, idle-time compaction when it comes, expired cache and the gate on return.
Numbers with datesCache 93–99% (10/01); resume 284k × 187k and ~23k × ~10k per turn (14 days through 10/17).
Decide by the mathPath in a file: /clear + /prime. Something only in the conversation: resend once and write the handoff.

Going further

Previous lessonNext lesson