claude-code - 💡(How to fix) Fix Selective conversation history pruning to reduce token usage [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#54553Fetched 2026-04-30 06:42:30
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1

Root Cause

  • Token savings — long sessions accumulate substantial irrelevant context. Users know which parts are still load-bearing better than automatic compaction does.
  • Response quality — less noise in the context means better signal for the model. Stale debugging output or abandoned approaches can actively mislead.
  • User control — sits between the extremes of "keep everything" and "clear everything," giving power users fine-grained control without changing the default experience.
RAW_BUFFERClick to expand / collapse

Problem

Every prompt sent to the API includes the full conversation history. For long sessions, this means re-transmitting turns that are no longer relevant — dead-end debugging, exploratory file reads, superseded approaches — costing tokens and degrading signal-to-noise ratio.

The current options are:

  • /clear — wipes everything, losing all useful context
  • /compact — lossy summarization with limited user control over what's kept
  • Auto-compaction — happens automatically but the user has no say in what's preserved or discarded

None of these let the user surgically remove specific turns while keeping the rest intact.

Proposal

Allow users to selectively exclude individual turns or ranges of turns from the context sent to the API. Excluded turns could remain visible in the UI (greyed out) but would not be included in the next request payload.

Possible UX approaches

  1. Turn-level deletion — keyboard shortcut to toggle individual turns as excluded/included
  2. Range selection — e.g. /prune 5-23 to exclude a range of turns
  3. Semantic pruning — e.g. /prune "the database migration tangent" using the LLM to identify and exclude matching turns

These aren't mutually exclusive — (1) alone would cover the core use case.

Why this matters

  • Token savings — long sessions accumulate substantial irrelevant context. Users know which parts are still load-bearing better than automatic compaction does.
  • Response quality — less noise in the context means better signal for the model. Stale debugging output or abandoned approaches can actively mislead.
  • User control — sits between the extremes of "keep everything" and "clear everything," giving power users fine-grained control without changing the default experience.

Alternatives considered

  • /compact with a focus prompt partially addresses this but produces a lossy summary rather than preserving exact turns the user wants to keep
  • More aggressive auto-compaction could help but removes user agency over what's important

extent analysis

TL;DR

Implement a feature to selectively exclude individual turns or ranges of turns from the context sent to the API, allowing users to surgically remove irrelevant information.

Guidance

  • Introduce a new API parameter to accept a list of turn IDs or ranges to exclude from the context.
  • Develop a UI feature to allow users to toggle individual turns as excluded/included, potentially using a keyboard shortcut.
  • Consider implementing a range selection feature, such as /prune 5-23, to exclude a range of turns.
  • Evaluate the feasibility of semantic pruning using the LLM to identify and exclude matching turns based on user input.

Example

// Example API request with excluded turns
{
  "context": [
    {"turn": 1, "text": "Hello"},
    {"turn": 2, "text": "How are you?"},
    // ...
  ],
  "excluded_turns": [3, 4, "5-10"]
}

Notes

The implementation details of the exclusion feature will depend on the specific requirements and constraints of the API and UI. It may be necessary to balance the level of user control with the potential complexity of the feature.

Recommendation

Apply a workaround by introducing a new API parameter to accept a list of turn IDs or ranges to exclude from the context, allowing users to have fine-grained control over the context sent to the API. This approach provides a balance between user control and simplicity of implementation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING