Feature Request: Add Context Pruning as Alternative to Compacting

Status Open
Maintainer reply None cached
Activity 11 comments · opened Aug 23, 2025

Problem Statement

Currently, Claude Code appears to only offer context compaction/summarization when managing conversation history. This requires Claude to process and summarize the entire context, which can be unnecessary and inefficient in many scenarios where users simply want to retain recent messages.

Proposed Solution

Implement a context pruning feature that allows users to keep only the most recent X messages without requiring Claude to process or summarize the pruned content. This would be a lightweight alternative to the existing compaction feature.

Use Cases

  • After creating a plan or task list: When I've just finished outlining a plan or creating a task list, I often only need to keep that recent output plus a few preceding messages for context
  • Starting a new phase of work: When transitioning to a different aspect of a project, older context becomes irrelevant
  • Performance optimization: Avoid unnecessary API calls for summarization when simple truncation would suffice
  • Cost reduction: Eliminate token usage for summarization when not needed

Suggested Implementation

Option 1: Command-based pruning

/prune --keep-last 5

This would keep only the last 5 message pairs (user + assistant)

Option 2: Interactive pruning

/prune --from-message <message-id>

Keep everything from a specific message onward

Option 3: Smart pruning with markers

Allow users to set "checkpoint" markers in the conversation:

/checkpoint "Task list created"
/prune --from-checkpoint

Benefits

  1. Faster context management: No need to wait for Claude to process and summarize
  2. More predictable: Users know exactly what context is retained
  3. Cost-effective: No API tokens spent on summarization
  4. User control: Direct control over what stays in context
  5. Preserves exact content: No risk of losing important details through summarization

Additional Considerations

  • Could coexist with the current compaction feature - users choose based on their needs

View original on GitHub ↗

11 Comments

github-actions[bot] · 1 year ago

Found 2 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/3852
  2. https://github.com/anthropics/claude-code/issues/4023

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

coygeek · 1 year ago

Hey, this is a great suggestion. I've also found myself wanting a more lightweight way to manage context without a full summarization, especially for the exact use cases you mentioned. It would definitely be faster and more cost-effective.

While we wait for an official feature like /prune, I was digging through the documentation provided and found a couple of things that might work as partial workarounds.

1. The /clear command

For when you're starting a totally new phase of work, the /clear command is the most straightforward option. It just wipes the current conversation history and gives you a fresh start.

It's a bit of a blunt instrument since you can't keep the last few messages, but it's quick and stops any irrelevant context from being used.

2. Guiding the /compact command

The docs on the /cost page mention that you can give /compact specific instructions. This is still summarization, but you might be able to guide it to do something close to pruning.

For example, after creating a plan, you could try:

> /compact Keep only the final plan and the last user prompt. Discard everything else.

I haven't tested how well it follows precise instructions like that, but the documentation suggests it's possible. The costs doc even mentions you can add custom compaction instructions to your CLAUDE.md file for more permanent guidance.

3. Manual Copy/Paste + /clear

A more manual but effective method I've used is to just copy the last few important messages from the conversation, run /clear, and then paste the copied text back into the new, clean session as the first prompt. It's not elegant, but it gives you perfect control over the exact content you want to keep.

---

All that said, your idea for a dedicated /prune command is still way better and would be a fantastic quality-of-life improvement. Hoping the dev team sees this and considers it

peixotorms · 11 months ago

my request is a bit more elaborate #7359 but this would still be better than nothing.

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

douglance · 8 months ago

👍 Strong +1 for this feature.

Additional use case: After a long debugging session, I've finally isolated the bug in the last 2-3 exchanges. I want to clear old noise but keep the recent debugging context to continue working with a clean slate.

/prune --keep-last 5 would be perfect for this - discard tangential tool calls and exploration, keep only what's immediately relevant.

This came up in #15277 (now closed as dup) and is also related to #7919's request for preserving recent messages during compaction.

douglance · 8 months ago

FYI: @laurigates created a plugin-based proof-of-concept: https://github.com/laurigates/claude-code/pull/1

It implements /prune and /checkpoint commands, but as noted in the PR, it's "soft pruning" - it instructs Claude to focus on recent context rather than actually removing messages (plugin limitation). True pruning would need core CLI support.

This demonstrates demand and provides a reference implementation for the UX.

ediril · 7 months ago

There is a more general and useful form of this request, which is the ability to see and manage the contents of the context window at any point. This request mentions a specific way to do it which is great, and it is a subset of the request I submitted: https://github.com/anthropics/claude-code/issues/20652

junaidtitan · 6 months ago

try the tool that we created and now made os https://github.com/Ruya-AI/cozempic/ it auto prunes and protects

Morriz · 5 months ago

I'd favor a tail compaction like codex cli does, which is SUPER good at keeping track of context imo. It simply covers most use cases OOTB but being able to configure in the settings which strategy, like summarize-all (default) and summarize-tail, with tail-percentage=20% (which compacts more often than 50% but feels more natural).

junaidtitan · 5 months ago

Use cozempic for now

Regards,
Junaid Ali Qureshi

On Mon, 9 Mar 2026 at 1:35 PM Maurice Faber @.***>
wrote:

Morriz left a comment (anthropics/claude-code#6390) <https://github.com/anthropics/claude-code/issues/6390#issuecomment-4022410713> I'd favor a tail compaction like codex cli does, which is SUPER good at keeping track of context imo. It simply covers most use cases OOTB but being able to configure in the settings which strategy, like summarize-all (default) and summarize-tail, with tail-percentage=20% (which compacts more often than 50% but feels more natural). — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/6390#issuecomment-4022410713>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AFVALNKP2DYXUB5S4HNGPTD4P2F7PAVCNFSM6AAAAACETWUSAKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DAMRSGQYTANZRGM> . You are receiving this because you commented.Message ID: @.***>
shayaShav · 2 months ago

I built an open source MCP server that implements this pruning idea: flatten-mcp. Rather than keep-last-N messages, it prunes the bulkiest part of the context, which is tool output (large file reads, command logs, screenshots), into a sidecar file with a small retrievable reference left in place. No summarization pass, every prompt stays verbatim, and it is fully reversible. MIT licensed: https://github.com/shayaShav/flatten-mcp