feat: add CacheTimer widget (continues #307)#466
Open
zachthedev wants to merge 7 commits into
Open
Conversation
Reads ~/.claude/state/cache-timer-{session_id}.json written by the
claude-cache-countdown hooks and displays live cache state:
🔥 HOT — agent active, cache being refreshed
🟢 4:52 — countdown with green/yellow/red urgency colors
❄️ COLD — cache expired
Widget type: 'cache-timer', category: Session
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Instead of reading ~/.claude/state/cache-timer-{session_id}.json
(which required the claude-cache-countdown hooks to be installed),
the widget now reads the last assistant message timestamp directly
from the transcript_path provided by Claude Code.
No hooks, no external scripts — works out of the box with ccstatusline alone.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When Claude is processing a request, the transcript's last entry is a user message (the assistant response hasn't been written yet). The previous code only searched for assistant timestamps, so it would use the prior turn's timestamp — never showing HOT during active work. Now detects the pending user message and displays 🔥 HOT immediately. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Builds on the widget from sirmalloc#307 and aligns it with the empty-state convention the Cache widgets follow: instead of returning null when there is no transcript or no assistant turn yet, render n/a gated behind a new (h)ide when empty toggle, so the widget stays visible unless the user opts out. Also guard a malformed assistant timestamp so it can never reach the countdown as NaN, and document that a trailing user-role entry (a prompt or a tool result) is what drives the HOT state.
Sandboxed widget tests using temp transcript files: preview, n/a versus hidden empty-state, HOT during an in-flight turn, the green/yellow/red countdown buckets and COLD, the malformed-timestamp guard, and the hide-when-empty keybind and editor wiring.
The five state icons (HOT, fresh, draining, urgent, cold) become editable glyphs via the shared (g)lyph editor, declared as named SymbolSlots the same way the other symbol-aware widgets do, so nerd-font and ASCII users can replace the emoji with symbols that respect the widget color. A blanked glyph collapses its trailing space. The cache TTL is now configurable: a (t)tl keybind cycles 5m/1h and any positive ttlSeconds can be set in settings.json, matching Claude Code writing both 5-minute and 1-hour cache breakpoints. The 5-minute default and existing output are unchanged.
Adds cases for per-state glyph overrides (custom and blanked), the preview reflecting a custom glyph, a 1-hour TTL extending the countdown window, malformed-TTL fallback, the (t)tl cycle, and the editor TTL annotation; updates the keybind assertion for the new (t) and (g) binds.
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.
Continues #307 by @tuansondinh: his three commits, unchanged, rebased onto current
main, with follow-up commits to match the project conventions and round out the widget.What it does
A
cache-timerwidget (Session category) showing the time left on the prompt cache TTL, read straight fromtranscript_path(no hooks, no external deps): 🔥 HOT while a turn is in flight, a 🟢/🟡/🔴m:sscountdown as it drains, ❄️ COLD once expired.Follow-up commits on top of #307
n/agated behind a(h)ide when emptytoggle instead of returningnullwhen there is no transcript or assistant turn yet, matching the Cache / origin widgets so it stays visible unless opted out.NaN:NaN.(g)lypheditor as named symbol slots (like the git and compaction widgets), so nerd-font / ASCII users can swap them for symbols that respect the widget color.(t)tlkeybind cycles 5m/1h, and any positivettlSecondscan be set insettings.json. Anthropic''s ephemeral cache defaults to 5 minutes, but Claude Code also writes 1-hourcache_controlbreakpoints, so this lets the countdown track whichever tier you care about. Default stays 5 minutes.CacheTimer.test.tscovering preview, empty-state, HOT, the countdown buckets, COLD, the timestamp guard, custom/blanked glyphs, and the TTL cycle + annotation.bun run lintclean;bun testgreen (1609). Credit to @tuansondinh for the original widget.