← 返回研报
译文对照 · Claude Code

把每一次 Claude Code 会话用到位Maximizing the Value of Your Claude Code Sessions

原文 Lydia Hallie · Anthropic 官方博客 · 2026 年 8 月 14 日 · AI Insight 中英对照编译 · 原文链接

本文为 Anthropic 官方博客原文的中英对照全文翻译,左栏英文原文、右栏中文译文,供逐句核对与学习之用。译文力求忠实,术语(如 prompt cache、prefill/decode、effort、subagent)保留英文以免歧义;如有出入以官方原文为准:claude.com/blog/maximizing-the-value-of-your-claude-code-sessions[1]

TL;DR TL;DR


价值最大化 Maximizing value

English
中文
Until pretty recently, the tools you wrote code with were a flat fee or free, whereas with agentic tools like Claude Code, individual tasks carry their own costs. The same completed task can cost different amounts depending on usage patterns.
直到不久之前,你写代码所用的工具还都是一口价、或者干脆免费;而在 Claude Code 这类智能体工具里,每一个任务都自带成本。同样一件已完成的任务,会因为你的使用方式不同而花掉不同的钱。
One example shows Claude reading a test and its corresponding file, making an edit in a handful of turns. In another scenario, it greps the repository first, reads a dozen files before reaching the same two, and every one of those turns also drags along everything else that's been read into the conversation since this morning.
举个例子:一种情况下 Claude 读了一个测试和它对应的文件,几轮之内就完成了改动。另一种情况下,它先在整个仓库里 grep,读了十几个文件才摸到同样的那两个——而这中间每一轮,还会把从今早到现在读进对话的所有内容一并带上

一个 token 的价格由什么决定 What decides the price of a token

English
中文
Billing occurs per token based on inference — the computational time for running the model over tokens. Three factors determine this cost: the model size, whether tokens are input or output, and whether they were cached.
计费按 token 进行,依据是推理——也就是让模型在这些 token 上运行所耗的计算时间。决定这笔成本的有三个因素:模型大小、token 是输入还是输出、以及它们是否被缓存

模型 Model

Larger models perform more work on both input and output tokens. Use a larger model when the problem is genuinely hard or ambiguous, and a smaller one when the work is routine.
更大的模型在输入和输出 token 上都要做更多的工作。问题真的困难或含糊时用大模型,工作只是例行公事时用小模型。

输入与输出 token Input and output tokens

Requests occur in two phases. Prefill: the model reads the request and context (system prompt, CLAUDE.md, message, files read, and command outputs) — these are input tokens. Decode: the model writes output tokens (thinking, tool calls, visible text) one at a time. Output is priced at roughly 5x input.
一次请求分两个阶段。Prefill(预填充):模型读入请求与上下文(system prompt、CLAUDE.md、你的消息、读过的文件、命令输出)——这些是输入 tokenDecode(解码):模型逐个写出输出 token(思考、工具调用、可见文本)。输出的单价大约是输入的 5 倍。
A lot of the output tokens in a session are thinking tokens, and how much thinking the model does per turn is what the effort level controls.
一次会话里很大一部分输出 token 是思考 token,而模型每一轮思考多少,正是由 effort(思考强度)控制的。

Prompt 缓存 Prompt caching

If a request begins with identical tokens as a previous request, the server reuses the cached state, costing only 0.1x the input price for reads. Writing tokens to cache costs up to 2x normal input initially, but the write occurs once per token while 0.1x reads happen on every subsequent turn.
如果一次请求开头的 token 与上一次请求完全相同,服务器会复用已缓存的状态,读取只需输入价的 0.1 倍。把 token 写入缓存起初最高要 2 倍普通输入价,但写入对每个 token 只发生一次,而 0.1 倍的读取则在之后每一轮都发生。
Claude Code manages prompt caching automatically, but certain actions break it with cost spikes: /model — each model has its own cache, switching causes full re-prefill at full price. /effort — also keyed to the cache, switching mid-conversation re-prefills everything. Fast mode — part of the cache key, enable it at session start. /compact — replaces the conversation with a summary, breaking the cache. Time — the cache expires after one hour on subscription, or five minutes on API keys. Session resumption — usually triggers cache loss.
Claude Code 会自动管理 prompt 缓存,但某些动作会击穿缓存、带来成本尖峰:/model——每个模型有各自的缓存,切换会以全价重新 prefill 一遍。/effort——同样计入缓存 key,中途切换会把所有内容重新 prefill。Fast mode(快速模式)——它是缓存 key 的一部分,要用就在会话开始时开。/compact——用摘要替换对话,会打断缓存。时间——订阅制下缓存一小时过期,API key 则是五分钟。恢复会话——通常会导致缓存失效。

一次会话到底发出多少 token What decides how many tokens a session sends

