我统计了本机最近 7 天的 Claude Code 使用记录:4,423 次 API 请求,合计 10.3 亿 token。按 Anthropic 公布的 API 标价折算,约 335 美元。其中 60% 花在「缓存读取」上,也就是每一轮对话都把之前的全部内容重新读一遍;28% 花在缓存写入上,模型真正输出的内容只占 12%。
平均每次请求,Claude Code 要带着 23.3 万 token 的上下文发出去,换回 469 个 token 的输出。
10 月 21 日起,X 上有用户说 Claude Code 的用量「掉得快了 5 倍」。Claude Code 负责人 Boris Cherny 10 月 22 日先回复「我们这边没有改动」,同一天晚些时候又说团队正在排查。截至本文发稿,官方没有公布原因。本文不猜测那次的原因,只回答一个更基础的问题:在正常情况下,Claude Code 的用量到底消耗在哪里。
先说结论。额度的大头不在问了多少个问题,而在每问一句时要连带重发多长的对话。在这个前提下,截断工具输出、给代码建索引这类常见的省 token 办法,收益都在个位数百分比;真正有效的是控制上下文长度,以及避免缓存过期后把整段对话重写一遍。
需要说明两点:本文所有金额都是按 API 标价折算的,订阅套餐的额度怎么计量,Anthropic 没有公开;本机数据只代表一个人的用法。
98% 的 token 是缓存读取,成本占六成
Claude Code 每发一次请求,都会把整段对话连同系统提示、工具定义、读过的文件一起发给模型。官方文档写得很直接:「Claude Code sends your full conversation with every request」,哪怕在开了一整天的会话里问一句话,消耗的也是整段对话。
这些重复发送的内容大部分会命中提示缓存(prompt caching)。本机 7 天的缓存命中率是 98.6%。命中缓存的部分按「缓存读取」计价,Opus 5.5 是每百万 token 0.20 美元,只有正常输入价 4 美元的 5%。
单价很低,但量太大。7 天里,缓存读取占全部 token 的 98.4%,折算成本占 59.9%。缓存写入只占 token 的 1.4%,成本却占 27.8%;输出占 token 的 0.2%,成本占 12.3%。
30 天的数据结构相同:缓存读取占 token 的 98.0%、成本的 53.1%,缓存写入占成本的 33.7%。
这个比例和社区的两份实测基本一致。Dan Mercede 统计了自己 7 天、471 个会话、61.5 亿 token,缓存读取占 token 的 96.9%、成本约 46%,缓存写入占 token 的 2.8%、成本约 38%。另一位开发者在 claudiu 项目的 issue 里统计了 8,631 次请求,缓存读取占成本 61.6%,缓存写入 21.2%。三份数据来自不同的人和项目,「读取量最大、写入单价最贵」的结构是一致的。
上下文超过 20 万的请求占了三分之二的成本
既然每次请求都要重读整段对话,成本就和上下文长度成正比。本机 7 天里,单次请求的上下文中位数是 22.7 万 token,90 分位是 39.4 万。
按上下文长度分组:上下文超过 20 万 token 的请求占全部请求的 55.5%,却占了 67.7% 的成本;10 万以下的请求占 19%,成本只占 11.5%。
这意味着同样问一个问题,在一个已经聊了几个小时的会话里问,比在新会话里问贵得多。Claude Code 会在上下文接近上限时自动压缩(auto-compaction),但 Opus 5.5 的上下文窗口是 100 万 token,在触发自动压缩之前,会话可以长时间停留在二三十万 token 的区间,每一轮都按这个长度计费。
缓存过期后的整段重写:一次等于读 40 次
缓存写入单价高,是因为它要把内容完整地处理一遍再存起来。Opus 5.5 的 1 小时缓存写入是每百万 token 8 美元,是缓存读取的 40 倍。Dan Mercede 的例子很直观:一个 50 万 token 的会话,下一轮重读一遍约 0.10 美元,缓存过期后重写一遍约 4 美元。
缓存什么时候过期,取决于 TTL。根据 Claude Code 文档,订阅额度内,主对话默认使用 1 小时缓存,子 agent 和压缩等其他请求默认 5 分钟。每次命中缓存都会刷新计时,所以只要持续在用,缓存就不会过期;问题出在停下来之后。
本机 7 天里,一次写入超过 10 万 token 的整段重写有 15 次,全部发生在空闲之后,占缓存写入成本的 18%。30 天里有 55 次,其中 42 次发生在空闲超过 1 小时之后,这类重写合计约 138 美元,占缓存写入成本的 36.6%。Dan Mercede 的数据里,223 次大额重写有 209 次(94%)是空闲导致缓存过期。
典型场景是:晚上留着一个几十万 token 的会话没关,第二天早上回来接着问,第一句话就要把整段对话按写入价重新处理一遍。官方文档对此也有说明:长时间离开后再 /compact,压缩请求本身就要把整段历史当作未缓存输入重新处理,「This is why /compact costs the most when you resume an old session」。
子 agent 只占 16% 的 token,却占 45% 的缓存写入
子 agent 的缓存默认只保留 5 分钟,即使在订阅额度内也是如此,文档原话是「they get five minutes even on a subscription until you choose a longer one」。
本机 7 天里,子 agent 请求占全部 token 的 15.9%,却占了缓存写入的 44.8%。每个子 agent 启动时都要写入一份自己的系统提示和上下文;任务结束后如果主 agent 隔几分钟再追问它,5 分钟的缓存已经过期,又要重写一遍。Dan Mercede 的数据更极端:子 agent 占 token 的 32%,占缓存写入的 64%。
合盖之后的额度消耗:用户报告,官方未确认
另一类消耗来自 macOS 的后台唤醒。在 anthropics/claude-code 的 #102597 中,一位用户合上笔记本 6.5 小时,期间系统大约每 15 分钟唤醒一次,Claude Code 共发出 81 个请求、只完成 29 个,其中 15 次整段重写了 40 万到 58 万 token 的上下文,合计约 710 万 token,整夜的输出只有约 7,000 token,周额度从 20% 涨到 56%。#103064 报告了类似现象:合盖 2.2 小时,周额度从约 9% 涨到 19%。
这几个 issue 目前都处于 open 状态,没有官方回复,成因只是用户从外部观察得出的推测。如果你习惯让 Claude Code 跑着任务就合盖,值得在离开前确认任务已经结束,或者用 pmset -g log 查一下夜里有没有唤醒记录。
常见的省 token 办法:收益都在个位数
前面的结构决定了,只压缩某一类内容很难省下多少。claudiu 项目的作者逐项做了测试:
- 把每条工具输出截断到 4,000 token,最多省 4.2%;截断到 2,000 token,最多省 9.2%。原因是只有 3.7% 的工具结果超过 4,000 token。
- 对重复读取的文件去重,最多省 2.1%。
- 调整工具定义的顺序以提高缓存命中,没有空间:缓存未命中只占总成本的 1.7%。
- 接入代码索引工具,三轮共 56 次 A/B 测试,模型只在部分任务里用了索引,成本从持平到最多高出 12%,结论是在找代码、改代码的任务上不省 token。
这个 issue 最后以「not planned」关闭,作者的总结是:能做的 token 优化不多,剩下的只有使用建议。
值得改的四个习惯
结合计价规则和上面的数据,有效的办法都落在「上下文长度」和「缓存过期」两件事上。以下是我们据此整理的做法,括号里注明依据:
- 换话题就 /clear,不要在长会话里接着问。 新会话从几万 token 起步,旧会话每一轮都按二三十万计费(官方文档:「/clear costs nothing」;本机数据:上下文超过 20 万的请求占 67.7% 成本)。
- 长时间离开前先收尾,回来后开新会话。 空闲超过 1 小时,主对话缓存过期,第一句话就会触发整段重写;回来后在旧会话里 /compact 同样要重新处理整段历史(官方文档;本机 30 天 42 次此类重写,约占缓存写入成本的三分之一)。Claude Code 2.1.290 起提供 idleCompaction 设置,可以在空闲时自动压缩。
- 会反复追问的子 agent,考虑延长它的缓存时间。 子 agent 默认 5 分钟缓存,可以通过 subagentPromptCacheTtl 调整(需 2.1.242 及以上);更直接的做法是让子 agent 一次把结果交代完整,减少事后追问。
- 用 /usage 看缓存情况。 2.1.251 起,/usage 会显示主对话的「Prompt cache (main)」一行,可以直接看到命中和写入的比例,但这一行不包含子 agent。
想看自己的数据,可以对 ~/.claude/projects 下的会话记录做同样的统计。统计时注意一点:一次流式响应会在记录里出现多行,必须按 requestId 去重,否则会重复计数。
结论
Claude Code 的用量里,真正「干活」的输出只占一成多。剩下的近九成,是为了让模型记住之前的对话:要么按低价反复重读,要么在缓存过期后按高价整段重写。
所以,额度掉得快,首先要看的不是问了多少次,而是会话拖得有多长、中间停了多久。控制上下文长度、别让大会话在空闲后重新启动,比任何压缩工具输出的技巧都有效。
本文由 AI图鉴自动抓取并翻译,版权归原作者所有;如需查看原文请点下方链接。
I counted the last seven days of Claude Code's usage record: 4,423 API requests, totalling 1030 million token. Based on the API bid published by Anthropic, approximately US$ 335. Of these, 60 per cent spent on "cache Read" — that is, each round of conversations rereads the whole of what was before; 28 per cent spent on cache writing, and only 12 per cent of what was actually exported from the model.
On average, Claude Code sends out 233,000 tokens of context for 469 tokens.
On October 21, X users said Claude Code's usage was "five times faster". Claude Code's head, Boris Cherny, replied "We haven't changed our side" on October 22, and later that day said the team was working on it. As of the date of the present document, there are no official reasons for this. This paper does not speculate about the reason for that, but answers a more fundamental question: Under normal circumstances, where does Claude Code consume it?
First, conclusions. The head of quota did not ask many questions, and each question was accompanied by a long dialogue. In this context, the most common token-based method of cutting off tool outputs, indexing codes and so forth, the benefits are in a single-digit percentage; what is really effective is to control the length of context and to avoid cache ' s expiry by rewriting the entire conversation.
Two points need to be made: all the amounts in this paper are converted at API prices, what is the measure of quota for the subscription package, and Anthropic is not publicly available; the current data represent the usage of only one person.
98% of the token is cache reading at 60% cost.
Claude Code sends the entire dialogue to the model together with the system tips, tool definitions, and read documents at each request. The official document is written directly: "Claude Code sends your full review with every request" and even if you ask a word in a full-day session, it consumes the whole conversation.
Most of these duplicates will hit cache. The cache hit rate for 7 days is 98.6%. The portion of the hit cache is denominated in "cache Read" and Opus 5.5 is $0.20 per million token, with a normal input price of $0.5 per cent.
The unit price is low, but it's too much. 7 Days, cache is 98.4% of all tokens and the converted cost is 59.9%. cache writes only 1.4 per cent of token, while the cost is 27.8 per cent; output accounts for 0.2 per cent of token and cost 12.3 per cent.
The data structure is the same for 30 days: cache reads 98.0 per cent of token, 53.1 per cent of cost, and cache writes 33.7 per cent of cost.
This ratio and the two community measurements are basically the same. Dan Mercede counted 7 days, 471 sessions, 6.15 billion token, cache reading 96.9 per cent of token, about 46 per cent of cost, cache writing 2.8 per cent of token and about 38 per cent of cost. Another developer counted 8,631 requests, cache read 61.6 per cent of the cost, and cache wrote 21.2 per cent. The three data came from different people and projects, and the structure "the most read, the most expensive to write" was consistent.
context over 200,000 claims cost two thirds.
Since each request is rereading the entire dialogue, the cost is proportional to the length of context. For 7 days, the median number of context requests is 227,000 token, 90 is 39.40 million.
Grouped by context length: context requests over 200,000 tokens accounted for 55.5 per cent of all requests, but for 67.7 per cent of the costs; requests under 100,000 accounted for 19 per cent and costs only 11.5 per cent.
This means asking the same question, in a session that has been in conversation for hours, is much more expensive than in a new one. Claude Code will approach limited-time on context, but the context window of Opus 5.5 is 1 million token, and until the automatic compression is triggered, the session can stay in the 2.3 million token zone for a long time, and each round is charged on this length.
Rewrite the entire paragraph after the expiry of cache: once equals 40 readings
cache was written at high unit prices because it had to deal with the whole content over and over again. One hour of cache writing for Opus 5.5 is $8 per million token, 40 times as much as cache reads. The example of Dan Mercede is intuitive: a half-million token session, rereading about $0.10 in the next round, and rewriting about $4 after cache expired.
When cache expires depends on TTL. According to Claude Code document, subscription to quota, the main dialogue defaults on one hour cache, sub anent and compression other requests defaults 5 minutes. Every time cache hits, the clock is refreshed, so as long as it continues, cache does not expire; the problem arises after the stop.
For 7 days, the entire section of the machine, which is written over 100,000 tokens at a time, has been rewritten 15 times, all after free time, representing 18 per cent of the cost of writing cache. Of the 55 times in 30 days, 42 occurred after more than one hour of free time, such rewrites totalling approximately $138, or 36.6 per cent of the cost of writing cache. Of the data from Dan Mercede, 223 large rewrites (94%) resulted in the expiry of cache due to idleness.
The typical scenario was that the hundreds of thousands of tokens were left open at night, and then came back the next morning to ask, and the first sentence was to reprocess the entire conversation at writing prices. This is why /compact hosts the most when you leave an old session.
Subent only 16% of token, 45% of cache writing
cache of the sub anent defaults to keep only five minutes, even if it is a subscription to quota, and the document originally reads "they get five minutes even on a subscription until you choose a longer one".
For 7 days, the request of son represents 15.9 per cent of the total token, but 44.8 per cent of the cache. Each sub angent starts by writing its own system tip and context; if the main angent asks it a few minutes later after the mission, the five-minute cache has expired and rewritten again. Dan Mercede's data are even more extreme: subent accounted for 32 per cent of token and 64 per cent of cache writing.
Consumption of quota after consolidation: user report, not officially confirmed
Another type of consumption comes from the backstage of MacOS. In anthropics/claude-code #102597, one user joined the notebook for 6.5 hours, with the system waking up about every 15 minutes, while Claude Code sent 81 requests and completed only 29, of which 15 times context was rewritten from 400,000 to 580,000 token, for a total of about 7.1 million token, with only about 7,000 token and quota per week rising from 20 per cent to 56 per cent. #103064 reports similar phenomena: 2.2 hours of quota week increased from about 9% to 19%.
These issues are now open, there is no official response, and the cause is only speculation from outside observations. If you're used to keeping Claude Code on the run, it's worth confirming that the mission is over before you leave, or using pmset-g log to check if there's a wake-up call at night.
Common token approach: returns are in single digits
The structure in the front determines how much it is difficult to save by compressing only one category of content. The author of the claudiu project tested each item:
Interrupt each tool output to 4,000 token, with a maximum of 4.2 per cent; and 2,000 token, with a maximum of 9.2 per cent. The reason is that only 3.7% of the tool results exceed 4,000 token.
- Weighting of duplicated documents, with a maximum saving of 2.1 per cent.
- Reordering tool definitions to raise cache hit, no space: cache was only 1.7% of total cost.
- Access code indexing tool, with a total of 56 A/B tests in three rounds, the model uses indexing only for part of the task, at a cost of up to 12 per cent, concluding that the task of searching for code or changing the code will not be saved.
This issue is closed with "not planned" and the author concludes that there is little token to optimize, but only use advice.
Four habits worth changing.
In combination with the pricing rules and the above data, the effective approach falls on two things: "context Length" and "cache Expire". The following is a summary of our practice in this regard, which is indicated in parentheses:
- Change the subject. Don't continue in the long session. The new session starts with tens of thousands of tokens, and the old session is charged 2.3 million per round (official document: "/clear costs nothing"; machine data: context over 200,000 requests cost 67.7%).
- Finish it before leaving for a long time and start a new session when you return. The first sentence triggers a rewriting of the entire paragraph when there is more than one hour of free time available and the main dialogue with cache expires; when back, the whole history is also reprocessed (official document; 30 days; 42 times such rewrite, approximately one third of the cost of cache writing). Claude Code 2.1.290 provides an idlecomparation setting that can be automatically compressed when you are free.
- I'll ask the kid over and over again, consider extending its cache time. The sub angent defaults for 5 minutes cache, which can be adjusted by subagentPromptCacheTtl (requires 2.1.242 and above); more directly, lets the sub angent complete the results at a time and reduce subsequent follow-up.
- Take a look at cache. 2.1.151, /usage shows the line "Prompt Cache (main)" of the main dialogue, where the hit and written ratio can be seen directly, but this line does not contain a sub-agent.
If you want to see your data, you can do the same statistics for the session records under ~/.claude/projects. Note that there are multiple lines in the record for a one-time stream response, which has to be heavy by reference to requestId or double counting.
Conclusions
The real "work" output is only 10 percent of Claude Code's usage. The remaining almost 90 per cent is to allow the model to remember the previous dialogue: either read it again and again at a low price or rewrite it at a high price as a whole after the expiry of cache.
So quota fell fast, not by asking how many times, but by how long and how long the conversation took. Controlling the length of context and not allowing General Assembly messages to be restarted after free time is more effective than any technique to compress the output of tools.
Auto-fetched and translated by AI Atlas. All rights belong to the original author.