Skip to content

feat: add CacheTimer widget for prompt cache TTL countdown#307

Open
tuansondinh wants to merge 3 commits intosirmalloc:mainfrom
tuansondinh:main
Open

feat: add CacheTimer widget for prompt cache TTL countdown#307
tuansondinh wants to merge 3 commits intosirmalloc:mainfrom
tuansondinh:main

Conversation

@tuansondinh
Copy link
Copy Markdown

@tuansondinh tuansondinh commented Apr 15, 2026

Summary

Adds a new cache-timer widget that displays the remaining time on Anthropic's 5-minute prompt cache TTL directly in the status line.

No external dependencies. The widget reads the last assistant message timestamp directly from the transcript_path that Claude Code already passes to ccstatusline — no hooks, no additional tools required.

How it works

On each status line refresh, the widget:

  1. Reads the last few bytes of the transcript JSONL file
  2. Finds the most recent type: "assistant" entry
  3. Computes remaining = 300s − elapsed from that timestamp

Display states:

Output Meaning
🟢 4:52 Cache warm, >50% remaining
🟡 1:30 Draining, 20–50% remaining
🔴 0:15 Almost cold, <20% remaining
❄️ COLD Cache expired

Usage

Add cache-timer to your layout via the TUI or directly in ~/.config/ccstatusline/settings.json:

{ "type": "cache-timer" }

Pair with refreshInterval: 1 in your Claude Code statusLine config so the countdown ticks in real time when the agent is idle:

"statusLine": {
  "type": "command",
  "command": "npx -y ccstatusline@latest",
  "refreshInterval": 1
}

Files changed

  • src/widgets/CacheTimer.ts — new widget
  • src/widgets/index.ts — export
  • src/utils/widget-manifest.ts — registration

Tuan Son and others added 3 commits April 15, 2026 10:48
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>
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