上下文管理是AI辅助编码中的真正瓶颈。
在每天使用Cursor和Claude Code的过程中,我注意到当一个AI编码助手偏离或忘记约束时,我们往往认为这是模型的局限性。<p>但在很多情况下,这其实是上下文管理的问题。<p>以下是一些观察结果:
- 令牌不仅仅是限制,它们也是注意力的竞争。
- 即使在达到硬性窗口限制之前,注意力稀释就已经发生。
- 编码任务的衰退速度比聊天更快,因为它们依赖的密度和多重表示的处理(差异、日志、测试)。<p>因此,我开始有意识地管理上下文:
- 始终写下合同
- 按意图将会话分块
- 快照状态并重启
- 优先使用按需命令行接口,而不是预加载大型MCP响应<p>这大大提高了助手的稳定性。<p>我很好奇其他人是如何处理上下文优化的。
查看原文
After using Cursor and Claude Code daily, I’ve noticed that when an AI coding agent drifts or forgets constraints, we assume it’s a model limitation.<p>In many cases, it’s context management.<p>A few observations:
- Tokens are not just limits. They’re attention competition.
- Even before hitting the hard window limit, attention dilution happens.
- Coding tasks degrade faster than chat because of dependency density and multi-representation juggling (diffs, logs, tests).<p>I started managing context deliberately:
- Always write a contract
- Chunk sessions by intent
- Snapshot state and restart
- Prefer on-demand CLI instead of preloading large MCP responses<p>It dramatically improved the stability of the agent.<p>Curious how others are handling context optimization.