Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save nickleefly/082a598437f2bfd2ce44bb78eed12eb6 to your computer and use it in GitHub Desktop.

Select an option

Save nickleefly/082a598437f2bfd2ce44bb78eed12eb6 to your computer and use it in GitHub Desktop.
claude code (cli) 5hour limit reset via bash script or cron

Use a small wrapper script (see claude-heartbeat-cron.sh)

Make it executable:

chmod +x ~/.local/bin/claude-heartbeat.sh

Edit crontab:

crontab -e

Add:

0 7  * * * ~/.local/bin/claude-heartbeat-cron.sh
5 12 * * * ~/.local/bin/claude-heartbeat-cron.sh
10 17 * * * ~/.local/bin/claude-heartbeat-cron.sh

Why this is better

  • No duplication risk from repeated installs
  • Logging persists across reboots
  • Easy to audit behavior
  • Easy to remove
  • Works even if your shell environment is minimal
#!/usr/bin/env bash
# ~/.local/bin/claude-heartbeat-cron.sh
LOG="$HOME/.claude-heartbeat.log"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Sending Claude heartbeat..." >> "$LOG"
if claude -p "hello" >/dev/null 2>&1; then
echo " ✓ Claude responded" >> "$LOG"
else
echo " ✗ Claude failed" >> "$LOG"
fi

What this dumb-ish script does

  • Periodically sends a minimal request to the claude CLI

  • Purpose:

    • verify connectivity
    • keep the CLI session “warm”
    • potentially advance or trigger the usage/session reset cycle if the backend treats activity as renewal
  • It does not guarantee a reset of any quota or limit

  • It makes no assumptions beyond “a successful request happened”

  • Can be used to “pre-warm” your session: by sending small requests before heavy usage, you increase the likelihood that the first quota reset happens sooner than usual

For example:

Scenarios

You want to “pre-warm” or consume a tiny amount of quota before starting your main work.

Example:

  • You start work at 09:00
  • Run a small request at 06:00 via the heartbeat script to trigger the quota/timer cycle early
  • After a few hours of heavy use (e.g., 11:00), the system performs its first reset, giving you a full quota refill sooner than normal

The cron implementation

  • Performs the same heartbeat functionality but is more stable
  • You create periodic pings via crontab that call and execute _claude-heartbeat-cron.sh_
  • Logs each request’s success or failure to a dedicated log file
  • Stateless, reliable, and minimal: each run is independent, making it easier to audit and schedule
  • Ideal for automating pre-warm cycles to increase the chance of early quota resets
#!/usr/bin/env bash
# Claude CLI heartbeat
# --------------------------------------------------
# Sends a minimal request at specific times each day.
# Purpose:
# - Confirm Claude CLI is reachable
# - Keep the session warm
# - Potentially refresh session/usage state
#
# IMPORTANT:
# This does NOT guarantee quota or limit resets.
# Any renewal behavior depends entirely on Claude's backend.
# --------------------------------------------------
SCHEDULED_TIMES=("07:00" "12:05" "17:10")
LOOP_INTERVAL=30 # seconds
last_run=""
echo "[claude-heartbeat] Watching times: ${SCHEDULED_TIMES[*]}"
while true; do
now_time="$(date '+%H:%M')"
today="$(date '+%Y-%m-%d')"
for t in "${SCHEDULED_TIMES[@]}"; do
key="${today} ${t}"
if [[ "$now_time" == "$t" && "$last_run" != "$key" ]]; then
last_run="$key"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Sending Claude heartbeat..."
if claude -p "hello" >/dev/null 2>&1; then
echo " ✓ Claude responded successfully"
else
echo " ✗ Claude CLI failed"
fi
fi
done
sleep "$LOOP_INTERVAL"
done
### Notes
# Time matching is **minute-accurate**, not second-accurate
# Loop interval can drift slightly, but the `last_run` guard prevents double-fires
# If the machine sleeps at the exact trigger time, the event is missed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment