Feature Request: Add low-context warning hook before compaction
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:
- At ~15% context remaining → show warning to user
- User runs
/context-saveto write session log - Compaction happens safely with context preserved
Current Behavior
PreCompactfires 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
PreCompacthook: Only fires during compaction, too late- Periodic
/contextcheck: 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:
- Manually check
/contextfrequently (disrupts flow) - Accept losing context to sudden compaction (loses important work)
Thank you for considering this enhancement!
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