A coding agent has found why a CSV export breaks when an address spans two lines. It has a patch and a regression test. Forty minutes earlier, the developer also specified that the export must keep its existing column order because another application imports the file by position. If the agent loses that detail during a long session, it can fix the bug and still break the importer.
Context compaction gives an agent more room to work by carrying a shorter representation of earlier conversation into later turns. For a development team, the practical question is whether the agent can still finish the job under the original constraints once that shorter context takes over.
What gets compacted during a coding session?
A model’s context window is the space it has for material it can use on a turn. An agent fills that space with instructions, messages, files it has read and results from tools such as test runners. A single failing test may produce hundreds of lines of output, even though the next step only needs one error message and the name of the test.
Compaction reduces the amount of earlier material carried forward. The patch in the working tree and the test results on disk are separate from the API conversation. If a detail needs to be checked again, the agent can reopen the relevant file or rerun the test, provided it still has access and knows where to look. A reference to the test is more valuable at that point than a summary that merely says “tests were run”.
How OpenAI and Claude handle compaction
Both APIs let developers choose when to compact or configure a token threshold. The on-demand options are especially useful when the application already knows that a stage of work has finished, such as after the final tool result from an investigation comes back.
| API | When it compacts | What the application receives |
|---|---|---|
| OpenAI Responses API | At a configured threshold, or on a separate request to /responses/compact |
An opaque encrypted compaction item. The standalone endpoint returns a compacted window that can also include retained items. |
| Claude Messages API | At a configured threshold, or on a separate on-demand request on supported models | On demand, a readable summary in a signed block that the application sends back unchanged. |
With OpenAI’s standalone endpoint, pass the returned window to the next request as supplied. With Claude’s on-demand beta, put the signed block at the start of the continued message history in place of the turns it summarizes. The readable text makes it possible to see which details Claude carried into the summary. Anthropic also documents that images and documents in the summarized turns need to be supplied again if the agent still needs them. OpenAI compaction guide · Claude on-demand documentation
Teams already using Claude message threads can think of those as a way to send less repeated history over the network. Compaction changes how much of that history the model works with on later turns.
Give the agent a short record it can reopen
For the CSV fix, a handoff could include four entries.
- Goal — Keep multiline addresses in a single CSV field.
- Required behaviour — Preserve the existing header and column order. Keep the export compatible with PHP 8.3.
- Evidence — The multiline-address fixture passed after the patch. Compatibility with the importer still needs checking.
- Next action — Run the existing header-order assertion and the export tests under PHP 8.3.
Keep that record somewhere the agent can reopen, such as the issue or a short file in its workspace. Give the agent its location when it resumes. If an instruction changes mid-session, update the record with the latest decision. If a test fails, record the failure and the test name so a later turn can reproduce it.
Test the first turn after compaction
Take a completed issue with clear acceptance criteria. Start two runs from the same commit, with the same model and tools. Continue one with the original history and compact the other at the same completed step. Check whether the agent recalls the column-order requirement, finds the relevant test and finishes with an export the importer can still read. Repeat across several issues before drawing a conclusion.
Record elapsed time and total API usage alongside the test results. Claude bills on-demand summarization as its own request, so include that call when comparing costs. A smaller context is worth keeping when the agent can resume the work, recover the evidence it needs and satisfy the same acceptance criteria. Claude usage reporting
