Claude Code 压缩机制与按需检索对比分析

原标题:如果我理解的没错的话,当前 Claude Code 在压缩后继续任务,会按需从历史会话中查找有用的信息加载到上下文。
45AI 研判分

宝玉指出 Claude Code 的上下文压缩机制在效果上类似于新开会话并从历史中按需加载信息,两者主要差异仅在于摘要带来的少量 Token 开销。该观点反驳了 Alexander Yue 关于“压缩是错误”的论断,后者主张保留完整记录并让智能体自主检索关键行,以规避摘要的信息丢失问题。

报道正文

宝玉 (@dotey) · 2026-10-30 04

如果我理解的没错的话,当前 Claude Code 在压缩后继续任务,会按需从历史会话中查找有用的信息加载到上下文。

这和作者所说的新开一个会话再去从原来的会话加载有用信息不是一回事吗?唯一的差别就是多了一点摘要信息,但这多不了多少 Token。

而且就算你新开一个会话,任务继续同样会很快填满上下文。

↳ 引用 @Alezander9 (Alexander Yue): Compaction is a mistake.

When an agent's context fills up, tools like Codex and Claude Code compact it:

  1. The model prefills the entire session again
  2. It writes a summary of everything so far
  3. A new session starts from that summary

I measured this on a real ~400k-token session with Opus 5.5: → 38 s and $1.99 when the prompt cache has expired → 29 s and $0.17 when it hasn't

And the summary is lossy. The exact error message, the file path, the one number you needed is often gone.

So I do something new for Mainplane

Context retrieval works the other way around. Mainplane keeps the full record of every session as a file. When the context fills up, a new session starts right away with one instruction: "You are continuing session X. Retrieve key context from it as you go."

The agent searches the old session and copies the exact lines it needs, when it needs them.

Same session, same model: 15 s and $0.10 to get back to work. It does not depend on a cache hit, and nothing is paraphrased.

This is the bitter lesson applied to agent memory. Don't hand-design what the model should remember. Give it the full record and good tools, and let it decide.

Mainplane is open source (MIT). Link in the first comment.