使用 Claude Code:session management 和 1M context
How
如何
you
你
manage
管理
sessions,
会话,
context,
上下文,
and
和
compaction
compaction
in
在
Claude
Claude
Code
代码
shapes
形状
your
你的
results
结果
more
更多
than
比
you
你
might
might
expect.
expect.
Here's
这里是
a
一个
practical
实用
guide
指南
to
来
making
制作
the
该
right
对
call
调用
at
在
every
每个
turn.
回合。
We released /usage, a new slash command to help you understand your usage with Claude Code. This feature was informed by a number of conversations with customers.
我们发布了 /usage,一个新的斜杠命令,帮助您了解与 Claude Code 的使用情况。此功能受到了与客户多次对话的启发。
What came up again and again in these calls is that there is a lot of variance in how users manage their sessions, especially with our new update to 1 million context in Claude Code.
在这些通话中反复出现的是,用户管理会话的方式差异很大,尤其是随着我们在 Claude Code 中更新到 1 million context。
Do you only use one session or two sessions that you keep open in a terminal? Do you start a new session with every prompt? When do you use compact, rewind or subagents? What causes a bad compact or bad session?
你只使用一个会话,还是在终端中保持两个会话打开?你每次提示都启动一个新会话吗?你何时使用 compact、rewind 或 subagents?什么会导致糟糕的 compact 或糟糕的会话?
There’s a surprising amount of detail here that can really shape your experience with Claude Code and almost all of it comes from managing your context window.
这里有令人惊讶的细节量,这些细节真的会塑造您与 Claude Code 的体验,几乎所有这些都来自于 managing your context window。
A quick primer on context, compaction and context rot
关于 context、compaction 和 context rot 的快速入门

The context window is everything the model can "see" at once when generating its next response. It includes your system prompt, the conversation so far, every tool call and its output, and every file that's been read. Claude Code has a context window of one million tokens.
上下文窗口是模型在生成下一个响应时一次能“看到”的所有内容。它包括你的 system prompt、迄今为止的对话、每个 tool call 及其输出,以及每个已读取的文件。Claude Code 的上下文窗口为 100 万 tokens。
Unfortunately, using context has a slight impact on performance, which is often called context rot. Context rot is the observation that model performance degrades as context grows because attention gets spread across more tokens, and older, irrelevant content starts to di...