Opus 5.5 Compaction Limits: What Each Trigger Costs and Keeps

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 500kin a sessionautoCompactWindowin settings--autocompactat launchCLAUDE_CODE_AUTO_COMPACT_WINDOWin 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 class | USD per million | When it is billed |
|---|---|---|
| Uncached input | $4 | New input that is not written to the cache |
| Cache write, 5-minute | $5 | New context on an API key; every compaction request |
| Cache write, 1-hour | $8 | New context in the main conversation on a subscription |
| Cache read | $0.20 | The context already cached, on every call |
| Output | $20 | Responses, thinking and summaries |
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 callsIn plain terms: the context is a saw-tooth that climbs from R to L and drops back. A lower limit means more teeth.
Data in this chart
| Trigger | Compactions | Average context | Session cost |
|---|---|---|---|
| 150K | 12 | 126,660 | $29.39 |
| 367K | 2 | 222,527 | $29.10 |
| 967K | 0 | 378,590 | $39.04 |
Each kind of call bills differently:
- An ordinary call reads the previous context from cache and writes the
gnew tokens. - The call after a compaction finds only the system prompt and tools in cache (
sCached) and writes the rest ofRagain. - The summary request reads the whole pre-compaction context from cache, adds
g + wuncached tokens, and writes the summary as output. - Output is
otokens 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 * sigmaSimply 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.
| Symbol | What it is | Value | Spread or n | Kind |
|---|---|---|---|---|
| g | Context growth per call, tokens (mean) | 1,763 | p50 1,099, p90 3,620, n 34,380 | measured |
| s | Context of the first call (median) | 74,457 | p10 58,788, p90 95,661 | measured |
| sWarm | Part of the first call already cached (median) | 11,633 | n 557 | measured |
| sCached | Still cached after a compaction: system prompt and tools (median) | 27,666 | n 55 | measured |
| sAfter | Reloaded after every compaction (median) | 76,352 | n 48 | measured |
| c0 + phi * L | Summary plus turns kept verbatim | 20,661 + 0.00583 * L | n 48, correlation 0.19, sd 4,043 | measured fit |
| o | Output tokens per call, thinking included (mean) | 742 | n 34,996 | measured |
| u | Uncached input per call | 2 | measured | |
| rho, 1-hour cache | Calls that found the cache expired | 0.2% | measured | |
| rho, 5-minute cache | Share of gaps between calls over 5 minutes | 2.93% | calculated | |
| sigma + sigmaPhi * L | Output tokens of one summary | 4,813 + 0.00326 * L | 2.63 characters per token | calculated |
| w | Tokens the summarization request adds | 1,996 | identical in every measured compaction | measured |
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:
| Preset | Calls T | Growth g | First context s | Sessions in the bucket |
|---|---|---|---|---|
| Short fix | 26 | 1,898 | 72,613 | 367 |
| Feature | 66 | 1,709 | 72,722 | 155 |
| Long refactor | 344 | 1,721 | 83,438 | 35 |
| Marathon (the longest session) | 1,604 | 1,721 | 83,438 | 1 |
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
| Overhead profile | Cache writes | Cheapest trigger | Cost per call there | At 367K (default) | At 967K (1M window) | Within 1% of cheapest | Setting |
|---|---|---|---|---|---|---|---|
| Measured | 1-hour (subscription) | 217.5K | $0.0778 | $0.0871 (+12.0%) | $0.1486 (+90.9%) | 196K to 246K | /autocompact 250k |
| Measured | 5-minute (API key) | 180K | $0.0869 | $0.1099 (+26.5%) | $0.2102 (+141.9%) | 166K to 201K | /autocompact 210k |
| Lean | 1-hour (subscription) | 117K | $0.0561 | $0.0774 (+38.0%) | $0.1414 (+152.2%) | 104K to 134K | /autocompact 150k |
| Lean | 5-minute (API key) | 96.5K | $0.0584 | $0.0977 (+67.3%) | $0.1997 (+241.9%) | 89K to 109K | /autocompact 130k |
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.
| Task | What the model does | Graded on | Triggers | Runs |
|---|---|---|---|---|
| K | Reads 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 mentioned | Flagged and incidental facts | 50K, 100K, 200K, 400K, 600K | 10 |
| S | Reads 40 files, then writes a module to a 14-requirement spec from the opening prompt | 59 hidden tests | 50K, 100K, 200K, 367K | 12 |
| Q | Task S plus 4 format quirks, each noted once in an early file and never flagged | 63 hidden tests | 50K, 100K, 200K, 367K | 8 |
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 --verboseThat 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) | 50K | 100K | 200K | 400K | 600K |
|---|---|---|---|---|---|
| Compactions, predicted | 14 | 6 | 3 | 1 | 1 |
| Compactions, measured (exact) | 14 | 6 | 3 | 1 | 1 |
| 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, predicted | 29,179 | 52,238 | 98,634 | 171,337 | 292,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, predicted | 11,460 | 11,598 | 11,875 | 12,429 | 12,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, predicted | 1,379 | 1,480 | 1,682 | 2,086 | 2,490 |
| Summary output tokens, measured (within 25%) | 1,627 (+18%) | 1,829 (+24%) | 2,190 (+30%) out | 2,206 (+6%) | 2,886 (+16%) |
| Cost per call USD, measured | $0.0694 | $0.0679 | $0.0739 | $0.0859 | $0.1111 |
Data in this chart
| Run | Trigger | Calls | Compactions | Cost (USD) | Total tokens | In the means |
|---|---|---|---|---|---|---|
| K-L050k-r1 | 50K | 101 | 14 | $7.0964 | 3,672,442 | yes |
| K-L050k-r2 | 50K | 101 | 14 | $6.9153 | 3,682,259 | yes |
| K-L100k-r1 | 100K | 100 | 6 | $6.7285 | 5,899,810 | yes |
| K-L100k-r2 | 100K | 99 | 6 | $6.7780 | 5,821,155 | yes |
| K-L200k-r1 | 200K | 101 | 3 | $7.4674 | 10,862,079 | yes |
| K-L200k-r2 | 200K | 94 | 3 | $8.2971 | 10,516,837 | no |
| K-L400k-r1 | 400K | 99 | 1 | $8.5175 | 17,193,402 | yes |
| K-L400k-r2 | 400K | 101 | 1 | $8.6588 | 17,789,459 | yes |
| K-L600k-r1 | 600K | 101 | 1 | $11.1430 | 30,089,082 | yes |
| K-L600k-r2 | 600K | 100 | 1 | $11.1955 | 30,412,355 | yes |
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.
Where the money goes
Data in this chart
| Task K, measured: tokens | Cache read | Cache write | Uncached input | Output |
|---|---|---|---|---|
| 50K | 2,860,852 | 669,741 | 112,284 | 34,475 |
| 100K | 5,157,169 | 630,906 | 48,184 | 24,224 |
| 200K | 10,198,880 | 620,697 | 24,192 | 18,310 |
| 400K | 16,855,697 | 613,867 | 8,187 | 13,680 |
| 600K | 29,612,975 | 614,719 | 8,206 | 14,819 |
| Task K, measured: USD | Cache read | Cache write | Uncached input | Output |
|---|---|---|---|---|
| 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: tokens | Cache read | Cache write | Uncached input | Output |
|---|---|---|---|---|
| 150K | 43,672,957 | 1,675,157 | 45,292 | 353,616 |
| 200K | 51,461,083 | 1,229,153 | 22,990 | 322,782 |
| 250K | 59,662,595 | 1,014,192 | 11,839 | 306,876 |
| 300K | 67,470,326 | 952,707 | 8,122 | 301,574 |
| 367K | 76,306,777 | 970,926 | 8,122 | 302,011 |
| 500K | 90,145,849 | 921,206 | 4,405 | 296,435 |
| 667K | 127,668,103 | 997,040 | 4,405 | 296,979 |
| 800K | 129,313,558 | 921,230 | 688 | 289,992 |
| 967K | 129,313,558 | 921,230 | 688 | 289,992 |
| Long refactor, calculated: USD | Cache read | Cache write | Uncached input | Output |
|---|---|---|---|---|
| 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 fact | Survived | Per-compaction retention | From |
|---|---|---|---|
| Flagged by the task | 3,986 of 3,986 | at least 0.99925 | codes, pack sizes and errata in all runs that compacted |
| Needed but never flagged | 64 of 64 | at least 0.954 | 24 format quirks in Task Q |
| Incidental, first compaction, 100-file sessions | 4 of 895 | 0.45% (0.12% to 1.14%) | a surname in each file header |
| Incidental, a later compaction | 0 of 2 | the survivors of the first | |
| Incidental, first compaction, one 12-file session | 11 of 11 | 1 run | |
| Incidental, second compaction, the same session | 0 of 6 | 1 run |
Data in this chart
| Run | Trigger | Compactions | Flagged recalled | Incidental recalled | In the means |
|---|---|---|---|---|---|
| K-L050k-r1 | 50K | 14 | 100 of 100 | 2 of 100 | yes |
| K-L050k-r2 | 50K | 14 | 100 of 100 | 2 of 100 | yes |
| K-L100k-r1 | 100K | 6 | 100 of 100 | 9 of 100 | yes |
| K-L100k-r2 | 100K | 6 | 100 of 100 | 9 of 100 | yes |
| K-L200k-r1 | 200K | 3 | 100 of 100 | 5 of 100 | yes |
| K-L200k-r2 | 200K | 3 | 100 of 100 | 4 of 100 | no |
| K-L400k-r1 | 400K | 1 | 100 of 100 | 35 of 100 | yes |
| K-L400k-r2 | 400K | 1 | 100 of 100 | 35 of 100 | yes |
| K-L600k-r1 | 600K | 1 | 100 of 100 | 3 of 100 | yes |
| K-L600k-r2 | 600K | 1 | 100 of 100 | 3 of 100 | yes |
| Trigger | Kept at first compaction | Entered | 95% interval |
|---|---|---|---|
| 50K | 0 | 196 | 0.00% to 1.86% |
| 100K | 0 | 182 | 0.00% to 2.01% |
| 200K | 3 | 192 | 0.32% to 4.50% |
| 400K | 0 | 130 | 0.00% to 2.80% |
| 600K | 1 | 195 | 0.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:
| Trigger | Compactions | Task S tests | Task S cost | Task Q tests | Task Q cost |
|---|---|---|---|---|---|
| 50K | 5 | 59 of 59 in 3 runs | $2.80 | 63 of 63 in 2 runs | $2.83 |
| 100K | 2 | 59 of 59 in 3 runs | $2.71 | 63 of 63 in 2 runs | $2.71 |
| 200K | 1 | 59 of 59 in 3 runs | $2.97 | 63 of 63 in 2 runs | $2.94 |
| 367K | 0 | 59 of 59 in 3 runs | $3.15 | 63 of 63 in 2 runs | $3.15 |
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:
| Trigger | Window to set | Long refactor: compactions | Average context | Cost, 1-hour cache | Cost, 5-minute cache | Marathon: compactions | Cost, 1-hour cache | Cost, 5-minute cache |
|---|---|---|---|---|---|---|---|---|
| 150K | 183K | 12 | 126.7K | $29.39 | $29.82 | 61 | $139.31 | $141.16 |
| 200K | 233K | 6 | 149.7K | $26.67 | $29.56 | 29 | $123.90 | $138.37 |
| 250K | 283K | 3 | 174.2K | $26.23 | $30.91 | 19 | $125.13 | $147.04 |
| 300K | 333K | 2 | 197.2K | $27.18 | $33.09 | 14 | $129.88 | $157.91 |
| 367K (default) | 400K | 2 | 222.5K | $29.10 | $36.10 | 10 | $137.82 | $173.18 |
| 500K | 533K | 1 | 263.3K | $31.35 | $40.35 | 6 | $158.53 | $208.64 |
| 667K | 700K | 1 | 372.1K | $39.47 | $53.15 | 4 | $184.20 | $250.57 |
| 800K | 833K | 0 | 378.6K | $39.04 | $53.25 | 3 | $206.90 | $287.15 |
| 967K | 1M | 0 | 378.6K | $39.04 | $53.25 | 3 | $229.97 | $323.49 |
- 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.
Data in this chart
| Trigger | Cost (USD) | Compactions | Not beaten on both |
|---|---|---|---|
| 150K | $29.39 | 12 | no |
| 200K | $26.67 | 6 | no |
| 250K | $26.23 | 3 | yes |
| 300K | $27.18 | 2 | yes |
| 367K | $29.10 | 2 | no |
| 500K | $31.35 | 1 | yes |
| 667K | $39.47 | 1 | no |
| 800K | $39.04 | 0 | yes |
| 967K | $39.04 | 0 | yes |
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.
- 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 class | Tokens | Cost (USD) |
|---|---|---|
| Cache read | 76,306,776 | $15.26 |
| Cache write | 970,926 | $7.77 |
| Uncached input | 8,122 | $0.03 |
| Output | 302,011 | $6.04 |
| Total | 77,587,836 | $29.10 |
Blue line: the model's session cost at every limit for this session. White dot: your limit.
Every assumption behind this result
| Symbol | What it is | Value | Where it comes from |
|---|---|---|---|
T | Calls in the session | 344 | preset: median session of those with 200 or more calls |
g | Tokens added to the context per call | 1,721 | preset: median session of those with 200 or more calls |
L | Compaction trigger | 367,000 | your input |
s | Context of the first call | 83,438 | measured from session logs |
sAfter | Reloaded after every compaction | 85,333 | measured from session logs |
c0 + phi * L | Summary plus turns kept verbatim | 20,661 + 0.00583 * L | measured from session logs, linear fit |
sWarm | Part of the first call already cached | 11,633 | measured from session logs |
sCached | Still cached after a compaction | 27,666 | measured from session logs |
o | Output tokens per call, thinking included | 843 | measured from session logs |
u | Uncached input tokens per call | 2 | measured from session logs |
rho | Share of calls that find the cache expired | 0.20% | measured from session logs |
sigma + sigmaPhi * L | Output tokens of one summary | 4,813 + 0.00326 * L | calculated from logged summary lengths |
w | Tokens the summary request adds | 1,996 | measured, identical in every compaction |
Prices | USD per million tokens: input, cache write, cache read, output | 4, 8, 0.2, 20 | documented; cache writes at the 1-hour price |
Window | Claude Code auto-compact window for this trigger | 400,000 | trigger 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 150kon a subscription,/autocompact 130kon 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
autoper 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
- opus-5-5-compaction-limits.csv: every number in this article, 2,341 rows, each marked documented, measured, predicted or calculated
- confirmation-runs.json: per-run results of the 33 runs
- model.mjs: the formulas, as functions of the trigger
- measure-summary.mjs: the calibration runs and the file generator
- confirm/harness.mjs: the queue that launched and recorded the confirmation runs
- confirm/fixtures.mjs: the task files and prompts
- confirm/grade_ledger.py: the hidden tests for tasks S and Q
- Charts as SVG files: sawtooth, cost-per-call, predicted-vs-measured, token-split, compactions, retention, frontier
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.7727Run 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 1A 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.