技巧精选

Claude Code 建议用 /autocompact 400k 控制自动压缩阈值

精选理由

用 Claude Code 的人看下这条:/autocompact 400k 能让消息不用背着一整个长对话跑,省钱省 token,还有个旧环境变量记得删。

Claude Code 的自动压缩(auto-compact)触发时会把整段对话替换成摘要,而不是保留完整上下文。

正文

Lydia Hallie 解释,1M 模型默认要到约 967K token 才压缩,导致之前每条消息都携带整个对话历史,用量随之累加。作者建议用 /autocompact 400k 把压缩阈值降到 400K 左右(自己设的是 300k)。

另外此前建议的环境变量 CLAUDE_CODE_DISABLE_1M_CONTEXT 现在应从 settings.json 中删除,否则上下文最多只能到 200k。

原文 · 宝玉

建议你的 Claude Code 约束一下自动压缩的上下文长度,400k 左右是个比较合理的长度,我自己是设置的 300k,这个值足够了。 /autocompact 400k 另外我以前建议过禁用 1M, "CLAUDE_CODE_DISABLE_1M_CONTEXT"(~/.claude/settings.json),现在没必要了,请删除,否则最多也只能到 200k。 Lydia Hallie ✨ @lydiahallie Just to avoid some confusion: auto-compact does summarize. When it runs, your whole conversation is replaced by a short summary. It doesn't keep the last 1M tokens around. The ~967K is only when it runs on 1M models. Compacting itself is just one request that reads about as many tokens as the message you sent right before it, and it's mostly cache reads if your cache is still warm. What @rohit3a found is that waiting until 967K means every message before that point uses a lot of tokens, because each one includes your whole conversation so far. Most of it is read from the cache, which is much cheaper (so this is usually fine as long as your cache is warm), but it still counts toward your usage and adds up as your conversation grows. /autocompact 400k makes it summarize at 400K instead, so your messages never get that big.

产业坐标与信源核验

本条情报归属 AITOP「技巧」核心栏目,重点聚焦北美前沿实验室与硅谷科技巨头。在跨区域产业观察坐标中,该动态直接关联「AI 开发者工具链、Coding Agent 与工程化实践」研究主线,反映出当前技术演进与商业落地的最新风向。涉及核心实体与技术议题包括:Claude Code、autocompact、提示词工程、上下文窗口,读者可通过下方标签进入对应专题页查阅历史脉络与关联对比。

信源核验说明:本文原始线索采编自「宝玉」(@dotey),经 AITOP 多维评分管线结构化提炼。

Claude Code 建议用 /autocompact 400k 控制自动压缩阈值|AI热报