### Install cachebeat user-level Source: https://github.com/arahim3/cachebeat/blob/main/README.md Installs cachebeat at the user level for all projects. Run these commands from the cachebeat project directory. The setup consists of two files: the skill and the watcher script. ```bash mkdir -p ~/.claude/skills/cachebeat cp SKILL.md beat.sh ~/.claude/skills/cachebeat/ ``` -------------------------------- ### Arm cachebeat background Bash task with beat.sh Source: https://github.com/arahim3/cachebeat/blob/main/SKILL.md Start ONE background task with run_in_background: true, substituting for idle minutes and for max hours. The command runs silently and exits on the beat; re-arm with the exact same string. The description must be 'cachebeat keepalive'. ```Bash Bash( command: "sh /beat.sh ", description: "cachebeat keepalive", run_in_background: true ) ``` -------------------------------- ### Check cache read and creation tokens from transcript Source: https://github.com/arahim3/cachebeat/blob/main/README.md Run inside the Claude Code session (prefix with '!') to inspect the latest assistant reply's token costs. A warm turn shows a large cache_read and a tiny cache_creation; a cold turn shows the reverse, indicating the context was rebuilt from scratch. ```bash F=$(ls ~/.claude/projects/*/"$CLAUDE_CODE_SESSION_ID".jsonl 2>/dev/null | head -1) echo "cache_read: $(tail -n 400 "$F" | grep -oE '"cache_read_input_tokens":[0-9]+' | tail -1 | grep -oE '[0-9]+')" echo "cache_creation: $(tail -n 400 "$F" | grep -oE '"cache_creation_input_tokens":[0-9]+' | tail -1 | grep -oE '[0-9]+')" ``` -------------------------------- ### Allow cachebeat watcher in Claude Code settings Source: https://github.com/arahim3/cachebeat/blob/main/README.md Adds a permission rule to Claude Code settings to allow all variants of the cachebeat watcher command without prompting. Use the absolute path exactly as it appears in the approval prompt; the rule is matched against the literal command. ```json { "permissions": { "allow": ["Bash(sh /Users/you/.claude/skills/cachebeat/beat.sh:*)"] } } ``` -------------------------------- ### beat.sh: background idle watcher loop Source: https://github.com/arahim3/cachebeat/blob/main/README.md Background shell task that polls the session transcript every 30 seconds. It exits with code 0 when the session has been idle for MINUTES*60 seconds, or 3 when the END deadline is reached. The activity signal is the last transcript line's timestamp, which only changes on a real turn, avoiding false positives from file-mtime bumps. ```bash PREV=__init__; LAST=$(date +%s) while [ "$(date +%s)" -lt "$END" ]; do sleep 30 # Activity signal = timestamp of the last transcript line. It changes only on a # real turn — a bare file-mtime bump (recap rewrite, atomic save) does NOT fool it. SIG=$(tail -n 1 "$F" | grep -oE '"timestamp":"[^"]+"' | tail -1) [ -z "$SIG" ] && SIG=$(wc -c < "$F") [ "$SIG" != "$PREV" ] && { PREV="$SIG"; LAST=$(date +%s); } # new turn -> reset clock IDLE=$(( $(date +%s) - LAST )) [ "$IDLE" -ge $(( MINUTES*60 )) ] && exit 0 # exit wakes Claude -> cache refreshed -> re-arm done exit 3 # auto-stop deadline reached ``` -------------------------------- ### cachebeat slash command usage Source: https://github.com/arahim3/cachebeat/blob/main/README.md Command-line invocations for the cachebeat slash command. The default idle threshold is 50 minutes with an 8-hour auto-stop; the threshold is clamped to 5–55 minutes, and the auto-stop duration can be customized. Use 'stop' to halt the watcher. ```text /cachebeat # fire after 50 min of inactivity, auto-stop after 8 h /cachebeat 40 # custom idle threshold in minutes (clamped to 5–55) /cachebeat 40 4 # custom threshold + auto-stop after 4 h /cachebeat stop # stop it ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.