Skip to content

Plugin: add proactive context usage alerts with one-tap compact#61

Open
mvanhorn wants to merge 1 commit intopwrdrvr:mainfrom
mvanhorn:osc/feat-proactive-context-usage-alerts
Open

Plugin: add proactive context usage alerts with one-tap compact#61
mvanhorn wants to merge 1 commit intopwrdrvr:mainfrom
mvanhorn:osc/feat-proactive-context-usage-alerts

Conversation

@mvanhorn
Copy link
Copy Markdown

Summary

Sends a proactive warning when context remaining drops below 25% and a critical alert below 10% after each turn. Each alert includes a one-tap "Compact Now" button. Alerts fire once per threshold crossing and reset after compaction.

Why this matters

Long-running Codex threads silently approach the context window limit. The ContextUsageSnapshot data is already available after every turn (stored in StoredBinding.contextUsage), but there's no proactive alert surface. Users discover the limit only when a turn fails or output quality drops.

This builds on the "push notification" direction in #25 (monitor channels).

Changes

  • src/types.ts: Added ContextAlertLevel type, lastContextAlertLevel field on StoredBinding, and threshold constants (CONTEXT_ALERT_WARNING_PERCENT = 25, CONTEXT_ALERT_CRITICAL_PERCENT = 10)
  • src/format.ts: Added formatContextUsageAlert() that reuses formatCodexContextUsageSnapshot() for the usage text and prefixes level-appropriate messaging
  • src/controller.ts: Added checkContextUsageAlert() private method called after each turn completion. Also resets lastContextAlertLevel to null after successful compaction so alerts can fire again if context refills
  • src/format.test.ts: Three tests covering warning, critical, and empty-snapshot formatting

Alert deduplication: lastContextAlertLevel on the binding tracks what was last alerted. Same-level alerts are suppressed. Downgrade from critical to warning is also suppressed (already alerted at a higher severity). Crossing above the warning threshold resets the level to null.

The "Compact Now" button uses store.putCallback({ kind: "run-prompt", prompt: "/cas_compact" }) to reuse the existing compact infrastructure.

Video Demo

Demo

Testing

  • pnpm test - 197 tests pass (3 new for formatContextUsageAlert)
  • pnpm typecheck - clean
  • Post-build dogfooding skipped (score 8/10). Tested via automated test suite only. Setup requires OpenClaw + Codex CLI + bot tokens.

This contribution was developed with AI assistance (Claude Code).

Send a warning when context remaining drops below 25% and a critical
alert below 10% after each turn. Each alert includes a one-tap
"Compact Now" button. Alerts fire once per threshold crossing and
reset after compaction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant