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 555 real sessions.对话长到一定程度,Claude Code 会自动压缩。多长由 autoCompactWindow 设置决定。这个选择要花多少钱,下面用 555 个真实会话来回答。
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.每张卡片是在压缩时间不超过你工作时间某个比例的前提下,最省钱的触发点。拖动图表下方的速度滑块,它们会跟着变。
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 Opus 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 Opus 5.5 的自动压缩,在窗口 300K 下发生在中位数 267.9K,缓冲约 32.1K。你能设的最高触发点是 1M 减 33K,即 967K,所以图画到这里。窗口还会被限制在模型自身 1M 的上下文窗口以内。
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 的花费。橙线是用在压缩上的工作时间占比。把鼠标移到图上或点一下,就能读出任意触发点的数值。浅色带是可能的范围。
Costs use standard Claude Opus 5.5 API prices per million tokens: input $4, cache write $5 (5 minutes) or $8 (1 hour), cache read $0.20, output $20.费用按 Claude Opus 5.5 的标准 API 价格计算(每百万 token:输入 $4,缓存写入 5 分钟 $5 / 1 小时 $8,缓存读取 $0.20,输出 $20)。
Cost is per 1M tokens billed with the mix seen in these sessions: 96.6% cache reads, 0.4% cache writes (1 hour), 2.8% cache writes (5 minutes), 0.0% plain input, 0.3% output.费用按每 100 万个计费 token 计算,构成与这些会话一致:缓存读取 96.6%、缓存写入(1 小时)0.4%、缓存写入(5 分钟)2.8%、普通输入 0.0%、输出 0.3%。
In short: we replayed real sessions at every trigger and added up what they would have cost and how long compaction would have taken.简单说:我们用真实使用记录在每个触发点上重放一遍,把费用和压缩耗时加起来。
555 independent work sessions (20 main conversations and 535 subagent sessions), 45,170 deduplicated requests and about 212 hours of agent time. 260 real compactions calibrate the model. Sessions that used other models, and sessions with no Claude Opus 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.555 个独立工作会话(20 个主对话和 535 个子代理会话),共 45,170 个去重请求,约 212 小时的代理时间。260 次真实压缩用来校准模型。用了其他模型的会话,以及没有 Claude Opus 5.5 请求的会话,都没有计入。工作时间按相邻请求的间隔估算,超过 5 分钟的间隔算空闲,并扣掉压缩耗时。主对话和并行的子代理时间是加在一起的。
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 (6,736 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: 96.6% cache reads, 0.4% cache writes (1 hour), 2.8% cache writes (5 minutes), 0.0% plain input and 0.3% output. Costs are comparable between models and between amounts of history.图上不是这些会话的总账单,因为总账单会随历史数据的多少而变。每个费用都是该触发点下重放得到的总费用,除以真实历史的计费 token 数(6,736 百万),再乘以一百万。除数是每个模型固定的一个数,不是每次重放的 token 数。所以这一百万 token 的构成与真实计费一致:缓存读取 96.6%、缓存写入(1 小时)0.4%、缓存写入(5 分钟)2.8%、普通输入 0.0%、输出 0.3%。这样不同模型、不同数据量之间的费用可以直接比较。
The cost of one request comes first. Then ordinary requests and compactions are added up over the whole workload.先算一次请求的费用,再把普通请求和压缩在整个工作负载上加起来。
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 Opus 5.5: 0.05.缓存输入价格除以未缓存输入价格;Claude Opus 5.5 为 0.05。ρOutput price divided by uncached input price; Claude Opus 5.5: 5.输出价格除以未缓存输入价格;Claude Opus 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.压缩次数、单次压缩耗时,以及不含压缩的工作时间。α makes keeping a long context cheap.缓存输入越便宜,触发点越高。α 越小,保留长上下文越划算。Δ makes low triggers compact over and over.增长越快,触发点越高。Δ 越大,低触发点就会一次又一次压缩。G makes each compaction cost more.摘要越长,触发点越高。G 越大,每次压缩越贵。v makes each compaction last longer, so fewer of them fit in your time budget.写得越慢,触发点越高。v 越小,每次压缩越久,在你的时间预算里就容不下那么多次。The time model is fitted to 260 compactions: R² = 0.73. Summary size alone gives 0.69, 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.时间模型用 260 次压缩拟合,R² = 0.73;只用摘要大小是 0.69,只用输入大小是 -0.01。闭式公式用来解释每个因素的影响方向,图上的曲线来自重放,保留了真实的请求顺序、上下文增长和压缩时点。