Opus 5.5 Compaction Limits: What Each Trigger Costs and Keeps

By Sam French15 min read
Line diagram of context size per call in one long session: three saw-tooth traces for compaction triggers of 150K, 367K and 967K tokens

Short answer: for long Claude Code sessions on Opus 5.5 with a subscription and a setup like mine, /autocompact 250k is the cheapest setting I can calculate, and any trigger from 196K to 246K is within 1% of it. By the same calculation the default, which compacts at 367K, costs 12.0% more per call in a long session, and a 1M window costs 90.9% more. I checked the model against 33 real runs of synthetic tasks: its compaction count was exact in 9 of 9 clean cost-test runs and its mean cost was within 1.84% at every trigger. In those runs compaction kept every fact the task flagged and dropped almost every detail it did not.

I wanted one number: the compaction limit that costs the least without losing work. I wrote the cost of a session as a formula of the limit, filled it with inputs from 557 of my own Opus 5.5 sessions, then ran 33 real sessions to see if the formula holds. It does. This is the calculation, the runs, and what to set.

What compaction is

A long agent session re-sends its whole context on every call. Compaction replaces the older part with a summary, so later calls are smaller.

In Claude Code the setting is the auto-compact window. The model configuration docs give four ways to set it:

  • /autocompact 500k in a session
  • autoCompactWindow in settings
  • --autocompact at launch
  • CLAUDE_CODE_AUTO_COMPACT_WINDOW in the environment

The window is 100K tokens or more, capped at the model's own window. The default is auto, which the docs put at 400K for models with a native 1M window: "On auto at 400K, compaction runs at about 367K tokens." With /autocompact 1M it "runs at about 967K tokens."

Both documented points put the trigger 33,000 tokens under the window, so I use trigger = window - 33,000 for every other window. The runs agree: at all 90 compactions of the 30 main runs, Claude Code's own pre-compaction count was between 696 tokens under and 4,994 over the trigger I intended.

After a compaction Claude Code reloads the system prompt, the project-root CLAUDE.md and auto memory from disk, and re-reads up to 5 recent files. A file over 5,000 tokens comes back as a path only (what survives compaction).

The summary is a separate request. It repeats the system prompt, the tools and the history being summarized, and reads that prefix from cache while the cache is warm. The next turn then rebuilds the conversation cache (prompt caching and compaction). By my calculation below, that rebuild is most of what a compaction costs when a session reloads as much context as mine do.

In the API compaction is the compact_20260112 context edit behind the compact-2026-01-12 beta header (compaction docs). The trigger defaults to 150,000 input tokens and must be at least 50,000. The summary is an extra sampling step and is billed; sum usage.iterations to see it.

json{
  "model": "claude-opus-5-5",
  "max_tokens": 4096,
  "messages": [{ "role": "user", "content": "..." }],
  "context_management": {
    "edits": [{ "type": "compact_20260112", "trigger": { "type": "input_tokens", "value": 150000 } }]
  }
}

In this article the limit means the trigger: the context size, in tokens, at which compaction runs.

What each token costs

Token classUSD per millionWhen it is billed
Uncached input$4New input that is not written to the cache
Cache write, 5-minute$5New context on an API key; every compaction request
Cache write, 1-hour$8New context in the main conversation on a subscription
Cache read$0.20The context already cached, on every call
Output$20Responses, thinking and summaries
Opus 5.5 list prices in USD per million tokens, read 2026-12-02 (documented).

Three facts from the pricing page set up everything else:

  • A cache read costs 0.05x the input price. Re-reading a big context is cheap per token, but a session does it on every call.
  • A cache write costs $5 or $8 per million. Each compaction forces one large write.
  • There is no long-context surcharge. The full 1M window of Opus 5.5 bills at the standard per-token rates.

Claude Code uses the 1-hour cache for the main conversation on a subscription, within the plan's included usage, and the 5-minute cache with an API key. Compaction requests get the 5-minute cache (cache lifetimes). I report both.

Every dollar figure here is at API list prices. On a subscription that is not a bill. It is what the same tokens would cost through the API, which makes sessions comparable.

The calculation

One call is one model request in the main conversation. The first call's context is s. Each call adds g tokens. When the next call would reach the limit L, the session compacts, and the call after it starts from R: what Claude Code reloads, plus the summary and the turns it keeps.

x(1) = s                          context of the first call
x(i) = x(i-1) + g                 every ordinary call
compact when x + g >= L           the next call then starts at R
R = sAfter + c0 + phi * L         reloaded context + what the compaction keeps

n1 = ceil((L - s) / g)            calls before the first compaction
m  = ceil((L - R) / g)            calls between later compactions
k  = 0 if T <= n1, else 1 + floor((T - n1 - 1) / m)    compactions in T calls

In plain terms: the context is a saw-tooth that climbs from R to L and drops back. A lower limit means more teeth.

Context per call in a 344-call session at compaction triggers of 150K, 367K, 967K tokens (calculated)Trigger 150K: 12 compactions, average context 126.7K tokens, session cost $29.39. Trigger 367K: 2 compactions, average context 222.5K tokens, session cost $29.10. Trigger 967K: 0 compactions, average context 378.6K tokens, session cost $39.04.150K: 12 compactions367K (default): 2 compactions967K (1M window): 0 compactions0100K200K300K400K500K600K700K150100150200250300344Call number (long refactor preset: 344 calls, 1,721 tokens added per call)Context sent with the call (tokens)Trigger 150K: 12 compactions, average context 126.7K, session cost $29.39 (calculated)Trigger 367K: 2 compactions, average context 222.5K, session cost $29.10 (calculated)Trigger 967K: 0 compactions, average context 378.6K, session cost $39.04 (calculated)trigger 150Ktrigger 367K673.7K by call 344, never compacted
Calculated: the model walked call by call through the long-refactor preset. Each drop is one compaction, and the area under a line is what the session re-reads from cache. At 250K, between the blue and orange lines, the session costs $26.23; at the default it costs $29.10; with no compaction, $39.04. Open this chart as an SVG file.
Data in this chart
TriggerCompactionsAverage contextSession cost
150K12126,660$29.39
367K2222,527$29.10
967K0378,590$39.04

Each kind of call bills differently:

  • An ordinary call reads the previous context from cache and writes the g new tokens.
  • The call after a compaction finds only the system prompt and tools in cache (sCached) and writes the rest of R again.
  • The summary request reads the whole pre-compaction context from cache, adds g + w uncached tokens, and writes the summary as output.
  • Output is o tokens per call at any limit.

For a session long enough that its start no longer matters, cost per call is:

f(L) = h * ((L + R) / 2 - g)                  holding: re-read the average context
     + pWrite * g + pOut * o + pIn * u        the same at every limit
     + A(L) * g / (L - R)                     one compaction every (L - R) / g calls

