[FEATURE] fire a hook/event when context window approaches compression threshold

Resolved 💬 4 comments Opened Mar 11, 2026 by veridian69 Closed Mar 15, 2026

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

When the context window approaches its limit and auto-compression is about to occur, the model has no warning.
This means:

  • No opportunity to deliberately save important state before compression flattens it
  • No way to trigger a "checkpoint" action (e.g. write key facts to persistent memory)
  • The compression is invisible and lossy — structured information becomes prose summaries

Proposed Solution

Add a hook (similar to the existing PreToolUse/PostToolUse hooks) that fires when the context reaches a configurable threshold (e.g. 80% of the context window). This would allow users to run a script or command — for example, flushing important context to an external memory store before compression occurs.

Alternative Solutions

_No response_

Priority

Medium - Would be very helpful

Feature Category

API and model interactions

Use Case Example

A persistent memory system like mnemon could be triggered automatically to snapshot current context before it gets compressed, preserving structured facts that would otherwise be degraded.

Possible shape:
// settings.json
{
"hooks": {
"ContextWindowWarning": [
{ "matcher": "", "hooks": [{ "type": "command", "command": "mnemon checkpoint" }] }
]
}
}

Additional Context

_No response_

View original on GitHub ↗

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