Claude Code 新增空闲压缩机制:缓存过期前自动执行 /compact 以降低 Token 成本

原标题:Claude Code 添加了空闲压缩功能,也就是缓存即将失效的时候主动帮你运行一下 /compact,这样过了一小时再用就不用担心第一次请求会因为缓存失效 token 费用飙升,很实用的功能👍
42AI 研判分

Anthropic 为 Claude Code 引入“空闲压缩”功能,在提示词缓存即将失效(约1小时)时自动触发 /compact 命令。该机制将长会话摘要化,使用户回归时仅需处理摘要而非全量上下文,从而显著降低因缓存未命中导致的 Token 费用飙升。用户可通过配置文件手动禁用此功能。

报道正文

Claude Code 添加了空闲压缩功能,也就是缓存即将失效的时候主动帮你运行一下 /compact,这样过了一小时再用就不用担心第一次请求会因为缓存失效 token 费用飙升,很实用的功能👍

如果想关闭,需要在 ~/.claude/settings.json 中设置 "idleCompaction": false

↳ 引用 @lydiahallie (Lydia Hallie ✨): We recently added idle compaction to Claude Code!

It now compacts long idle sessions right before the prompt cache expires (~1h). If you come back to it later, it only has to reprocess the summary instead of the entire conversation, which saves you some usage.