h    = pRead * (1 - rho) + pWrite * rho       cost of carrying one token for one call
A(L) = pRead * (L - g) + pIn * (g + w) + pOut * (sigma + sigmaPhi * L) + pWrite * (R - sCached)

The first term grows with the limit and the last one shrinks. If R and the summary size did not depend on L, the minimum would have a closed form, the same square-root rule used for reorder quantities in inventory:

L* = R + sqrt(2 * g * (pRead * (R - g) + A0) / h)
A0 = pWrite * (R - sCached) + pIn * (g + w) + pOut * sigma

Simply put: a low limit pays to rewrite the reloaded context too often, and a high limit pays to re-read a bigger context on every call. The cheapest limit balances the two.

Quality gets one more line. Each compaction keeps an earlier fact with probability r, so a fact from the opening prompt survives k compactions with probability r^k. That line is a model, not a derivation; r is measured below.

Inputs

I measured the inputs from my own Claude Code logs. They cover 557 Opus 5.5 sessions and 34,996 calls on one machine, from 2026-11-02 to 2026-12-03. The script reads token counts only.

SymbolWhat it isValueSpread or nKind
gContext growth per call, tokens (mean)1,763p50 1,099, p90 3,620, n 34,380measured
sContext of the first call (median)74,457p10 58,788, p90 95,661measured
sWarmPart of the first call already cached (median)11,633n 557measured
sCachedStill cached after a compaction: system prompt and tools (median)27,666n 55measured
sAfterReloaded after every compaction (median)76,352n 48measured
c0 + phi * LSummary plus turns kept verbatim20,661 + 0.00583 * Ln 48, correlation 0.19, sd 4,043measured fit
oOutput tokens per call, thinking included (mean)742n 34,996measured
uUncached input per call2measured
rho, 1-hour cacheCalls that found the cache expired0.2%measured
rho, 5-minute cacheShare of gaps between calls over 5 minutes2.93%calculated
sigma + sigmaPhi * LOutput tokens of one summary4,813 + 0.00326 * L2.63 characters per tokencalculated
wTokens the summarization request adds1,996identical in every measured compactionmeasured
Model inputs. Measured: 557 sessions, 34,996 calls, 2026-11-02 to 2026-12-03, one machine, and the synthetic runs for w.

Two more inputs are scenarios:

  • Overhead. My sessions start at 74,457 tokens: system prompt, tools, project instruction files, memory and the first prompt. The lean profile replaces that with the 27,666 tokens of system prompt and tools alone. It is calculated, not measured.
  • Session shape. Four presets from the logs. Three are the median session of a length bucket and the fourth is my longest session:
PresetCalls TGrowth gFirst context sSessions in the bucket
Short fix261,89872,613367
Feature661,70972,722155
Long refactor3441,72183,43835
Marathon (the longest session)1,6041,72183,4381
Session presets from the logs (measured): the median call count and median first context of each length bucket, with the mean growth per call of that bucket.

Before any new run I checked the model against the logs it came from:

  • It gave the exact compaction count for 12 of the 12 logged sessions that kept one window throughout. Across all 27 sessions with only automatic compactions it was exact in 17 and within one in 22. Every miss was an over-count in a session whose window changed partway.
  • For the 526 sessions that never compacted it gave 95.8% of the logged cost. Real sessions add context faster at the start than a straight line does, so the model runs slightly low.

Where the cheapest limit is

Steady-state cost per call by compaction trigger for Opus 5.5, with 1-hour and 5-minute cache writes (calculated)1-hour cache writes (subscription), This machine's overhead: cheapest at 217.5K ($0.0778 per call), $0.0871 at 367K, $0.1486 at 967K. 1-hour cache writes (subscription), Lean overhead: cheapest at 117K ($0.0561 per call), $0.0774 at 367K, $0.1414 at 967K. 5-minute cache writes (API key), This machine's overhead: cheapest at 180K ($0.0869 per call), $0.1099 at 367K, $0.2102 at 967K. 5-minute cache writes (API key), Lean overhead: cheapest at 96.5K ($0.0584 per call), $0.0977 at 367K, $0.1997 at 967K.This machine's overheadLean overheadCheapest triggerAt 367K and 967K1-hour cache writes (subscription)$0.00$0.05$0.10$0.15$0.20$0.25200K400K600K800K1MCompaction trigger (tokens)Cost per call (USD, list price)default 367KThis machine's overhead, 1-hour cache writes (subscription): cheapest at 217.5KLean overhead, 1-hour cache writes (subscription): cheapest at 117KThis machine's overhead, trigger 367K: $0.0871 per call, 12.0% above the cheapestThis machine's overhead, trigger 967K: $0.1486 per call, 90.9% above the cheapestThis machine's overhead: cheapest at 217.5K, $0.0778 per call; within 1% from 196K to 246K217.5KLean overhead, trigger 367K: $0.0774 per call, 38.0% above the cheapestLean overhead, trigger 967K: $0.1414 per call, 152.2% above the cheapestLean overhead: cheapest at 117K, $0.0561 per call; within 1% from 104K to 134K117K5-minute cache writes (API key)200K400K600K800K1MCompaction trigger (tokens)default 367KThis machine's overhead, 5-minute cache writes (API key): cheapest at 180KLean overhead, 5-minute cache writes (API key): cheapest at 96.5KThis machine's overhead, trigger 367K: $0.1099 per call, 26.5% above the cheapestThis machine's overhead, trigger 967K: $0.2102 per call, 141.9% above the cheapestThis machine's overhead: cheapest at 180K, $0.0869 per call; within 1% from 166K to 201K180KLean overhead, trigger 367K: $0.0977 per call, 67.3% above the cheapestLean overhead, trigger 967K: $0.1997 per call, 241.9% above the cheapestLean overhead: cheapest at 96.5K, $0.0584 per call; within 1% from 89K to 109K96.5K
Calculated. Left of a line's lowest point the session pays for compactions too often. Right of it every call re-reads more context. The lines are flat near the bottom: any trigger from 196K to 246K is within 1% of the cheapest for my sessions on a subscription. Open this chart as an SVG file.
Overhead profileCache writesCheapest triggerCost per call thereAt 367K (default)At 967K (1M window)Within 1% of cheapestSetting
Measured1-hour (subscription)217.5K$0.0778$0.0871 (+12.0%)$0.1486 (+90.9%)196K to 246K/autocompact 250k
Measured5-minute (API key)180K$0.0869$0.1099 (+26.5%)$0.2102 (+141.9%)166K to 201K/autocompact 210k
Lean1-hour (subscription)117K$0.0561$0.0774 (+38.0%)$0.1414 (+152.2%)104K to 134K/autocompact 150k
Lean5-minute (API key)96.5K$0.0584$0.0977 (+67.3%)$0.1997 (+241.9%)89K to 109K/autocompact 130k
Steady-state cost per call (calculated, with the long-session growth of 1,721 tokens per call): the cheapest trigger and what the default and the full window cost against it.

