When should Claude Sonnet 5.5 compact?Claude Sonnet 5.5 该在什么时候压缩?

Claude Code compacts on its own once a conversation gets big enough. You decide how big with the autoCompactWindow setting. Here is what that choice costs, based on 216 real sessions.对话长到一定程度,Claude Code 会自动压缩。多长由 autoCompactWindow 设置决定。这个选择要花多少钱,下面用 216 个真实会话来回答。

Pick a threshold选一个阈值

Each card is the cheapest trigger that keeps compaction within a share of your working time. They change when you move the speed slider under the chart.每张卡片是在压缩时间不超过你工作时间某个比例的前提下,最省钱的触发点。拖动图表下方的速度滑块,它们会跟着变。

Which number do I type?该填哪个数字?

The setting is autoCompactWindow, in tokens. It accepts 100K to 1M and works globally or per model under modelSettings. Claude Code does not compact at the window itself. It keeps a buffer of 33K free for writing the summary, so it compacts when the context reaches the window minus 33K. The chart is drawn against that real trigger, so type trigger + 33K. For example, a trigger of 267K means autoCompactWindow: 300000.设置项是 autoCompactWindow,单位是 token,取值 100K 到 1M,可以全局设置,也可以在 modelSettings 里按模型设置。Claude Code 不会等到窗口满了才压缩,它要留出 33K 给写摘要用,所以实际在上下文达到窗口减 33K时压缩。这张图画的是这个真实触发点,所以要填触发点加 33K。比如触发点 267K,就设 autoCompactWindow: 300000。

The buffer is 33K, from three sources. Claude Code's documentation says sessions with a 1M window auto-compact at about 967K by default. The installed Claude Code reserves 20K for the summary plus a 13K margin. And in the logs, automatic compactions of Claude Sonnet 5.5 happened at a median of 267.9K under a window of 300K, a buffer of 32.1K. The highest trigger you can set is 1M minus 33K, which is 967K, so the chart ends there. Claude Code also caps the window at the model's own context window of 1M.缓冲是 33K,有三处依据。Claude Code 文档说,窗口为 1M 时默认大约在 967K 处自动压缩;已安装的 Claude Code 预留 20K 给摘要,再加 13K 余量;日志里 Claude Sonnet 5.5 的自动压缩,在窗口 300K 下发生在中位数 267.9K,缓冲约 32.1K。你能设的最高触发点是 1M 减 33K,即 967K,所以图画到这里。窗口还会被限制在模型自身 1M 的上下文窗口以内。

Cost and waiting at every trigger每个触发点的费用和等待

Blue is what one million billed tokens of your usage costs at each trigger. Orange is the share of working time spent compacting. Hover or tap the chart to read any trigger. The shaded bands show the likely range.蓝线是在各个触发点下,用量里每一百万个计费 token 的花费。橙线是用在压缩上的工作时间占比。把鼠标移到图上或点一下,就能读出任意触发点的数值。浅色带是可能的范围。

Compaction time is mostly the model writing its summary. If your server is faster or slower than the measured 149 tokens per second, move the slider. Cost does not change.压缩耗时主要花在模型写摘要上。如果你的服务比实测的每秒 149 个 token 更快或更慢,就拖动滑块。费用不会变。

Costs use standard Claude Sonnet 5.5 API prices per million tokens: input $2, cache write $2.5 (5 minutes) or $4 (1 hour), cache read $0.20, output $10.费用按 Claude Sonnet 5.5 的标准 API 价格计算(每百万 token:输入 $2,缓存写入 5 分钟 $2.5 / 1 小时 $4,缓存读取 $0.20,输出 $10)。

Cost is per 1M tokens billed with the mix seen in these sessions: 95.0% cache reads, 0.1% cache writes (1 hour), 4.4% cache writes (5 minutes), 0.0% plain input, 0.5% output.费用按每 100 万个计费 token 计算,构成与这些会话一致:缓存读取 95.0%、缓存写入(1 小时)0.1%、缓存写入(5 分钟)4.4%、普通输入 0.0%、输出 0.5%。

