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

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

Description and use

Coding agents lose read‑only data during session compaction. Save non‑regenerable facts to disk and specify them in a /compact command to preserve them.

Problem

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

Outcome

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

Workflow

  • 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.

Evidence

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

Source

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

Source

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.

Source

  • Record date: 2026-11-01T21:43:51.947Z