CDX-101 · Module 1

Context Window & Compaction

4 min read

Like all LLM-powered tools, Codex operates within a finite context window. How it manages that window — and how you help it — directly determines the quality of output in longer sessions. When context grows too large, the model starts losing details buried in the middle of the conversation. Codex addresses this with a compaction system.

The /compact command manually triggers context compaction. Codex summarizes the conversation so far, preserving key decisions and file states while discarding redundant back-and-forth. This is useful when you notice output quality degrading or when you are about to pivot to a different area of the codebase.

The GPT-5.x-Codex series models have native compaction built in — they handle context management internally as part of their inference process. With these models, manual compaction is rarely needed. Standard models like GPT-4.1 and o3 benefit more from explicit /compact usage.

Do This

  • Run /compact before pivoting to a new area of the codebase
  • Use /status to check how much context you have consumed
  • Break large tasks into focused sessions rather than one marathon
  • Use /clear when starting a completely unrelated task

Avoid This

  • Let a single session run for hundreds of exchanges without compacting
  • Assume the model will perfectly recall details from early in a long conversation
  • Paste entire files into the prompt when /mention or file references work better

Context management in Codex and Claude Code follows similar principles but with different mechanisms. Claude Code uses auto-compaction that triggers automatically near the context limit and reserves a buffer. Codex relies more on manual /compact usage (unless using Codex-series models). Both tools benefit from the same discipline: keep sessions focused, clear between unrelated tasks, and compact before pivoting.