Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

How to Tell What Claude Code and Codex Forget When They Compact a Session

说明与用途

编码代理在压缩会话时会丢失仅被读取的数据。通过将不可再生的事实保存到磁盘并在 /compact 命令中明确指定,可保持这些数据。

问题

Coding agents lose in‑memory facts when they compact a session, causing missing data and repeated work.

结果

By explicitly saving non‑regenerable facts and configuring compaction prompts, agents retain critical information, reducing repeated work and avoiding silent data loss.

工作流

  • 1. Identify facts that cannot be regenerated (e.g., test failures, logs).
  • 2. Before compaction, write those facts to a persistent notes file or include them in a /compact command with a keep list.
  • 3. Use a /compact prompt that instructs the agent to keep exact error strings, ids, file paths, and test names.
  • 4. Configure Codex’s compact_prompt in ~/.codex/config.toml to enforce the keep list.
  • 5. Move rules that must survive compaction into the root rules file or a dedicated Compact Instructions section in CLAUDE.md.
  • 6. Add a SessionStart hook that runs after compaction to restore state (e.g., git status and notes file).
  • 7. In custom agents, keep the file list as data and re‑inject it after summarization.
  • 8. Audit a real session to verify retention of critical facts.

证据

A compacted agent keeps your instructions and its own edits, but loses most of what it only read.

来源

In my test session, 78,642 tokens became 2,632. That is 97% gone in about twenty seconds, and the session looks healthy afterward.

来源

The summary kept what mattered to the work so far. In an earlier run, the last task counted timeouts over 5000. Of six values I probed, only the two timeouts over 5000 survived.

来源

  • 记录日期: 2026-11-01T21:43:51.947Z