Feature Request: Hook or plugin to deduplicate/evict data from context window

Resolved 💬 6 comments Opened Apr 1, 2026 by 3824108-cell Closed Jun 5, 2026

Feature Request

Allow hooks or plugins to remove or replace data already in the context window, not just add to it.

Problem

Currently, hooks (PreCompact, PostToolUse, etc.) can only add additionalContext — they cannot remove, summarize, or replace existing tool results or prior conversation turns. This means:

  1. Duplicate information (e.g., reading the same file twice, re-running similar analysis) stays in context permanently until compaction
  2. Large Bash outputs remain in full even when only success/failure matters
  3. Repeated system-reminder injections (from UserPromptSubmit hooks) accumulate with each prompt
  4. Users cannot build a "context garbage collector" plugin

Proposed Solution

A new hook type or mechanism that allows:

  • PostToolUse to return "replaceOutput": "summary text" — replacing the full tool result with a compact summary
  • A new ContextCleanup hook that runs periodically and can mark conversation turns for eviction or summarization
  • Or: allow PreCompact hooks to provide a priority list of what to keep vs. discard during compaction

Use Case

I run Claude Code with 15+ MCP servers, complex boot protocols, and long sessions. Context fills up fast. I am willing to write this plugin myself if the hook API supports it.

Impact

Power users who build complex Claude Code setups (memory systems, MCP integrations, multi-project dashboards) hit context limits much faster than simple use cases. This feature would let us self-optimize without waiting for Claude Code core changes.

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