Skip to content

Latest commit

Β 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’° Claude Cache / Cost Widget

Watch your Claude Code spend in real-time. Save up to 90% with prompt caching.

A lightweight always-on-top desktop widget (Windows / PowerShell + WinForms) that shows live cache heat and actual token costs for your Claude Code sessions. No estimatesβ€”real numbers from your transcript.

The problem it solves: Long Claude Code sessions are expensive. Prompt caching can save 90%+ on tokens, but you can't see it happening. This widget makes the invisible visible.


✨ What You Get

πŸ“Š Real-Time Metrics

  • Cache Clock β€” See your cache expire (green "hot" β†’ yellow "cooling" β†’ red "cold")
  • Live Token Count β€” In / Cached / Out tokens with cost breakdown
  • Cost Per Turn β€” Actual USD spent (from real API usage)
  • Total Spend β€” Cumulative tokens + savings + burn rate ($/min)
  • Plan Usage β€” Monthly quota utilization (optional)

🎯 Key Features

βœ… Live cache heat tracking β€” Know when you're about to lose your 90% discount
βœ… Actual costs β€” Reads real message.usage from transcripts, not estimates
βœ… Multiple models β€” Claude 3.5 Sonnet, Opus, Haiku pricing built-in
βœ… Automatic hooks β€” Installs into Claude Code lifecycle (SessionStart, Stop)
βœ… Draggable widget β€” Always visible, never blocking
βœ… Right-click menu β€” Quick access to transcripts and settings
βœ… Single-instance β€” No dupes, auto-restarts cleanly


🎬 Visual Preview

The widget displays:

  • Top section β€” Cache countdown (time until 5-min TTL expires)
  • Middle β€” Your current turn breakdown (input / cache-read / output tokens)
  • Bottom β€” Session totals (all tokens + USD + how much cache saved you)
  • Right-click menu β€” Copy summary, open transcript, open project folder

Example:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CACHE: quente (4m 23s)  [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ] β”‚  ← Cache fresh!
β”‚  Token: 1,200 in | 450 cache | 380 out
β”‚  Cost:  $0.042 per turn | Total: $1.83 | Saved: $8.70 (90%)
β”‚  Plan:  21% of month quota
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Windows 10/11 + PowerShell 5.1+ (PowerShell 7 recommended)
  • Claude Code (writes transcripts to ~/.claude/projects/)
  • Python 3 (optional β€” only for plan/budget section)

Install (One Command)

git clone https://github.com/Codyte/claude-cache-widget.git
cd claude-cache-widget
powershell -ExecutionPolicy Bypass -File .\install.ps1

Done. The widget launches immediately and auto-starts on next Claude Code session.

Uninstall

powershell -ExecutionPolicy Bypass -File .\install.ps1 -Uninstall

πŸ“– Documentation

Configuration

Edit config.json to customize:

  • context_limit β€” Your model's token limit
  • cache_ttl_seconds β€” How long cache stays hot (default: 300s)
  • idle_close_minutes β€” Auto-close after N min of inactivity
  • prices.json β€” Token pricing (auto-updates when Anthropic changes rates)