English
中文
Nothing gets sent just once. Everything that ends up in the conversation — a file Claude read or the output of a command it ran — gets sent again on every turn after it, for the rest of the session. The session cost model centers on: how many tokens end up in context, how many turns they stay there, and how many contexts run simultaneously.
没有什么东西是只发一次的。任何进入对话的内容——Claude 读过的文件、它跑过的命令的输出——在此之后的每一轮都会被再发一遍,直到会话结束。会话成本模型的核心是三点:有多少 token 进了上下文、它们在里面停留了多少轮、以及同时有多少个上下文在跑。

什么会进上下文 What ends up in the context

Initial context includes tool definitions, system prompt, CLAUDE.md, and loaded elements. Run /context in a fresh session to see what's in there before you've typed anything. Nearly everything added during a session comes from tool results: files Claude reads and command outputs.
初始上下文包括工具定义、system prompt、CLAUDE.md 以及已加载的各类内容。在新会话里、还没输入任何东西之前先跑一次 /context,看看里面都有什么。会话过程中新增的内容,几乎全部来自工具结果:Claude 读的文件和命令的输出。
When referring to files, @-mention it instead of typing the path. Claude Code attaches the file to your message before anything gets sent, so it's in the very first request and there's no Read call for it. Command outputs add to context like read files, remaining for subsequent turns. Outputs exceeding 30,000 characters get written to files with only a preview in the conversation (BASH_MAX_OUTPUT_LENGTH controls this).
引用文件时,用 @ 提及、而不是打出路径。Claude Code 会在任何东西发出之前就把文件附到你的消息里,于是它出现在最开始的那次请求中,也就不需要一次 Read 调用。命令输出会像读过的文件一样加进上下文,并在后续各轮中一直保留。超过 30,000 字符的输出会被写入文件,对话里只留一段预览(由 BASH_MAX_OUTPUT_LENGTH 控制)。

它们停留多少轮 How many turns it stays there

One long session costs more than the same work spread over a few short ones, and by more than you'd think, because turn 40 is also re-reading the 39 turns before it. Use /clear when starting new tasks and /compact when earlier parts of the same task complete.
一次长会话,比把同样的工作拆成几次短会话要贵——而且贵得超乎你想象,因为第 40 轮同时也在重读前面 39 轮。开始新任务时用 /clear;同一任务里早先的部分已完成时用 /compact
Note: /loop fires as a full turn in the session you set it up in, carrying that whole conversation with it every time, and if it's been more than an hour since the last turn, it's a cache miss on top.
提示:/loop 会在你设置它的那个会话里以一整轮的形式触发,每次都把整段对话一起带上;而如果距上一轮已超过一小时,还要再叠加一次缓存未命中。

子代理 Subagents

Subagents run in separate contexts with their own system prompt and tools, but not your conversation. Only the answer returns to the main session. This prevents noisy job outputs from remaining in your context, though subagents may re-read information the main session already has. Subagent definitions can specify a model (like Haiku) for frequently-delegated noisy jobs.
子代理在独立的上下文里运行,有自己的 system prompt 和工具,但不带你的对话;只有最终答案会回到主会话。这样能避免吵闹的任务输出滞留在你的上下文里——代价是子代理可能会重读主会话已经有的信息。子代理定义里可以为那些频繁委派的吵闹任务指定模型(比如 Haiku)。

该先看哪里 Where to look first

English
中文
Four priorities for token awareness, roughly in order of how much they cost: (1) Session length — the number of turns context accumulates across. (2) Context size — files and command outputs in the conversation. (3) Model and effort level — set before starting. (4) Prompt cache breaks — mid-session model/effort/compact operations.
关注 token 的四个优先级,大致按花费从高到低排:(1) 会话长度——上下文累积经过了多少轮。(2) 上下文大小——对话里的文件与命令输出。(3) 模型与 effort——开工前就设好。(4) prompt 缓存被打断——会话中途的 model / effort / compact 操作。

AI Insight 一句话 Our take

AI Insight 观点

这篇官方指南的底层只有一句话:「没有什么是只发一次的」——凡进了对话的东西,之后每一轮都在为它重复付费。所以省 token 的真功夫不在抠某个字,而在管理上下文的“体量 × 停留轮数 × 并发数”:短会话勤 /clear、离开前 /compact、开工前定死 model/effort 别中途改、吵闹活儿丢子代理。把这几件变成肌肉记忆,账单自然下来。


参考文献 Source

[1] Anthropic 官方博客 — Lydia Hallie, “Maximizing the value of your Claude Code sessions”(2026-08-14)claude.com/blog/maximizing-the-value-of-your-claude-code-sessions

说明:本文为 Anthropic 官方博客的中英对照编译,仅供学习参考;译文力求忠实,如与官方原文有出入,一律以官方原文为准。定价倍数、缓存时长等细节可能随官方调整而变化。