With my overhead and subscription cache prices the cheapest trigger is 217.5K (the closed form gives 219.1K). The default of 367K costs 12.0% more per call. A 1M window costs 90.9% more.

Two things move the minimum:

  • Cache price. With 5-minute writes it drops to 180K and the default costs 26.5% more. A rewrite is cheaper at $5 than at $8, and 2.93% of calls find a 5-minute cache expired against 0.2% for the 1-hour cache, so carrying context costs more.
  • Overhead. The lean profile reloads 50.5K after a compaction instead of 108.1K. Each compaction is cheaper and the minimum falls to 117K.

Simply put: the more a compaction has to reload, the less often you want one.

There is also a floor. In my long sessions the context right after a compaction is already about 108.1K tokens, so a trigger of 100K or less would compact after every call. The model flags those rows instead of pricing them.

The confirmation: 33 real runs

A formula built from logs can fit those logs and still be wrong. So I committed the predictions first, then ran real sessions at fixed triggers and compared.

TaskWhat the model doesGraded onTriggersRuns
KReads 100 files of about 6,135 tokens, one per request, then lists a code from each. A second turn asks for a detail the first never mentionedFlagged and incidental facts50K, 100K, 200K, 400K, 600K10
SReads 40 files, then writes a module to a 14-requirement spec from the opening prompt59 hidden tests50K, 100K, 200K, 367K12
QTask S plus 4 format quirks, each noted once in an early file and never flagged63 hidden tests50K, 100K, 200K, 367K8
The confirmation runs: 30 sessions plus 3 smoke runs, all served by claude-opus-5-5 on Claude Code 2.1.335 (measured).

Task K runs were launched like this, on a subscription, in a scratch directory holding only the task files, with no MCP servers, settings or instruction files. Tasks S and Q add the Write tool:

bashenv -u ANTHROPIC_API_KEY CLAUDE_CODE_AUTO_COMPACT_WINDOW=133000 nice -n 10 claude -p \
  --model claude-opus-5-5 --restricted --safe-mode \
  --strict-mcp-config --mcp-config '{"mcpServers":{}}' \
  --tools Read --allowed-tools Read --permission-mode dontAsk \
  --no-session-persistence --input-format stream-json --output-format stream-json \
  --include-partial-messages --verbose

That window gives a 100K trigger. Triggers under 67K need a window below the 100K minimum, so those runs set a 100K window and CLAUDE_AUTOCOMPACT_PCT_OVERRIDE (62.5 for 50K). The harness stopped any run whose first compaction fired away from the intended trigger, and any run where an event named a model other than claude-opus-5-5. 33 of 33 finished runs passed the model check.

Task K is the cost test. Each request reads one file of about 6,135 tokens, so the context grows by a known step and the compaction count, the context sizes and the cost can all be predicted. The model's inputs for this workload (first context, step, what a compaction keeps, summary length) came from 4 shorter calibration runs of the same workload at triggers from 40K to 133K, done before the predictions were committed. So every prediction above 133K is an extrapolation.

Quantity (tolerance)50K100K200K400K600K
Compactions, predicted146311
Compactions, measured (exact)146311
Cost USD, predicted$6.94$6.77$7.48$8.75$11.25
Cost USD, measured (within 5%)$7.01 (+0.96%)$6.75 (-0.29%)$7.47 (-0.22%)$8.59 (-1.84%)$11.17 (-0.75%)
Average context, predicted29,17952,23898,634171,337292,737
Average context, measured (within 3%)29,138 (-0.14%)52,624 (+0.74%)101,353 (+2.76%)170,743 (-0.35%)294,888 (+0.73%)
Context after a compaction, predicted11,46011,59811,87512,42912,983
Context after a compaction, measured median (within 10%)11,542 (+0.72%)11,704 (+0.91%)11,885 (+0.08%)11,737 (-5.57%)12,198 (-6.05%)
Summary output tokens, predicted1,3791,4801,6822,0862,490
Summary output tokens, measured (within 25%)1,627 (+18%)1,829 (+24%)2,190 (+30%) out2,206 (+6%)2,886 (+16%)
Cost per call USD, measured$0.0694$0.0679$0.0739$0.0859$0.1111
Task K, predicted before the runs against the mean of the clean runs (n = 2, 2, 1, 2, 2 by trigger).
Opus 5.5 compaction model against 10 measured runs: session cost and total tokens by trigger (Task K, 100 files)Trigger 50K: predicted $6.94, measured mean $7.01 over 2 runs, 3.68M tokens. Trigger 100K: predicted $6.77, measured mean $6.75 over 2 runs, 5.86M tokens. Trigger 200K: predicted $7.48, measured mean $7.47 over 1 run, 10.86M tokens. Trigger 400K: predicted $8.75, measured mean $8.59 over 2 runs, 17.49M tokens. Trigger 600K: predicted $11.25, measured mean $11.17 over 2 runs, 30.25M tokens.Model, calculated before the runsMeasured runMeasured, left out of the meansSession cost (USD at list prices)$6$7$8$9$10$11$120100K200K300K400K500K600KUSDModel: session cost by trigger (calculated)K-L050k-r1: trigger 50K, 101 calls, 14 compactions, $7.0964 measuredK-L050k-r2: trigger 50K, 101 calls, 14 compactions, $6.9153 measuredK-L100k-r1: trigger 100K, 100 calls, 6 compactions, $6.7285 measuredK-L100k-r2: trigger 100K, 99 calls, 6 compactions, $6.7780 measuredK-L200k-r1: trigger 200K, 101 calls, 3 compactions, $7.4674 measuredK-L200k-r2: trigger 200K, 94 calls, 3 compactions, $8.2971 measured (left out of the means: several files read in one request)K-L400k-r1: trigger 400K, 99 calls, 1 compactions, $8.5175 measuredK-L400k-r2: trigger 400K, 101 calls, 1 compactions, $8.6588 measuredK-L600k-r1: trigger 600K, 101 calls, 1 compactions, $11.1430 measuredK-L600k-r2: trigger 600K, 100 calls, 1 compactions, $11.1955 measured+0.96%-0.29%-0.22%-1.84%-0.75%Total tokens processed, all classes0M8M16M24M32M0100K200K300K400K500K600KCompaction trigger (tokens)TokensModel: total tokens by trigger (calculated)K-L050k-r1: trigger 50K, 3,672,442 tokens measuredK-L050k-r2: trigger 50K, 3,682,259 tokens measuredK-L100k-r1: trigger 100K, 5,899,810 tokens measuredK-L100k-r2: trigger 100K, 5,821,155 tokens measuredK-L200k-r1: trigger 200K, 10,862,079 tokens measuredK-L200k-r2: trigger 200K, 10,516,837 tokens measuredK-L400k-r1: trigger 400K, 17,193,402 tokens measuredK-L400k-r2: trigger 400K, 17,789,459 tokens measuredK-L600k-r1: trigger 600K, 30,089,082 tokens measuredK-L600k-r2: trigger 600K, 30,412,355 tokens measured-0.19%-0.60%+2.66%-1.30%+0.22%
The blue line is the model with the inputs committed before the runs. Each orange dot is one real session that read 100 files. Labels are the measured mean against the prediction. The cost check was fixed in advance at 5%; the token comparison was not one of the advance checks. The hollow dot read 8 files in one request and is left out of the means. Open this chart as an SVG file.
Data in this chart
RunTriggerCallsCompactionsCost (USD)Total tokensIn the means
K-L050k-r150K10114$7.09643,672,442yes
K-L050k-r250K10114$6.91533,682,259yes
K-L100k-r1100K1006$6.72855,899,810yes
K-L100k-r2100K996$6.77805,821,155yes
K-L200k-r1200K1013$7.467410,862,079yes
K-L200k-r2200K943$8.297110,516,837no
K-L400k-r1400K991$8.517517,193,402yes
K-L400k-r2400K1011$8.658817,789,459yes
K-L600k-r1600K1011$11.143030,089,082yes
K-L600k-r2600K1001$11.195530,412,355yes

