Feature request: expose context window usage to hooks and support threshold-based triggers

Resolved 💬 3 comments Opened Apr 2, 2026 by tyfong-lbl Closed Apr 5, 2026

Summary

Enable hooks (or a new hook event) to access context window usage metrics and trigger actions at configurable thresholds — for example, automatically saving progress and clearing the context window at 50% usage.

Motivation

Long-running sessions risk losing valuable context when automatic compression kicks in unexpectedly. Users currently have no programmatic way to:

  1. Detect how full the context window is from a hook or skill
  2. Trigger memory-saving actions based on a threshold
  3. Automate graceful context management

This forces manual monitoring via /context and manual invocation of /clear.

Proposed Changes

Any combination of:

  • Expose context_usage_percent (or token counts) in hook input data — even just adding it to UserPromptSubmit or PostToolUse input would unlock threshold-based logic in user scripts
  • Add a ContextThreshold hook event — fires when context usage crosses a configurable percentage (e.g., 50%, 75%)

Use Cases

  • Auto-save session progress to memory files before context gets compressed
  • Trigger /clear at a controlled point rather than hitting the limit unexpectedly
  • Alert the user (via hook stderr) when context is getting large
  • Delegate remaining work to subagents when context is nearly full

View original on GitHub ↗

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