Feature: Inject context usage as system-reminder to model before auto-compact

Resolved 💬 3 comments Opened Mar 10, 2026 by DavidXueArc Closed Mar 14, 2026

Problem

When working on long development sessions, I have a structured knowledge extraction workflow that needs to run before context compaction. Currently:

  1. StatusLine has context usage data (context_window.used_percentage) — but only for terminal UI, not visible to the model
  2. PreCompact hook fires before auto-compact — but can only run shell commands, cannot inject messages into the conversation
  3. The model itself has zero awareness of context usage — it cannot proactively trigger actions before context runs out

This means the model cannot autonomously perform cleanup/extraction tasks before compaction destroys the working context. The user must manually monitor the CLI's context indicator and intervene — which defeats the purpose of an autonomous agent.

Proposed Solution

Add the ability for the model to receive context usage information, either via:

Option A: System-reminder injection at configurable threshold

Allow hooks or settings to inject a <system-reminder> into the conversation when context usage crosses a threshold:

{
  "contextThreshold": {
    "percentage": 70,
    "message": "Context at 70%. Run extraction workflow before continuing."
  }
}

Option B: Expose context usage in PreCompact hook with conversation injection

Allow PreCompact hooks to inject a message into the model's conversation (not just run shell commands):

{
  "hooks": {
    "PreCompact": [{
      "matcher": "auto",
      "hooks": [{
        "type": "inject",
        "message": "Context is about to be compacted. Please run your extraction workflow first."
      }]
    }]
  }
}

Option C: New ContextThreshold hook event

A new hook event that fires when context usage crosses a configured percentage, with the ability to pause auto-compact until the model completes a specified action.

Use Case

Many power users build structured workflows around Claude Code sessions — e.g., updating project docs, extracting reusable knowledge, summarizing decisions made during the session. These workflows need to run before context is lost to compaction.

Today, the workaround is:

  • User watches the CLI context indicator manually
  • User types a trigger phrase to tell the model to run the workflow
  • If the user forgets or isn't watching, auto-compact fires and session context is lost

The irony: the data exists (StatusLine receives it), the timing mechanism exists (PreCompact fires), but the model is blind — these two capabilities aren't connected to the model's conversation.

Related Issues

  • #24320 — Context threshold hooks to auto-trigger skills
  • #29829 — Expose session cost and context usage in hook event data
  • #28962 — Context window usage indicator with threshold alerts

This request specifically focuses on model-facing injection (not just user-facing UI or shell hooks), which is the missing piece that would enable fully autonomous context-aware workflows.

View original on GitHub ↗

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