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. Your browser does not support the video tag. 🔗 View on Twitter 🔗 View Quoted Tweet 💬 2 🔄 0 ❤️ 5 👀 1268 📊 3 ⚡