Against the tolerances fixed in advance:

  • Compaction count: exact in 9 of 9 clean runs.
  • Cost: the mean of the clean runs was within 1.84% at every trigger (tolerance 5%). The worst single clean run was 2.64% off.
  • Average context: mean within 2.76% (tolerance 3%).
  • Cheapest trigger for this workload: predicted 100K, measured 100K.
  • Total tokens, which was not an advance check: within 2.66%.
  • The miss: summaries came out 6% to 30% longer than predicted, past the 25% tolerance at 200K. 9 of 10 advance checks held.

The runs produced two corrections:

  • Summaries are longer. Refit on the runs, a summary is 1,577 + 0.002039 × L output tokens, about 299 more than I assumed at any limit. It barely moves cost: with the refit, the cost errors run from -0.25% to -1.91%.
  • Claude Code compacts slightly later than I assumed. I assumed it compacts before the call that would reach the limit, one full step of 6,135 tokens early. It fired once a call's context came within a fixed lead of the trigger, and 30 runs bracket that lead between 3,992 and 4,471 tokens. Re-run with each run's own inputs, the model's worst average-context error is 3.18% with my assumption and 0.90% with the measured one.

One run is reported but left out of the means. At 200K the model read 8 files in one request instead of one, finished in fewer calls and cost $8.30, +10.87% against the prediction. I set that exclusion rule (more than three files in one request) after seeing the run, not before. Counted in, the mean cost at 200K would be +5.33% from the prediction, just outside the tolerance. Left out, n = 1 at 200K.

Compactions per session by trigger: Task K model and measured runs, and the calculated long sessionsTask K, 101 calls: 14 at 50K, 6 at 100K, 3 at 200K, 1 at 400K, 1 at 600K (measured, equal to the model in every clean run). Long refactor, 344 calls (calculated): 12 at 150K, 2 at 367K, 0 at 967K. Marathon, 1,604 calls (calculated): 61 at 150K, 10 at 367K, 3 at 967K.Model (calculated)Measured runMeasured, left out of the meansTask K, 101 calls051015200200K400K600KCompaction trigger (tokens)Task K: compactions predicted by the modelK-L050k-r1: trigger 50K, 14 compactions measured in 101 callsK-L050k-r2: trigger 50K, 14 compactions measured in 101 callsK-L100k-r1: trigger 100K, 6 compactions measured in 100 callsK-L100k-r2: trigger 100K, 6 compactions measured in 99 callsK-L200k-r1: trigger 200K, 3 compactions measured in 101 callsK-L200k-r2: trigger 200K, 3 compactions measured in 94 callsK-L400k-r1: trigger 400K, 1 compactions measured in 99 callsK-L400k-r2: trigger 400K, 1 compactions measured in 101 callsK-L600k-r1: trigger 600K, 1 compactions measured in 101 callsK-L600k-r2: trigger 600K, 1 compactions measured in 100 calls146311Long refactor, 344 calls051015200K600K1MCompaction trigger (tokens)default 367KLong refactor: compactions by trigger (calculated)Long refactor, trigger 150K: 12 compactions in 344 calls (calculated)Long refactor, trigger 367K: 2 compactions in 344 calls (calculated)Long refactor, trigger 967K: 0 compactions in 344 calls (calculated)1220Marathon, 1,604 calls020406080200K600K1MCompaction trigger (tokens)default 367KMarathon: compactions by trigger (calculated)Marathon, trigger 150K: 61 compactions in 1,604 calls (calculated)Marathon, trigger 367K: 10 compactions in 1,604 calls (calculated)Marathon, trigger 967K: 3 compactions in 1,604 calls (calculated)61103
Left: the model's step function with every measured run on it; the count was exact in 9 of 9 clean runs. Middle and right: calculated for my two long session shapes. The marathon preset still compacts 3 times with a 1M window. Open this chart as an SVG file.

Where the money goes

