If you have ever had a long coding session in a coding agent like Pi , Claude Code, or Codex, you will have triggered a compaction. In this post we explain how compaction works and when Pi needs to compact. An LLM conversation Large language models (LLMs) have limited context windows . The context window is what the model can "see" while producing a response. The transformer architecture used by LLMs limits how much input they can process. The input for a coding agent session includes all the previous messages and tool calls, and this keeps growing as you work. Once it exceeds the context window, the LLM rejects the request. When working interactively with a coding agent like Pi, the agent sends requests to an LLM and receives responses. Each request includes a system prompt, loaded files such as AGENTS.md , tool definitions, and the conversation history. A coding agent's first LLM request contains this initial context, along with a first user message. request 1: [system][tools][user] This starts a turn.…