Plugin: add proactive context usage alerts with one-tap compact#61
Open
mvanhorn wants to merge 1 commit intopwrdrvr:mainfrom
Open
Plugin: add proactive context usage alerts with one-tap compact#61mvanhorn wants to merge 1 commit intopwrdrvr:mainfrom
mvanhorn wants to merge 1 commit intopwrdrvr:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ContextUsageSnapshotdata is already available after every turn (stored inStoredBinding.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: AddedContextAlertLeveltype,lastContextAlertLevelfield onStoredBinding, and threshold constants (CONTEXT_ALERT_WARNING_PERCENT = 25,CONTEXT_ALERT_CRITICAL_PERCENT = 10)src/format.ts: AddedformatContextUsageAlert()that reusesformatCodexContextUsageSnapshot()for the usage text and prefixes level-appropriate messagingsrc/controller.ts: AddedcheckContextUsageAlert()private method called after each turn completion. Also resetslastContextAlertLeveltonullafter successful compaction so alerts can fire again if context refillssrc/format.test.ts: Three tests covering warning, critical, and empty-snapshot formattingAlert deduplication:
lastContextAlertLevelon 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 tonull.The "Compact Now" button uses
store.putCallback({ kind: "run-prompt", prompt: "/cas_compact" })to reuse the existing compact infrastructure.Video Demo
Testing
pnpm test- 197 tests pass (3 new forformatContextUsageAlert)pnpm typecheck- cleanThis contribution was developed with AI assistance (Claude Code).