Skip to main content
A session pays for the context it carries: every cache rebuild re-bills the whole context at write rates, compactions cost turns, and cost per turn climbs as the context grows. Past some size, those costs stop being worth carrying. That size is different per team, per model and per working style, so measure your own sessions to find it. This investigation runs as a skill for your coding agent. It reads your sessions from LangWatch, computes cost per model call, cache rebuild rate and compaction rate, and writes a report with the context size to stay under.

Run the investigation

Find my context sweet spot
Install via CLI
npx skills add langwatch/skills/context-sweet-spot
Skill Usage
/context-sweet-spot
Copy Full PromptRun skill without installing
Download SKILL.mdManual installation

What it computes

The skill exports your coding-agent sessions and their per-call rows, then buckets sessions by peak-context share of the model’s window and compares three things between buckets:
  • Cost per model call, split by session lifetime: does the last third of a session cost more per call than the first third?
  • Cache rebuild rate: model calls that re-created the context instead of reading it from cache. Each one pays write rates for tokens that were already paid for.
  • Compaction rate: how often the agent compressed its conversation to stay under the context window.
The sweet spot is the highest context share where all three stay flat. The report states it in one line, shows the bucket comparison behind it, and dissects your three most expensive sessions: where the context grew, where it rebuilt, what one rebuild cost.

What it looks like

The published version of this investigation ran on 287,748 real model calls and produced the cost curve your report draws for your own sessions:
Tokens per productive step against the compaction threshold

Tokens per productive step against the compaction threshold. The optimum sat at 220k, and every threshold between 170k and 316k stayed within 10 percent of it. Letting the context fill to 900k costs 2.3 times the optimum.

The same investigation priced the compaction itself beyond the tokens it re-bills: for the first 30 steps after one, the share of user messages containing a correction runs at up to 2.4 times the baseline, and it takes about 60 steps to return to steady state.
Corrections by steps since the last compaction

Share of user messages containing a correction, by steps since the last compaction, over 128,853 observations across 700 transcripts.

The full study is published at Finding the optimal context window.

What to do with the number

The report ties each recommendation to your own evidence: when to start a fresh session instead of pushing a long one further, what to offload to sub-agents so their context does not enter the main session, and whether compactions happen late, after the context already crossed your threshold. The session detail shows the same cache-health stats live, per session, so you can watch the habit change after you act on the report. Also check: Sessions for the data this investigation reads, and Compare provider costs for the other question your usage data answers.
Last modified on August 27, 2026