Tokens and cost by token class at each compaction trigger: measured Task K runs and the calculated long-refactor sessionTask K at 50K (measured): 3.68M tokens, $7.01, cache writes $5.30. Task K at 100K (measured): 5.86M tokens, $6.75, cache writes $5.04. Task K at 200K (measured): 10.86M tokens, $7.47, cache writes $4.96. Task K at 400K (measured): 17.49M tokens, $8.59, cache writes $4.91. Task K at 600K (measured): 30.25M tokens, $11.17, cache writes $4.92. Long refactor at 150K (calculated): 45.7M tokens, $29.39, cache reads $8.73. Long refactor at 200K (calculated): 53.0M tokens, $26.67, cache reads $10.29. Long refactor at 250K (calculated): 61.0M tokens, $26.23, cache reads $11.93. Long refactor at 300K (calculated): 68.7M tokens, $27.18, cache reads $13.49. Long refactor at 367K (calculated): 77.6M tokens, $29.10, cache reads $15.26. Long refactor at 500K (calculated): 91.4M tokens, $31.35, cache reads $18.03. Long refactor at 667K (calculated): 129.0M tokens, $39.47, cache reads $25.53. Long refactor at 800K (calculated): 130.5M tokens, $39.04, cache reads $25.86. Long refactor at 967K (calculated): 130.5M tokens, $39.04, cache reads $25.86.Cache readCache writeUncached inputOutputTask K, 101 calls: measured, mean of the clean runs (n = 2, 2, 1, 2, 2)Tokens (millions)010203040Trigger 50K, cache read: 2,860,852 tokens, 77.8% of 3.68MTrigger 50K, cache write: 669,741 tokens, 18.2% of 3.68M3.7M50KTrigger 100K, cache read: 5,157,169 tokens, 88.0% of 5.86MTrigger 100K, cache write: 630,906 tokens, 10.8% of 5.86M5.9M100KTrigger 200K, cache read: 10,198,880 tokens, 93.9% of 10.86MTrigger 200K, cache write: 620,697 tokens, 5.7% of 10.86M10.9M200KTrigger 400K, cache read: 16,855,697 tokens, 96.4% of 17.49MTrigger 400K, cache write: 613,867 tokens, 3.5% of 17.49M17.5M400KTrigger 600K, cache read: 29,612,975 tokens, 97.9% of 30.25MTrigger 600K, cache write: 614,719 tokens, 2.0% of 30.25M30.3M600KCost (USD at list prices)$0$5$10$15Trigger 50K, cache read: $0.57, 8.2% of $7.01Trigger 50K, cache write: $5.30, 75.6% of $7.01Trigger 50K, uncached input: $0.45, 6.4% of $7.01Trigger 50K, output: $0.69, 9.8% of $7.01$7.0150KTrigger 100K, cache read: $1.03, 15.3% of $6.75Trigger 100K, cache write: $5.04, 74.7% of $6.75Trigger 100K, uncached input: $0.19, 2.9% of $6.75Trigger 100K, output: $0.48, 7.2% of $6.75$6.75100KTrigger 200K, cache read: $2.04, 27.3% of $7.47Trigger 200K, cache write: $4.96, 66.5% of $7.47Trigger 200K, uncached input: $0.10, 1.3% of $7.47Trigger 200K, output: $0.37, 4.9% of $7.47$7.47200KTrigger 400K, cache read: $3.37, 39.3% of $8.59Trigger 400K, cache write: $4.91, 57.2% of $8.59Trigger 400K, output: $0.27, 3.2% of $8.59$8.59400KTrigger 600K, cache read: $5.92, 53.0% of $11.17Trigger 600K, cache write: $4.92, 44.0% of $11.17Trigger 600K, output: $0.30, 2.7% of $11.17$11.17600KLong refactor, 344 calls: calculated from the logged inputs, 1-hour cache writesTokens (millions)050100150Compaction trigger (tokens)Trigger 150K, cache read: 43,672,957 tokens, 95.5% of 45.75MTrigger 150K, cache write: 1,675,157 tokens, 3.7% of 45.75M46M150KTrigger 200K, cache read: 51,461,083 tokens, 97.0% of 53.04MTrigger 200K, cache write: 1,229,153 tokens, 2.3% of 53.04M53M200KTrigger 250K, cache read: 59,662,595 tokens, 97.8% of 61.00MTrigger 250K, cache write: 1,014,192 tokens, 1.7% of 61.00M61M250KTrigger 300K, cache read: 67,470,326 tokens, 98.2% of 68.73MTrigger 300K, cache write: 952,707 tokens, 1.4% of 68.73M69M300KTrigger 367K, cache read: 76,306,777 tokens, 98.3% of 77.59MTrigger 367K, cache write: 970,926 tokens, 1.3% of 77.59M78M367KTrigger 500K, cache read: 90,145,849 tokens, 98.7% of 91.37MTrigger 500K, cache write: 921,206 tokens, 1.0% of 91.37M91M500KTrigger 667K, cache read: 127,668,103 tokens, 99.0% of 128.97MTrigger 667K, cache write: 997,040 tokens, 0.8% of 128.97M129M667KTrigger 800K, cache read: 129,313,558 tokens, 99.1% of 130.53MTrigger 800K, cache write: 921,230 tokens, 0.7% of 130.53M131M800KTrigger 967K, cache read: 129,313,558 tokens, 99.1% of 130.53MTrigger 967K, cache write: 921,230 tokens, 0.7% of 130.53M131M967KCost (USD at list prices)$0$10$20$30$40Compaction trigger (tokens)Trigger 150K, cache read: $8.73, 29.7% of $29.39Trigger 150K, cache write: $13.40, 45.6% of $29.39Trigger 150K, uncached input: $0.18, 0.6% of $29.39Trigger 150K, output: $7.07, 24.1% of $29.39$29150KTrigger 200K, cache read: $10.29, 38.6% of $26.67Trigger 200K, cache write: $9.83, 36.9% of $26.67Trigger 200K, output: $6.46, 24.2% of $26.67$27200KTrigger 250K, cache read: $11.93, 45.5% of $26.23Trigger 250K, cache write: $8.11, 30.9% of $26.23Trigger 250K, output: $6.14, 23.4% of $26.23$26250KTrigger 300K, cache read: $13.49, 49.6% of $27.18Trigger 300K, cache write: $7.62, 28.0% of $27.18Trigger 300K, output: $6.03, 22.2% of $27.18$27300KTrigger 367K, cache read: $15.26, 52.4% of $29.10Trigger 367K, cache write: $7.77, 26.7% of $29.10Trigger 367K, output: $6.04, 20.8% of $29.10$29367KTrigger 500K, cache read: $18.03, 57.5% of $31.35Trigger 500K, cache write: $7.37, 23.5% of $31.35Trigger 500K, output: $5.93, 18.9% of $31.35$31500KTrigger 667K, cache read: $25.53, 64.7% of $39.47Trigger 667K, cache write: $7.98, 20.2% of $39.47Trigger 667K, output: $5.94, 15.0% of $39.47$39667KTrigger 800K, cache read: $25.86, 66.3% of $39.04Trigger 800K, cache write: $7.37, 18.9% of $39.04Trigger 800K, output: $5.80, 14.9% of $39.04$39800KTrigger 967K, cache read: $25.86, 66.3% of $39.04Trigger 967K, cache write: $7.37, 18.9% of $39.04Trigger 967K, output: $5.80, 14.9% of $39.04$39967K
Top row measured, bottom row calculated. Tokens are almost all cache reads at any trigger. Cost is not: in the measured runs cache writes are 76% of the bill at 50K and 44% at 600K, where cache reads take over. Uncached input is too small to see in most bars. Open this chart as an SVG file.
Data in this chart
Task K, measured: tokensCache readCache writeUncached inputOutput
50K2,860,852669,741112,28434,475
100K5,157,169630,90648,18424,224
200K10,198,880620,69724,19218,310
400K16,855,697613,8678,18713,680
600K29,612,975614,7198,20614,819
Task K, measured: USDCache readCache writeUncached inputOutput
50K$0.57$5.30$0.45$0.69
100K$1.03$5.04$0.19$0.48
200K$2.04$4.96$0.10$0.37
400K$3.37$4.91$0.03$0.27
600K$5.92$4.92$0.03$0.30
Long refactor, calculated: tokensCache readCache writeUncached inputOutput
150K43,672,9571,675,15745,292353,616
200K51,461,0831,229,15322,990322,782
250K59,662,5951,014,19211,839306,876
300K67,470,326952,7078,122301,574
367K76,306,777970,9268,122302,011
500K90,145,849921,2064,405296,435
667K127,668,103997,0404,405296,979
800K129,313,558921,230688289,992
967K129,313,558921,230688289,992
Long refactor, calculated: USDCache readCache writeUncached inputOutput
150K$8.73$13.40$0.18$7.07
200K$10.29$9.83$0.09$6.46
250K$11.93$8.11$0.05$6.14
300K$13.49$7.62$0.03$6.03
367K$15.26$7.77$0.03$6.04
500K$18.03$7.37$0.02$5.93
667K$25.53$7.98$0.02$5.94
800K$25.86$7.37$0.00$5.80
967K$25.86$7.37$0.00$5.80

