Index
Feed
Written by mateohq · Jul 5, 2026
Long sessions die one of two deaths: the bill or the compaction. This is the freelancer's version of token discipline — measure per task, keep the context lean on purpose, and checkpoint state to files so a fresh session costs you minutes, not the afternoon.
Check /cost after each task for a day, and /context when things feel sluggish. Two numbers matter: cost per completed task, and how much of the window is filled with stuff you no longer need. Most people find one repeated task eating half the budget.
/cost
/contextVerbose build and test output is the classic leak — thousands of tokens per run, consumed on every subsequent turn. Route noisy commands through filters in CLAUDE.md so only failures enter the context.
# CLAUDE.md excerpt
## Output discipline
- Tests: `npm test 2>&1 | tail -30` — never the full log.
- Builds: append `--quiet` or pipe through `grep -E 'error|warning' | head -20`.
- NEVER cat entire large files; read the specific functions you need.The reason people fear ending sessions is losing the agent's 'understanding'. Make that understanding a file. The agent maintains it as it works; the file — not the context window — is the source of truth for progress.
! Common failures
Did this recipe work for you?
Sign in to add your report — every count here is backed by a named account.
# CLAUDE.md excerpt
## Session state
Maintain .agent/state.md as you work. After completing each sub-task, update it:
- DONE: what shipped, with file paths
- IN PROGRESS: current sub-task and the next concrete action
- DECISIONS: choices made and why (keep terse)
- LANDMINES: things tried that failed, so we never retry themAuto-compaction is a lossy summary at a moment you don't choose — landmines are exactly what it drops. When /context shows you're past ~70%, finish the current sub-task, update the state file, and start fresh. Resume costs one prompt.
claude "Read .agent/state.md and continue from IN PROGRESS. Do not redo DONE items or retry LANDMINES."Test-writing, log-summarizing, and mechanical renames don't need your best model. Switch per task, not per session — /model mid-session works and the savings are large on long days.
/model claude-haiku-4-5Close the loop: one line per task in a log. After a week you'll know your baseline and can spot regressions — mine dropped from $11/task to $4 in the first week, almost all from step 2.
echo "$(date +%F),refactor-invoice-pdf,$(claude -p '/cost' 2>/dev/null | tail -1)" >> ~/agent-costs.csvRelated records
Strong evidence gets promoted into the record above.
Adopted the state file for my three solo apps. Unexpected benefit: .agent/state.md is a decent standup note. I read yesterday's DECISIONS section with coffee.
Suspicious as ever, I checked the claim in step 6 against my own logs: $9.80/task baseline, $5.10 after two weeks of the output-discipline rules. Not the advertised 60% but I'll take 48%. The tail -30 on test output was the single biggest line item.
to join the discussion, vote, and verify fixes.
The counterintuitive part that deserves emphasis: deliberately ending sessions SAVES money. People treat a long-lived session as an investment, but every turn re-reads the whole context. A lean restart from a good state file is cheaper AND better past a few hours.