Feature Request: Add Context Pruning as Alternative to Compacting
Status Open
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
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
- Faster context management: No need to wait for Claude to process and summarize
- More predictable: Users know exactly what context is retained
- Cost-effective: No API tokens spent on summarization
- User control: Direct control over what stays in context
- 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
11 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
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
/clearcommandFor when you're starting a totally new phase of work, the
/clearcommand 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
/compactcommandThe docs on the
/costpage mention that you can give/compactspecific 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:
I haven't tested how well it follows precise instructions like that, but the documentation suggests it's possible. The
costsdoc even mentions you can add custom compaction instructions to yourCLAUDE.mdfile for more permanent guidance.3. Manual Copy/Paste +
/clearA 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
/prunecommand is still way better and would be a fantastic quality-of-life improvement. Hoping the dev team sees this and considers itmy request is a bit more elaborate #7359 but this would still be better than nothing.
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.
👍 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 5would 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.
FYI: @laurigates created a plugin-based proof-of-concept: https://github.com/laurigates/claude-code/pull/1
It implements
/pruneand/checkpointcommands, 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.
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
try the tool that we created and now made os https://github.com/Ruya-AI/cozempic/ it auto prunes and protects
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)andsummarize-tail, withtail-percentage=20%(which compacts more often than 50% but feels more natural).Use cozempic for now
Regards,
Junaid Ali Qureshi
On Mon, 9 Mar 2026 at 1:35 PM Maurice Faber @.***>
wrote:
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