feat: add compaction-counter widget#282
Open
CorticalCode wants to merge 1 commit intosirmalloc:mainfrom
Open
Conversation
Tracks context compaction events per session. When Claude Code compacts conversation context, used_percentage drops — this widget detects the drop and displays ↻N. Detection: any drop in used_percentage > 2 percentage points between consecutive renders counts as compaction. The 2-point threshold filters rounding noise and cache wobble while catching real compaction events on both 200K and 1M context windows. State stored per-session in ~/.cache/ccstatusline/compaction/ as JSON, following the skills caching pattern. Related: addresses gap noted in sirmalloc#92 Origin: ported from CorticalCode/cc-statusline https://github.com/CorticalCode/cc-statusline Co-Authored-By: Claude Opus 4.6 (1M context) <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
compaction-counterwidget that tracks context compaction events per sessionused_percentagedrops — this widget detects the drop and displays↻NHow It Works
Context only grows until compaction — any drop in
used_percentage> 2 percentage points between consecutive renders is counted as a compaction event. The 2-point threshold filters rounding noise and cache accounting wobble (±1 point) while reliably catching real compaction events on both 200K and 1M context windows.Per-session state is stored in
~/.cache/ccstatusline/compaction/compaction-{sessionId}.json, following the skills caching pattern.Caveats
/compactdetection is delayed until the next assistant message (no statusline update on/compactitself)used_percentageexcludes system overhead (~15%, per context_window.used_percentage in status line JSON is significantly inaccurate anthropics/claude-code#34537), but relative drops between renders are still observableChanges
src/utils/compaction.tssrc/widgets/CompactionCounter.ts↻Nor null, supports preview mode)src/utils/__tests__/compaction.test.tssrc/widgets/__tests__/CompactionCounter.test.tssrc/types/RenderContext.tsCompactionDatainterface andcompactionDatafieldsrc/ccstatusline.tssrc/utils/widget-manifest.tscompaction-countersrc/widgets/index.tsDesign Decisions
Test Plan
bun test— 24 new tests pass (11 detection + 13 widget), no regressionsbun run lint— zero errors, zero warningsbun run build— succeeds,dist/ccstatusline.jsproducedOrigin
Ported from CorticalCode/cc-statusline, a TypeScript statusline project with compression detection, burn-rate velocity projection, and SQLite usage logging.
🤖 Generated with Claude Code