Feature Request: Add low-context warning hook before compaction

Resolved 💬 3 comments Opened Feb 5, 2026 by victorveloso Closed Feb 9, 2026

Problem

Currently, the PreCompact hook only fires when compaction is already being triggered (either manually via /compact or automatically when context is full). There's no way to get an advance warning when context is getting low.

This makes it impossible to implement a workflow like:

  1. At ~15% context remaining → show warning to user
  2. User runs /context-save to write session log
  3. Compaction happens safely with context preserved

Current Behavior

  • PreCompact fires during compaction, not before
  • No hook event for "context is at X% remaining"
  • No programmatic access to current context percentage
  • Users lose important context because they don't know compaction is imminent

Requested Feature

Add a new hook event: LowContext (or similar) that fires when context reaches a configurable threshold (e.g., 15% remaining).

Example Configuration

{
  "hooks": {
    "LowContext": [
      {
        "threshold": 15,
        "hooks": [
          {
            "type": "command",
            "command": "echo 'WARNING: Context at 15%! Run /context-save now.'"
          }
        ]
      }
    ]
  }
}

Use Case

Power users who run long sessions need time to:

  • Save session logs before compaction
  • Capture important context that would otherwise be lost
  • Run custom backup/sync scripts

Without advance warning, compaction happens suddenly and important context is lost in the summarization.

Workarounds Attempted

  • PreCompact hook: Only fires during compaction, too late
  • Periodic /context check: Manual, easy to forget
  • Rule-based self-monitoring by Claude: Unreliable, no context % visibility

Impact

This significantly impacts users who rely on Claude Code for extended work sessions. The current behavior forces users to either:

  1. Manually check /context frequently (disrupts flow)
  2. Accept losing context to sudden compaction (loses important work)

Thank you for considering this enhancement!

View original on GitHub ↗

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