Measured total tokens rise 8.2x from 50K to 600K. Measured cost rises 1.6x. The gap is the price ratio: a cache read is $0.20 per million tokens and a 1-hour cache write is $8. A low limit moves few tokens but rewrites them at the expensive rate after every compaction. A high limit moves many tokens at the cheap rate.

So "fewer tokens" and "cheaper" are different goals. Token count keeps falling as the limit drops. Cost has a minimum in the middle.

Quality: what a compaction keeps

I planted three kinds of fact:

  • Flagged. The task says up front that it will ask for them: a CHECK CODE in each file, and pack sizes and errata the final code must use.
  • Needed but never flagged. Format quirks stated once in an early file, which the final code needs.
  • Incidental. A clerk's surname in each file header, never mentioned by the task and asked for only at the end.
Kind of factSurvivedPer-compaction retentionFrom
Flagged by the task3,986 of 3,986at least 0.99925codes, pack sizes and errata in all runs that compacted
Needed but never flagged64 of 64at least 0.95424 format quirks in Task Q
Incidental, first compaction, 100-file sessions4 of 8950.45% (0.12% to 1.14%)a surname in each file header
Incidental, a later compaction0 of 2the survivors of the first
Incidental, first compaction, one 12-file session11 of 111 run
Incidental, second compaction, the same session0 of 61 run
What survived a compaction, by kind of fact (measured; bounds are one-sided 95%).
Facts recalled at the end of a 100-file session by compaction trigger, and the share of incidental facts that survive a compaction (measured)Trigger 50K: flagged facts 100% recalled, incidental facts 2.0% recalled (2 runs). Trigger 100K: flagged facts 100% recalled, incidental facts 9.0% recalled (2 runs). Trigger 200K: flagged facts 100% recalled, incidental facts 5.0% recalled (1 run). Trigger 400K: flagged facts 100% recalled, incidental facts 35.0% recalled (2 runs). Trigger 600K: flagged facts 100% recalled, incidental facts 3.0% recalled (2 runs). First-compaction survival of incidental facts: 0 of 196 at 50K, 0 of 182 at 100K, 3 of 192 at 200K, 0 of 130 at 400K, 1 of 195 at 600K; pooled 4 of 895.Flagged, measuredIncidental, measuredIncidental, calculatedLeft out of the meansRecalled at the end of the session, of 100 facts02550751000100K200K300K400K500K600KCompaction trigger (tokens)Facts recalledModel: incidental facts still in context at the end, at 0.45% survival per compaction (calculated)Trigger 50K: 100 of 100 flagged facts recalled in each of 2 clean runsTrigger 100K: 100 of 100 flagged facts recalled in each of 2 clean runsTrigger 200K: 100 of 100 flagged facts recalled in each of 1 clean runTrigger 400K: 100 of 100 flagged facts recalled in each of 2 clean runsTrigger 600K: 100 of 100 flagged facts recalled in each of 2 clean runsK-L050k-r1: trigger 50K, 14 compactions, 2 of 100 incidental facts recalledK-L050k-r2: trigger 50K, 14 compactions, 2 of 100 incidental facts recalledK-L100k-r1: trigger 100K, 6 compactions, 9 of 100 incidental facts recalledK-L100k-r2: trigger 100K, 6 compactions, 9 of 100 incidental facts recalledK-L200k-r1: trigger 200K, 3 compactions, 5 of 100 incidental facts recalledK-L200k-r2: trigger 200K, 3 compactions, 4 of 100 incidental facts recalledK-L400k-r1: trigger 400K, 1 compactions, 35 of 100 incidental facts recalledK-L400k-r2: trigger 400K, 1 compactions, 35 of 100 incidental facts recalledK-L600k-r1: trigger 600K, 1 compactions, 3 of 100 incidental facts recalledK-L600k-r2: trigger 600K, 1 compactions, 3 of 100 incidental facts recalled295353100 of 100 at every triggerIncidental: survived first compaction0%2%4%6%Trigger, and facts kept / enteredline: all runs pooled, 0.45%Trigger 50K: 0 of 196 incidental facts survived their first compaction (0.00%; 95% interval 0.00% to 1.86%)50K0/196Trigger 100K: 0 of 182 incidental facts survived their first compaction (0.00%; 95% interval 0.00% to 2.01%)100K0/182Trigger 200K: 3 of 192 incidental facts survived their first compaction (1.56%; 95% interval 0.32% to 4.50%)200K3/192Trigger 400K: 0 of 130 incidental facts survived their first compaction (0.00%; 95% interval 0.00% to 2.80%)400K0/130Trigger 600K: 1 of 195 incidental facts survived their first compaction (0.51%; 95% interval 0.01% to 2.82%)600K1/195
Measured, one dot per run. Flagged facts were recalled in full at every trigger. Incidental facts were recalled only if they were read after the last compaction, which is why 400K beats 600K: its one compaction came after call 64 or 66, the other after call 98. The blue line is the model at the pooled survival rate. Whiskers on the right are 95% intervals. Open this chart as an SVG file.
Data in this chart
RunTriggerCompactionsFlagged recalledIncidental recalledIn the means
K-L050k-r150K14100 of 1002 of 100yes
K-L050k-r250K14100 of 1002 of 100yes
K-L100k-r1100K6100 of 1009 of 100yes
K-L100k-r2100K6100 of 1009 of 100yes
K-L200k-r1200K3100 of 1005 of 100yes
K-L200k-r2200K3100 of 1004 of 100no
K-L400k-r1400K1100 of 10035 of 100yes
K-L400k-r2400K1100 of 10035 of 100yes
K-L600k-r1600K1100 of 1003 of 100yes
K-L600k-r2600K1100 of 1003 of 100yes
TriggerKept at first compactionEntered95% interval
50K01960.00% to 1.86%
100K01820.00% to 2.01%
200K31920.32% to 4.50%
400K01300.00% to 2.80%
600K11950.01% to 2.82%
  • Flagged facts: none lost. 3,986 times a flagged fact went through a compaction, and 0 were lost. The one-sided 95% bound is at least 0.99925 kept per compaction.
  • Needed but never flagged: none lost, on thin data. 64 exposures over 24 facts, bound 0.954.
  • Incidental: nearly all lost. 4 of 895 survived their first compaction: 0.45%, 95% interval 0.12% to 1.14%.

