How to Keep a Long Claude Agent Loop Under the Context Limit with On-Demand Compaction
Use the Claude API's on-demand compaction parameter (beta compact-2026-09-04) to summarize a tool-calling agent loop before it outgrows the 1M window: when to trigger it, where to cut so tool calls and thinking stay valid, how to write the summarization instructions, and the stop reasons, errors and billing fields that trip people up.