[FEATURE] Claude clear context for itself
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
Give Caude the ability to run /clear or /compact for itself, but it preserves the last prompt + some message it can give to itself
Proposed Solution
Claude can run softer versions of /clear or /compact, preserving the last prompt (for when it's executing a plan and believe a good portion is done) and keeps some message to itself (for when it needs to know what's been done).
Alternative Solutions
_No response_
Priority
Medium - Would be very helpful
Feature Category
Other
Use Case Example
Example scenario:
I've given Claude a larger more detailed plan than it can handle in the current context.
Claude implements some features, and now has to worry about new features
Claude clears it's context about implementing the first few features, and goes back to a clean context window that includes just the original prompt that contains the plan + todolist if it made one + description from the last context window about what's been done.
Additional Context
This feature is for larger more detailed plans, which Claude currently almost certainly fails. This is largely due to how the autocompact works, where it may be in the middle of implementing something and then the context fails, or the autocompact may be affecting the prompt containing the detailed plan.
Currently, when Claude is given long and detailed plans that it cannot handle within a 200k context alone, it almost certainly starts messing up after auto compaction, misremembering details and optimizations, where after half-assing certain implementations, it frequently attempts band aid fixes or becomes inconsiderate of performance, which can all be fixed by giving it the plan prompt + what's been completed with a new context window.
Giving Claude the ability to prune it's own context window allows it to adhere more closely to plans compared to the autocompact used right now.
Showing cached comments. Read the full discussion on GitHub ↗
9 Comments
I'm looking for something similar to this. It's great that the plan mode offers a very limited version of it, but I'd like to have more control over it.
This would be very useful for me because I have several skills that go through requirements gathering -> planning -> priming beads tasks -> doing the work. I'd love to have Claude ask me if it should proceed to implementation, and giving me the option to automatically clear the context, then starting implementation (in this case, it would call /dev:work <bead id>).
It may make sense to have such a tool always ask the user whether it should clear the context, to prevent Claude from doing it at the wrong time.
Good option.
+1!
another option would be that if an agent has --dangerously-skip-permissions, it can switch to plan mode, make its plan, and then when it is ready, exit and clear context itself. then long running agents can do task-based things clearing context between tasks. Currently it can switch in and out of plan mode but doesn't have the option to clear context when leaving plan mode to implement, without human intervention
for context, i'm doing data cleaning for a research project, so i have one management claude running to scan the data and make cleaning tasks, and a few robot research assistants executing each cleaning task. it would definitely be nice for them to be able to clear their own context in a claude-native way between tasks.
This would be a good feature, my use case is a continuous development, where I have my agent go through github issues with a development process, each github issue is independent of the previous one, so all i need is that it starts fresh for the next github issue.
Indicating a message to pass on to the next instance of claude context would be helpful too, incase the github issues are dependent on previous ones
+1 I've been looking for something like this to help me run auto research loops that proactively clear its context window to prevent context rot at the start of each new loop
I second this. We now have /loop which works fine for me because the instruction in the loop references to persisted claude.md and task definitions on disk. The loop basically is ralph: `
/loop "Read claude.md, search directory X for todos. Pick one, do the task, remove the todo"It is way better to have a way to clear the context for each iteration than writing my own harness for claude -p "prompt" in bash/pwsh or whatever.
This really should be a command that can be executed post hook. For instance post tool use / post task etc, having the ability to run an internal
execute-clearwould allow us to make much more effective workflows without having the model 1. Hallucinate and 2. blowing out the context.