How to read it怎么看这张图

Where this can mislead you哪些地方可能误导你

How the numbers were made这些数字是怎么算出来的

In short: we replayed real sessions at every trigger and added up what they would have cost and how long compaction would have taken.简单说:我们用真实使用记录在每个触发点上重放一遍,把费用和压缩耗时加起来。

  1. Real requests真实请求Request by request, from 8,752 real Claude Sonnet 5.5 requests in Claude Code transcripts: the context size, the cached share and the output of each one. Both the main conversation and its subagents count.逐个请求分析 Claude Code 转录里的 8,752 个真实 Claude Sonnet 5.5 请求:每个请求的上下文大小、缓存命中比例和输出量。主对话和子代理都计入。
  2. Measured compactions实测压缩Only 21 real compactions were recorded for Claude Sonnet 5.5, all near 267.9K. They fix the level of compaction time. How it grows with context comes from 260 compactions of Claude Opus 5.5, rescaled to match. See the caveats.Claude Sonnet 5.5 只记录到 21 次真实压缩,都在 267.9K 附近,它们决定压缩耗时的整体水平。耗时如何随上下文增长,则取自 Claude Opus 5.5 的 260 次压缩,并按比例换算。详见注意事项。
  3. More workloads扩充工作负载Each session's request-to-request changes are cut into blocks of 8 requests and reshuffled with a fixed random seed. That gives 100 extra workloads that behave like the real one.把每个会话里相邻请求的变化切成每 8 个请求一块,用固定的随机种子重新洗牌,得到 100 组行为和真实记录相似的工作负载。
  4. Replay and average重放并取平均Every workload is replayed at every trigger. We average the cost and the compaction time over all 100 workloads. The final curves are not smoothed.每组工作负载在每个触发点上各重放一遍,再对 100 组的费用和压缩耗时取平均。最终曲线没有做平滑。

Data volume数据量

216 independent work sessions (5 main conversations and 211 subagent sessions), 8,752 deduplicated requests and about 38 hours of agent time. 21 real compactions calibrate the model. Sessions that used other models, and sessions with no Claude Sonnet 5.5 request, are left out. Work time is the gap between neighbouring requests, with gaps over 5 minutes counted as idle and compaction time removed. The main conversation and parallel subagents are added together.216 个独立工作会话(5 个主对话和 211 个子代理会话),共 8,752 个去重请求,约 38 小时的代理时间。21 次真实压缩用来校准模型。用了其他模型的会话,以及没有 Claude Sonnet 5.5 请求的会话,都没有计入。工作时间按相邻请求的间隔估算,超过 5 分钟的间隔算空闲,并扣掉压缩耗时。主对话和并行的子代理时间是加在一起的。

Cost per 1M tokens每 100 万 token 的费用

The chart does not show the total bill of the sessions, because that would grow with the amount of history. Every cost is the replay cost at that trigger divided by the billed tokens of the real history (1,051 million), times one million. The divisor is one fixed number per model, not the token count of each replay. The reference million therefore has the real billing mix: 95.0% cache reads, 0.1% cache writes (1 hour), 4.4% cache writes (5 minutes), 0.0% plain input and 0.5% output. Costs are comparable between models and between amounts of history.图上不是这些会话的总账单,因为总账单会随历史数据的多少而变。每个费用都是该触发点下重放得到的总费用,除以真实历史的计费 token 数(1,051 百万),再乘以一百万。除数是每个模型固定的一个数,不是每次重放的 token 数。所以这一百万 token 的构成与真实计费一致:缓存读取 95.0%、缓存写入(1 小时)0.1%、缓存写入(5 分钟)4.4%、普通输入 0.0%、输出 0.5%。这样不同模型、不同数据量之间的费用可以直接比较。

Formula and symbols公式和符号

The cost of one request comes first. Then ordinary requests and compactions are added up over the whole workload.先算一次请求的费用,再把普通请求和压缩在整个工作负载上加起来。

