[FEATURE] Add --keep flag to /clear command to preserve last N messages
Resolved 💬 4 comments Opened Dec 24, 2025 by douglance Closed Dec 24, 2025
Problem Statement
When working on long sessions, /clear removes all context including recent relevant exchanges. /compact only summarizes but doesn't reduce context noise. Users need a middle ground - the ability to reset context while keeping the last few messages that are immediately relevant to their current task.
Proposed Solution
Add an optional --keep=N parameter to /clear:
/clear --keep=5 # Clear all but last 5 messages
/clear -k 5 # Short form
Each message (user or assistant) counts as 1, preserving complete message structure including tool uses.
Alternative Solutions
- Using
/compact(doesn't reduce noise, only compresses) - Manual copy-paste of recent context (error-prone, tedious)
- Starting new session and re-explaining context (wastes tokens)
Use Case Example
- Working on a complex debugging session for 30 minutes
- Context has grown large with many tangential tool calls
- Finally isolated the bug in the last 2-3 exchanges
- Want to clear old noise but keep the recent debugging context
/clear --keep=5preserves last 5 messages, clears everything else- Continue working with clean context and relevant recent history
Implementation Considerations
- Message Counting: Count individual messages (each user or assistant = 1)
- Tool Results: Preserve complete message structure including tool use blocks
- System Messages: Only user/assistant messages count toward N
- Transcript Handling: Create new transcript with preserved messages
- Hooks Compatibility:
transcript_pathshould point to new transcript
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