claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] Ability to selectively remove context

Open jscalo opened this issue 3 months ago โ€ข 6 comments

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

For me and apparently a lot of others, the single biggest issue when working with CC is the limited context window and degradation of quality after compaction. But in my experience it's often the case that when approaching 100% of the cw capacity, there are several "rabbit holes" that we've gone down together that didn't pan out, but never the less occupy substantial space in the cw. It would be amazing to excise those prompts + responses from the context.

Proposed Solution

/edit_context

This would bring up a "table" of user prompts + the resulting ratio of the cw. E.g.

> /edit_context

Select prompt to remove:

> 1. Build a function that sorts an array of objects b     5.5%
  2. Fix memory leak in React component with async ef      3.2%
  3. Write SQL query to join users and orders by user      5.1%
  4. Optimize Python script for faster JSON parsing a      8.0%
  5. Explain difference between deep copy and shallow      2.7%

Enter to remove prompt and response from context ยท Esc to exit

Alternative Solutions

No response

Priority

High - Significant impact on productivity

Feature Category

CLI commands and flags

Use Case Example

No response

Additional Context

No response

jscalo avatar Sep 18 '25 15:09 jscalo

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/7359
  2. https://github.com/anthropics/claude-code/issues/2705
  3. https://github.com/anthropics/claude-code/issues/6390

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

github-actions[bot] avatar Sep 18 '25 15:09 github-actions[bot]

This is similar to #6390 but also different in that it allows choosing specific prompts+responses from a menu.

jscalo avatar Sep 18 '25 15:09 jscalo

Hey, just another user here, but I really like this idea. I run into the exact same problem all the time, where a few failed approaches end up polluting the context right when I need it most. The UI you mocked up for /edit_context is super intuitive.

While we wait for a feature like this to hopefully get implemented, I've found a couple of workarounds in the docs that might help manage the context window.

1. Guide the Compaction Process

This is probably the closest thing to what you're asking for. The documentation for the /compact command mentions you can give it instructions.

From the en/docs/claude-code/costs file:

Add custom instructions: /compact Focus on code samples and API usage

So, you could try to manually guide the summarization process to ignore the "rabbit holes." For example:

> /compact please disregard our conversation about the XYZ library since it was a dead end, and focus on the final implementation using the ABC library.

It's not as precise as removing the prompts entirely, but it can help steer Claude to preserve the useful parts of the conversation when it summarizes.

2. Isolate Rabbit Holes with Subagents

This is more of a preventative measure. I've started using subagents for tasks that I suspect might become a "rabbit hole."

The docs on subagents (en/docs/claude-code/sub-agents) mention:

Context preservation: Each subagent operates in its own context, preventing pollution of the main conversation and keeping it focused on high-level objectives.

If I'm about to try a complex or experimental fix, I'll ask Claude to use a subagent (or create a temporary one). If it doesn't pan out, the main conversation's context window is unaffected.

3. The "Nuclear Option"

Of course, there's always /clear, which wipes the whole session. It's not ideal since you lose everything, but sometimes it's faster than dealing with a confused model.

Anyway, none of these are as good as your proposed /edit_context command, which would be a massive quality-of-life improvement. Just wanted to share what I've pieced together from the current toolset. Hope this helps

coygeek avatar Sep 18 '25 18:09 coygeek

I want to remove (somehow) for example: first half of conversations and all file mentions

n0isy avatar Sep 20 '25 17:09 n0isy

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.

github-actions[bot] avatar Dec 07 '25 10:12 github-actions[bot]

+1, would love to have this!

Pranav-Srinivasan avatar Dec 21 '25 08:12 Pranav-Srinivasan