# Cache Efficiency Monitor Claude Code prompt caching efficiency monitor tracking cache hits, write efficiency, and cost savings with visual hit rate indicators and optimization recommendations. --- ## Metadata **Title:** Cache Efficiency Monitor **Category:** statuslines **Author:** JSONbored **Added:** October 2025 **Tags:** prompt-caching, cache-efficiency, cost-savings, hit-rate, cache-optimization **URL:** https://claudepro.directory/statuslines/cache-efficiency-monitor ## Overview Claude Code prompt caching efficiency monitor tracking cache hits, write efficiency, and cost savings with visual hit rate indicators and optimization recommendations. ## Content #!/usr/bin/env bash CACHE EFFICIENCY MONITOR FOR CLAUDE CODE TRACKS PROMPT CACHING PERFORMANCE AND COST SAVINGS READ JSON FROM STDIN read -r input EXTRACT CACHE METRICS (IF AVAILABLE IN JSON) cachereadtokens=$(echo "$input" | jq -r '.cost.cachereadinput_tokens // 0') cachecreatetokens=$(echo "$input" | jq -r '.cost.cachecreationinput_tokens // 0') regularinputtokens=$(echo "$input" | jq -r '.cost.input_tokens // 0') CALCULATE TOTAL INPUT TOKENS totalinput=$((cachereadtokens + cachecreatetokens + regularinput_tokens)) AVOID DIVISION BY ZERO if [ $total_input -eq 0 ]; then total_input=1 fi CALCULATE CACHE HIT RATE (PERCENTAGE OF TOKENS READ FROM CACHE) if [ $cachereadtokens -gt 0 ]; then cachehitrate=$(( (cachereadtokens * ) / total_input )) else cachehitrate=0 fi CALCULATE WRITE EFFICIENCY (CACHE CREATION VS REGULAR INPUT) if [ $cachecreatetokens -gt 0 ]; then writepercentage=$(( (cachecreatetokens * ) / totalinput )) else write_percentage=0 fi CACHE EFFICIENCY SCORING if [ $cachehitrate -ge 50 ]; then CACHE_COLOR="\[38;5;46m" # Green: Excellent caching (>50% hit rate) CACHE_ICON="✓" CACHE_STATUS="EXCELLENT" elif [ $cachehitrate -ge 25 ]; then CACHE_COLOR="\[38;5;226m" # Yellow: Good caching (% hit rate) CACHE_ICON="●" CACHE_STATUS="GOOD" elif [ $cachehitrate -gt 0 ]; then CACHE_COLOR="\[38;5;208m" # Orange: Low caching (% hit rate) CACHE_ICON="⚠" CACHE_STATUS="LOW" else CACHE_COLOR="\[38;5;250m" # Gray: No caching CACHE_ICON="○" CACHE_STATUS="NONE" fi ESTIMATE COST SAVINGS (CACHE READS COST 90% LESS THAN REGULAR INPUT) if [ $cachereadtokens -gt 0 ]; then # Savings = cachereadtokens * 0.9 (90% discount) savingstokens=$(echo "scale=0; $cacheread_tokens * 0.9 / 1" | bc) savingsdisplay="💰 ~${savingstokens} tok saved" else savings_display="" fi BUILD CACHE HIT RATE BAR (20 CHARACTERS WIDE) hitbarfilled=$(( cachehitrate / 5 )) # Each char = 5% hitbarempty=$(( 20 - hitbarfilled )) if [ $hitbarfilled -gt 0 ]; then hitbar=$(printf "█%.0s" $(seq 1 $hitbarfilled))$(printf "░%.0s" $(seq 1 $hitbar_empty)) else hit_bar="░░░░░░░░░░░░░░░░░░░░" fi OPTIMIZATION RECOMMENDATION if [ $cachehitrate -eq 0 ] && [ $cachecreatetokens -eq 0 ]; then RECOMMENDATION="(Enable caching?)" elif [ $cachehitrate -lt 25 ] && [ $write_percentage -gt 50 ]; then RECOMMENDATION="(More reads needed)" else RECOMMENDATION="" fi RESET="\[0m" OUTPUT STATUSLINE if [ -n "$savings_display" ]; then echo -e "${CACHEICON} Cache: ${CACHECOLOR}${hitbar}${RESET} ${cachehitrate}% | ${savingsdisplay} ${RECOMMENDATION}" else echo -e "${CACHEICON} Cache: ${CACHECOLOR}${hitbar}${RESET} ${cachehit_rate}% ${RECOMMENDATION}" fi KEY FEATURES ? Real-time prompt cache hit rate tracking (percentage of tokens read from cache) ? Cache write efficiency monitoring (cache creation vs regular input ratio) ? Cost savings estimation based on 90% cache read discount ? Visual hit rate bar (20-char progress indicator, each █ = 5%) ? Efficiency scoring (excellent >50%, good %, low %, none 0%) ? Optimization recommendations (enable caching, increase reuse patterns) ? Color-coded status (green excellent, yellow good, orange low, gray none) ? Lightweight bash with bc for percentage calculations CONFIGURATION Format: bash Refresh Interval: 2000ms Position: left USE CASES ? Optimizing prompt caching strategy to reduce API costs ? Identifying inefficient cache usage patterns (high writes, low reads) ? Validating that prompt caching is properly enabled and working ? Tracking cost savings from cache utilization ? Debugging cache misses in long coding sessions ? Comparing caching efficiency across different projects/workflows TROUBLESHOOTING 1) Cache hit rate always showing 0% despite caching enabled Solution: Verify cache fields exist in JSON: echo '$input' | jq '.cost | {cacheread: .cachereadinputtokens, cachecreate: .cachecreationinputtokens}'. If fields missing, Claude Code version may not expose cache metrics. Check official docs for required version. Caching requires Claude 3.5 Sonnet or Opus with prompt caching feature enabled. 2) Cost savings calculation showing unrealistic numbers Solution: Script estimates savings using 90% discount formula (cache reads cost 10% of regular input). Verify cachereadtokens value: echo '$input' | jq .cost.cachereadinputtokens. Formula: savings = cacheread_tokens * 0.9. Adjust discount percentage in script if Claude pricing changes. 3) Recommendation showing 'Enable caching?' when caching is on Solution: Recommendation triggers when both cachereadtokens and cachecreatetokens are 0. This means no cache activity detected. Verify prompt caching is configured in Claude Code settings. Check that prompts contain cacheable prefixes (system messages, long contexts). Short sessions may not benefit from caching. 4) Hit rate bar not displaying correctly or showing as empty Solution: Ensure terminal supports Unicode block characters (█ and ░). Test with: echo -e '█████░░░░░'. Bar uses hitrate / 5 for scaling (each char = 5%). If hitrate is 0, shows full empty bar (20x ░). Verify cachehitrate calculation: (cachereadtokens * ) / total_input. 5) Write efficiency showing 'More reads needed' incorrectly Solution: Recommendation appears when hit_rate 50% (creating more cache entries than using them). This indicates inefficient caching pattern. Solution: Reuse prompts more, reduce unique cache writes. Check if session involves many one-off queries vs repeated patterns. TECHNICAL DETAILS Documentation: https://docs.claude.com/en/docs/claude-code/statusline PREVIEW ✓ Cache: ████████████░░░░░░░░ 60% | 💰 ~4, tok saved --- Source: Claude Pro Directory Website: https://claudepro.directory URL: https://claudepro.directory/statuslines/cache-efficiency-monitor This content is optimized for Large Language Models (LLMs). For full formatting and interactive features, visit the website.