So at the end of a session the model recalled the incidental facts it had read since the last compaction and almost nothing older: 2, 9, 5, 35 and 3 of 100 at 50K, 100K, 200K, 400K and 600K.

In these runs a higher limit did not protect details. It moved the point where they were dropped. 400K kept the most only because its single compaction came early, after call 64 or 66 of about 100. At 600K the single compaction came after call 98 and wiped almost everything.

The model did not invent what it had lost. Of 1,000 answers about clerks, 0 were wrong. Every lost name came back as UNKNOWN.

One caution from a single short run: in a 12-file session at a 40K trigger, 11 of 11 incidental facts survived the first compaction and 0 of 6 survived the second. Summaries of small sessions may keep details that summaries of large ones drop. That rests on n = 1.

Working code is the test that matters most, and it did not move:

TriggerCompactionsTask S testsTask S costTask Q testsTask Q cost
50K559 of 59 in 3 runs$2.8063 of 63 in 2 runs$2.83
100K259 of 59 in 3 runs$2.7163 of 63 in 2 runs$2.71
200K159 of 59 in 3 runs$2.9763 of 63 in 2 runs$2.94
367K059 of 59 in 3 runs$3.1563 of 63 in 2 runs$3.15
Tasks S and Q: hidden tests passed and list-price cost per run (measured). Compaction counts matched the predictions in every run.

All 20 runs passed every hidden test, from 5 compactions down to 0. On these tasks the limit changed the cost and not the test results. That is a statement about these tasks: a 40-file job with its requirements in the opening prompt.

What it means for real sessions

These are calculated from the logged inputs, not measured:

TriggerWindow to setLong refactor: compactionsAverage contextCost, 1-hour cacheCost, 5-minute cacheMarathon: compactionsCost, 1-hour cacheCost, 5-minute cache
150K183K12126.7K$29.39$29.8261$139.31$141.16
200K233K6149.7K$26.67$29.5629$123.90$138.37
250K283K3174.2K$26.23$30.9119$125.13$147.04
300K333K2197.2K$27.18$33.0914$129.88$157.91
367K (default)400K2222.5K$29.10$36.1010$137.82$173.18
500K533K1263.3K$31.35$40.356$158.53$208.64
667K700K1372.1K$39.47$53.154$184.20$250.57
800K833K0378.6K$39.04$53.253$206.90$287.15
967K1M0378.6K$39.04$53.253$229.97$323.49
Session cost by trigger for the two long presets, measured overhead profile (calculated). Window = trigger + 33,000.
  • Long refactor, 344 calls. Cheapest at 250K: $26.23 with 3 compactions. The default costs $29.10, which is 10.9% more. A 1M window never compacts and costs $39.04, 34.1% more than the default, for 2.1x the tokens of the cheapest setting.
  • Marathon, 1,604 calls, my longest session. Cheapest at 200K: $123.90. The default costs $137.82 and a 1M window costs $229.97.
  • With an API key the gap widens. The long refactor costs $29.56 at 200K against $36.10 at the default, 22.1% more.

Most sessions never get that far. 526 of my 557 sessions (94.4%) never compacted. The median session is 37 calls, and at the median start and the mean growth per call the default trigger arrives at call 166. In a short session a lower limit can only add a compaction: the 66-call feature preset costs $4.04 at the default and $4.47 with a 150K trigger.

Cost against what a session keeps: measured Task K runs and the calculated long refactor, by compaction triggerTask K at 50K (measured): $7.01, 2 of 100 incidental facts recalled. Task K at 100K (measured): $6.75, 9 of 100 incidental facts recalled. Task K at 200K (measured): $7.47, 5 of 100 incidental facts recalled. Task K at 400K (measured): $8.59, 35 of 100 incidental facts recalled. Task K at 600K (measured): $11.17, 3 of 100 incidental facts recalled. Long refactor at 250K (calculated): $26.23, 3 compactions. Long refactor at 200K (calculated): $26.67, 6 compactions. Long refactor at 300K (calculated): $27.18, 2 compactions. Long refactor at 367K (calculated): $29.10, 2 compactions. Long refactor at 150K (calculated): $29.39, 12 compactions. Long refactor at 500K (calculated): $31.35, 1 compactions. Long refactor at 800K and 967K (calculated): $39.04, 0 compactions. Long refactor at 667K (calculated): $39.47, 1 compactions.Measured run, Task KCalculated, long refactorNot beaten on both axesTask K, 101 calls (measured)010203040$6$7$8$9$10$11$12Session cost (USD at list prices)Incidental facts recalled, of 100better: up and leftK-L050k-r1: trigger 50K, $7.0964, 2 of 100 incidental facts recalled, 14 compactionsK-L050k-r2: trigger 50K, $6.9153, 2 of 100 incidental facts recalled, 14 compactionsK-L100k-r1: trigger 100K, $6.7285, 9 of 100 incidental facts recalled, 6 compactionsK-L100k-r2: trigger 100K, $6.7780, 9 of 100 incidental facts recalled, 6 compactionsK-L200k-r1: trigger 200K, $7.4674, 5 of 100 incidental facts recalled, 3 compactionsK-L400k-r1: trigger 400K, $8.5175, 35 of 100 incidental facts recalled, 1 compactionsK-L400k-r2: trigger 400K, $8.6588, 35 of 100 incidental facts recalled, 1 compactionsK-L600k-r1: trigger 600K, $11.1430, 3 of 100 incidental facts recalled, 1 compactionsK-L600k-r2: trigger 600K, $11.1955, 3 of 100 incidental facts recalled, 1 compactions50K100K200K400K600KLong refactor, 344 calls (calculated)04812$25$30$35$40Session cost (USD at list prices)Compactions in the sessionbetter: down and leftLong refactor, trigger 250K: $26.23, 3 compactionsLong refactor, trigger 200K: $26.67, 6 compactions (another trigger is cheaper with no more compactions)Long refactor, trigger 300K: $27.18, 2 compactionsLong refactor, trigger 367K: $29.10, 2 compactions (another trigger is cheaper with no more compactions)Long refactor, trigger 150K: $29.39, 12 compactions (another trigger is cheaper with no more compactions)Long refactor, trigger 500K: $31.35, 1 compactionsLong refactor, trigger 800K and 967K: $39.04, 0 compactionsLong refactor, trigger 667K: $39.47, 1 compactions (another trigger is cheaper with no more compactions)250K200K300K367K150K500K800K, 967K667K
Left, measured: only 100K and 400K are not beaten on both cost and incidental recall. Right, calculated: the default of 367K is beaten by 300K, which compacts as often and costs $1.92 less. Open this chart as an SVG file.
Data in this chart
TriggerCost (USD)CompactionsNot beaten on both
150K$29.3912no
200K$26.676no
250K$26.233yes
300K$27.182yes
367K$29.102no
500K$31.351yes
667K$39.471no
800K$39.040yes
967K$39.040yes