How It Works

  1. Install hooks β€” install.ps1 registers three lifecycle hooks in ~/.claude/settings.json:

    • SessionStart β†’ launches widget
    • UserPromptSubmit β†’ marks turn as "busy" (pauses cache clock)
    • Stop β†’ marks turn as "idle" (starts cache expiry countdown)
  2. Read transcripts β€” Widget monitors ~/.claude/projects/*/latest.jsonl for real message.usage objects

  3. Calculate costs β€” Applies pricing from prices.json:

    • in = input tokens
    • cr = cache-read tokens (cheap!)
    • cw = cache-write tokens
    • out = output tokens
  4. Show savings β€” Displays how much cheaper this turn was vs. no caching

Privacy & Security

  • βœ… Local-only β€” reads only your transcripts on disk
  • βœ… No tracking β€” never sends data anywhere
  • βœ… OAuth optional β€” plan section uses same token Claude CLI already has
  • βœ… Credentials safe β€” .credentials.json never committed

πŸ’‘ Use Cases

Case 1: Long Refactoring Session

Before: Load full codebase context each turn β†’ $15 per turn (5K tokens)
After:  Cache keeps context hot β†’ $0.50 per turn (45 cache-read tokens)
        πŸ’Ύ 90% savings per turn!

Case 2: Multi-File Debugging

Turn 1: Load error context  β†’ $2.10 (cache written)
Turn 2-5: Reuse context    β†’ $0.20 each (cache hit!)
         πŸ’Ύ Saved $8 on just 5 turns

Case 3: API Integration Work

Session runs for 2 hours with context reuse
Total spend: $18.50 | Total saved via cache: $167
         πŸ’Ύ That's an 90% savings day!

βš™οΈ Advanced

Command-Line Usage (AI Agents)

# One-shot install for Copilot or other agents
git clone https://github.com/Codyte/claude-cache-widget.git claude-cache-widget
powershell -ExecutionPolicy Bypass -File .\claude-cache-widget\install.ps1

The installer is fully idempotent β€” running it twice just restarts the widget.

Custom Installation Path

.\install.ps1 -InstallDir "C:\MyTools\Claude"

Skip Hook Registration

.\install.ps1 -NoHooks

🀝 Contributing

Good first issues:

  • Translate UI to English (currently Portuguese) β€” see config.json for string keys
  • Support other LLM cost models (GPT-4, Gemini, Mixtral)
  • Add dark mode toggle
  • Cross-platform port (macOS + Linux via system tray)
  • Test on Windows 11 + PowerShell 7

Development:

# Edit widget-ui.ps1, then restart
.\install.ps1  # Restarts instantly

❓ FAQ

Q: Does this work with Claude Web UI (not Claude Code)? A: Not currently β€” it only reads Claude Code transcripts. The web UI doesn't write transcripts locally.

Q: Will this slow down my session? A: No. The widget runs in a separate process and uses negligible CPU (<1%).

Q: Is my data safe? A: Completely. The widget is local-only and never connects to the internet (except optional OAuth for plan usage).

Q: Can I see historical costs? A: Yes β€” explore ~/.claude/projects/*/latest.jsonl directly or check the widget's right-click menu.

Q: Why the Portuguese UI? A: The author is Brazilian πŸ‡§πŸ‡·. English translation is a welcome contribution!


πŸ› Troubleshooting

Widget doesn't appear after install

# Check if it's running
Get-Process | Where-Object {$_.ProcessName -like "*PowerShell*"}

# Restart manually
.\install.ps1

Costs look wrong

  1. Check prices.json β€” is it up to date with Anthropic's current rates?
  2. Verify message.usage in your transcript β€” sometimes early turns don't have it
  3. Reload config: Ctrl+R in widget (if implemented)

Widget won't install on PowerShell 5.1

The installer uses ConvertFrom-Json -AsHashtable which doesn't exist in PS 5.1. Use PowerShell 7+ or edit settings.json manually (instructions printed by installer).


πŸ“Š Pricing Reference

Default pricing (as of 2024):

  • Claude 3.5 Sonnet β€” $3/$15/$3/$15 per 1M tokens (in/cache-read/cache-write/out)
  • Claude 3 Opus β€” $15/$75/$15/$75 per 1M tokens
  • Claude 3 Haiku β€” $0.25/$1.25/$0.25/$1.25 per 1M tokens

Update prices.json when rates change. Contributions welcome!


πŸ“ License

MIT β€” See LICENSE

Not affiliated with Anthropic. "Claude" is a trademark of Anthropic.


🎯 Roadmap

  • English UI (v2)
  • Dark mode
  • Alerts for cache expiry
  • Cost trending over time
  • macOS version
  • GPU memory tracking (for local LLMs)

Have an idea? Open an issue!

About

No description, website, or topics provided.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages