PRODUCTION SCENARIO
Your customer-chat backend runs on the server-side compaction beta and intends to keep using it. The bulk of each prompt is chat turns rather than tool results. The first compaction returned a compaction block, so the trigger is firing. The app stores the returned summary in its own database, keeps sending the full original message history, and drops the compaction block from messages. Requests keep hitting the context limit.
What must the backend change?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Append the whole response, compaction block included, to the messages array
The compaction block is the marker that tells the API to ignore every content block before it, so it has to travel back with later requests, most simply by appending the whole response content to messages. Sending a stored summary as the only message is right when you run your own summarization instead of the API's; here the API's block is thrown away while the original history is resent, so nothing marks that history as replaceable. Lowering the trigger is right when compaction fires too late to help, and this one has already fired. Context editing is right when tool results are the bulk, and the bulk here is chat turns.
Official Source: https://platform.claude.com/docs/en/build-with-claude/compaction ↗