Claude Code Context Compression
This optimization addresses token usage efficiency in Claude Code by preventing conversations from growing too large before compression. Developers using Claude Code for long coding sessions should implement this setting to manage their token consumption effectively, especially as costs can accumulate with larger context windows. The 400k threshold balances between maintaining conversation history and controlling usage costs.
The tweet recommends setting Claude Code's auto-compact context length to 400k tokens.
The author uses 300k tokens personally, finding it sufficient.A previous suggestion to disable 1M context via CLAUDE_CODE_DISABLE_1M_ENV is now unnecessary as it limits context to 200k.
Auto-compact summarizes the conversation when it reaches the threshold, replacing the entire history with a short summary.
建议你的 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.
This report is categorized under AITOP's "How-to" desk, focusing on US frontier AI labs and Silicon Valley technology leaders. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows. Key entities and technical topics under continuous tracking include Claude Code, autocompact, prompt engineering, context window.
Source attribution: curated from 宝玉 (@dotey).