A compaction also stops the session while the summary is written: 71 seconds at the median in my logs (n = 48), and a median of 12 to 32 seconds, depending on the trigger, in the Task K runs. The long refactor waits 142 seconds in total at the default and 213 at 250K.

Try your own numbers

Compaction limit calculator

This runs the article's model in your browser. Every input it uses is listed under the chart. Results are calculated, not measured, except the orange dots shown with the Task K preset.

Overhead on every request
Cache write price
Compactions in the session
2the first after call 165, then every 151 calls
Context after a compaction
108,134 tokenswhat is reloaded plus the summary and the turns kept
Average context per call
222,527 tokens
Largest context sent
366,284 tokens
Session cost at list prices
$29.10$0.0846 per call
Flagged facts kept
at least 99.85%facts the task says matter, after 2 compactions at the measured floor of 0.99925 each
Incidental details still in context
8.3%about the last 28 of 344 calls; 0.45% of older detail survived a compaction in the runs
Waiting on summaries
142 s71 s per compaction, the median in the logged sessions
Token classTokensCost (USD)
Cache read76,306,776$15.26
Cache write970,926$7.77
Uncached input8,122$0.03
Output302,011$6.04
Total77,587,836$29.10
$0$20$40$60$800200K400K600K800K1MCompaction limit: the trigger, in tokensSession cost (USD)367K: $29.10, 2 compactions

Blue line: the model's session cost at every limit for this session. White dot: your limit.

Every assumption behind this result
SymbolWhat it isValueWhere it comes from
TCalls in the session344preset: median session of those with 200 or more calls
gTokens added to the context per call1,721preset: median session of those with 200 or more calls
LCompaction trigger367,000your input
sContext of the first call83,438measured from session logs
sAfterReloaded after every compaction85,333measured from session logs
c0 + phi * LSummary plus turns kept verbatim20,661 + 0.00583 * Lmeasured from session logs, linear fit
sWarmPart of the first call already cached11,633measured from session logs
sCachedStill cached after a compaction27,666measured from session logs
oOutput tokens per call, thinking included843measured from session logs
uUncached input tokens per call2measured from session logs
rhoShare of calls that find the cache expired0.20%measured from session logs
sigma + sigmaPhi * LOutput tokens of one summary4,813 + 0.00326 * Lcalculated from logged summary lengths
wTokens the summary request adds1,996measured, identical in every compaction
PricesUSD per million tokens: input, cache write, cache read, output4, 8, 0.2, 20documented; cache writes at the 1-hour price
WindowClaude Code auto-compact window for this trigger400,000trigger plus 33,000, the gap at both documented windows

Choosing a limit

  • Long sessions on a subscription, with a setup like mine: /autocompact 250k, a trigger of 217K. Anything from 196K to 246K costs the same within 1%.
  • Long sessions on an API key: /autocompact 210k, a trigger of 177K.
  • A lean setup with few or no instruction files: /autocompact 150k on a subscription, /autocompact 130k on an API key.
  • Short sessions: leave it alone. A session with the median start and the mean growth does not reach the default before call 166.
  • Do not go too low. With 108.1K tokens reloaded after each compaction, a trigger of 100K or less leaves no room and the model has it compacting after every call.
  • A 1M window removes the compactions from a 344-call session for $9.93 more than the default (calculated). With no summary, nothing is dropped by one, so it is the setting to try when the work depends on details nobody wrote down. I did not measure recall inside a context that large.
  • If a detail matters, flag it. Put it in the prompt or in CLAUDE.md, which is reloaded from disk after every compaction, or run /compact focus on ... to say what to keep. Flagged facts survived every compaction I measured.
  • API users: the lean profile is the closer match for an app with a small system prompt. It puts the cheapest trigger at 96.5K with 5-minute writes, below the API default of 150,000. That is calculated with Claude Code's compaction mechanics and my session shape. I ran nothing against the API's own compaction.

Limitations

  • Small n. One to three runs per cell. Task K has 2 clean runs per trigger and 1 at 200K; the two runs of a pair differ in cost by up to 2.6%. The retention bounds treat every exposure as an independent trial. They are not independent: one fact passes several compactions inside the same run.
  • Synthetic tasks. Each step adds 6,135 tokens against 1,763 in my real sessions, and the first call is 3,566 tokens against 74,457. The runs test the formulas. The dollar figures for real sessions come from the formulas.
  • Quality was not separated by these tasks. Every run passed every hidden test, so I can say a low limit was safe here, not that it is safe for harder work. I did not measure answer quality as context grows. The API docs say "as a conversation grows, response quality degrades"; if that holds, it is one more reason to go lower that this study does not price.
  • One machine's logs. My overhead of 74,457 tokens is large. The fit for what a compaction keeps is weak (correlation 0.19, n = 48), and the straight-line growth assumption gives 95.8% of logged cost.
  • Summaries prepared early. 7 of the automatic compactions in my interactive logs had their summary written before the boundary and kept about 46,421 tokens, roughly twice what the model assumes. The model does not cover that path, and the test runs never took it.
  • Extrapolation. Measured triggers stop at 600K. Everything at 967K is the model. Logged compactions covered triggers from 200.2K to 773.1K.
  • Versions and prices. Claude Code 2.1.335, prices read 2026-12-02. Anthropic tunes auto per model and can change it.
  • Runs not done. Four planned runs were not run: a second clean run at 200K and three more 12-file sessions.

Reproduce it

Check the arithmetic without spending anything. This prices Task K at a 100K trigger and prints the compaction count and the cost:

bashcurl -sO https://ai-compare.fly.dev/data/opus-5-5-compaction/model.mjs
node -e "import('./model.mjs').then((m) => { const t = m.totals({s:3566,sWarm:2732,sCached:2732,g:6135,u:2,w:1996,o:156,c0:7755,phi:0.00277,sigma:1278,sigmaPhi:0.00202,sAfter:3566,T:101,L:100000}); console.log(t.compactions, m.cost(t, m.OPUS_5_5.prices, '1h').total.toFixed(4)); })"
# 6 6.7727

Run one real session. It needs the Claude Code CLI signed in to a subscription, and it writes one row per run to confirm/runs.jsonl:

bashbase=https://ai-compare.fly.dev/data/opus-5-5-compaction
mkdir -p compaction/confirm && cd compaction
curl -sO $base/model.mjs -O $base/measure-summary.mjs
(cd confirm && curl -sO $base/confirm/harness.mjs -O $base/confirm/fixtures.mjs -O $base/confirm/grade_ledger.py)
node confirm/harness.mjs --plan main --list
nice -n 10 node confirm/harness.mjs --plan main --only K-L100k-r1 --concurrency 1

A Task K run at 100K cost $6.75 on average at list prices. All 33 runs cost $143.55, plus $9.29 for the 4 calibration runs.