Compress truncated responses instead of keeping them verbatim in conversation history

Resolved 💬 3 comments Opened Feb 26, 2026 by paoloc0 Closed Mar 1, 2026

Problem

When a response exceeds CLAUDE_CODE_MAX_OUTPUT_TOKENS (default 32k), the truncated response is added verbatim to the conversation history. This creates a bad feedback loop:

  1. Claude attempts a large response, hits the token limit, response is truncated and unusable
  2. The truncated content (broken JSON, half-finished file) is kept in full in the conversation history
  3. Context window shrinks significantly, leaving less room for a successful retry
  4. If Claude retries the same approach, the cycle repeats — each failed attempt consuming more context until the conversation is effectively dead

Current behavior

The failed turn is preserved in full. The rationale is that the model needs to "see" what it attempted so it can course-correct. But the truncated content itself has zero value — it is incomplete and will never be used.

Proposed improvement

Replace the truncated response with a compressed summary, something like:

"Attempted to [tool call description / response type], but output was truncated at 32k tokens. The response was incomplete and discarded."

This preserves the signal (what was attempted and why it failed) while discarding the bulk (the useless truncated content). The model gets enough context to adjust its approach without burning thousands of tokens on broken output.

Benefits

  • Reclaims context space for a successful retry
  • Model still knows what it tried and can course-correct
  • Reduces the chance of a death spiral where repeated failures consume all available context
  • Could be combined with a hint like "Produce a shorter response" to actively guide recovery

Current workaround

Users must manually Ctrl+C, and often start a new conversation because the context is too polluted to recover.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