Cost of one request Q(x, c, y) = p_m · [ω(1-c) + αc] · x + p_o · y Price ratios α = p_c / p_m ρ = p_o / p_m B = ω(1-β) + αβ Total cost J(T) = Σ Q(ordinary requests) + Σ Q(compaction input and summary output) Time of one compaction t_c = a · C + G / v Time share N_c(T) · t_c(T) / [W + N_c(T) · t_c(T)] Steady-state approximation T* ≈ R + √( 2Δ · (BR + ρG) / α )单次请求费用 Q(x, c, y) = p_m · [ω(1-c) + αc] · x + p_o · y 价格比例 α = p_c / p_m ρ = p_o / p_m B = ω(1-β) + αβ 总费用 J(T) = Σ Q(普通请求) + Σ Q(压缩输入与摘要输出) 单次压缩耗时 t_c = a · C + G / v 时间占比 N_c(T) · t_c(T) / [W + N_c(T) · t_c(T)] 稳态近似 T* ≈ R + √( 2Δ · (BR + ρG) / α )
xContext tokens in one request.一次请求里的上下文 token 数。
yOutput tokens of that request, billed at the output price.这次请求输出的 token 数,按输出价格计费。
cShare of a request's input that hits the prompt cache.请求输入中命中提示缓存的比例。
p_m / p_c / p_oPrice per token of uncached input, cached input and output.未缓存输入、缓存输入和输出的每 token 价格。
αCached input price divided by uncached input price; Claude Sonnet 5.5: 0.1.缓存输入价格除以未缓存输入价格;Claude Sonnet 5.5 为 0.1。
ρOutput price divided by uncached input price; Claude Sonnet 5.5: 5.输出价格除以未缓存输入价格;Claude Sonnet 5.5 为 5。
BEffective price of one ordinary context token, after the cache hit rate.考虑缓存命中率后,一个普通上下文 token 的有效价格。
C / KC is the compaction input: the whole context before compaction. Almost all of it is billed as cache reads. K differs from C only by the few thousand tokens added in the last turn, so K does not appear in the formula.C 是压缩输入,也就是压缩前的整段上下文,几乎全部按缓存读取计费。K 和 C 只差最后一轮新增的几千 token,所以公式里不出现 K。
T / RT is the compaction trigger; R is the context right after a compaction.T 是压缩触发点;R 是刚压缩完时的上下文大小。
ΔHow many tokens the context grows after each ordinary request, on average.每个普通请求之后,上下文平均增长多少 token。
GSummary tokens actually written, and billed, in one compaction.一次压缩实际写出并计费的摘要 token 数。
βShare of the compaction input that hits the cache.压缩输入中命中缓存的比例。
aSeconds to process one context token, fitted on the measured compactions. Cache reads take the same time.处理一个上下文 token 的时间,单位是秒,由实测压缩拟合。缓存读取同样耗时。
vHow fast the summary is written, in tokens per second. The slider changes this one.摘要的生成速度,单位是 token 每秒。滑块调的就是它。
ω is how many times the base input price an uncached token costs: 2 for a 1-hour cache write, 1.25 for 5 minutes, weighted by what was really written.ω 是未缓存 token 的价格相对基础输入价的倍数:1 小时缓存写入是 2,5 分钟是 1.25,按真实的写入比例加权。
N_c / t_c / WNumber of compactions, time of one compaction, and working time without compaction.压缩次数、单次压缩耗时,以及不含压缩的工作时间。

What moves the best trigger哪些因素会挪动最佳触发点

The time model is fitted to 281 compactions: R² = 0.71. Summary size alone gives 0.67, input size alone gives -0.01. The closed-form formula explains the direction of each effect. The chart itself comes from the replay, which keeps the real order of requests, the real growth and the real moments of compaction.时间模型用 281 次压缩拟合,R² = 0.71;只用摘要大小是 0.67,只用输入大小是 -0.01。闭式公式用来解释每个因素的影响方向,图上的曲线来自重放,保留了真实的请求顺序、上下文增长和压缩时点。