Skip to content

Instantly share code, notes, and snippets.

@sickerin
Last active August 24, 2026 14:53
Show Gist options
  • Select an option

  • Save sickerin/78ec5d0a5cd9d8787715a5139fda25b3 to your computer and use it in GitHub Desktop.

Select an option

Save sickerin/78ec5d0a5cd9d8787715a5139fda25b3 to your computer and use it in GitHub Desktop.
Resume claude

Resume claude after running out of usage limit. For Macos, it uses the automation scripts to resume usage.

For instance if your usage resets at 3pm

./resume_claude.sh "15:00"
#!/bin/bash
# Usage: ./resume_claude.sh HH:MM
TARGET_TIME="$1"
if [ -z "$TARGET_TIME" ]; then
echo "Usage: $0 HH:MM (24-hour format)"
exit 1
fi
# Convert to seconds since midnight
target_sec=$(( $(date -j -f "%H:%M" "$TARGET_TIME" +%s) ))
now_sec=$(( $(date +%s) ))
# If target time is in the future today, wait; else, exit
if [ "$target_sec" -le "$now_sec" ]; then
echo "⏱️ $TARGET_TIME is in the past. Exiting."
exit 1
fi
# Wait until the time comes
echo "πŸ•’ Waiting until $TARGET_TIME..."
sleep $(( target_sec - now_sec ))
# === After waiting, run Claude automation ===
DIR=$(pwd)
osascript <<EOF
tell application "Terminal"
do script "cd \"$DIR\"; claude --resume"
activate
end tell
EOF
sleep 2
osascript <<EOF
tell application "System Events"
tell application "Terminal" to activate
delay 0.5
keystroke "1"
delay 0.5
keystroke "continue"
delay 0.5
key code 36 using command down
end tell
EOF
@JunusErgin

Copy link
Copy Markdown

Fix: Handle times after midnight correctly

Currently, the script exits when called like this:

./resume_claude.sh "00:21"

if the current time is already later than 00:21.

The reason is that 00:21 is interpreted as today at 00:21. When the goal is to resume Claude a few hours later and the target time is after midnight, the script should automatically use the next day.

Here is the adjusted version:

#!/bin/bash

# Usage: ./resume_claude.sh HH:MM
TARGET_TIME="$1"

if [ -z "$TARGET_TIME" ]; then
  echo "Usage: $0 HH:MM"
  exit 1
fi

# Validate HH:MM format
if ! [[ "$TARGET_TIME" =~ ^([01][0-9]|2[0-3]):[0-5][0-9]$ ]]; then
  echo "Invalid time format. Use HH:MM, for example 00:21"
  exit 1
fi

# Current timestamp
now_sec=$(date +%s)

# Build target timestamp for today
today=$(date +%F)
target_sec=$(date -j -f "%Y-%m-%d %H:%M" "$today $TARGET_TIME" +%s)

# If target time already passed today, use tomorrow
if [ "$target_sec" -le "$now_sec" ]; then
  tomorrow=$(date -v+1d +%F)
  target_sec=$(date -j -f "%Y-%m-%d %H:%M" "$tomorrow $TARGET_TIME" +%s)
fi

wait_seconds=$((target_sec - now_sec))
target_readable=$(date -r "$target_sec" "+%Y-%m-%d %H:%M:%S")

echo "πŸ•’ Waiting until $target_readable..."
echo "⏳ Sleeping for $wait_seconds seconds."

sleep "$wait_seconds"

DIR=$(pwd)

osascript <<EOF
tell application "Terminal"
    do script "cd \"$DIR\"; claude --resume"
    activate
end tell
EOF

sleep 2

osascript <<EOF
tell application "System Events"
    tell application "Terminal" to activate
    delay 0.5

    keystroke "1"
    delay 0.5

    keystroke "continue"
    delay 0.5
    key code 36
end tell
EOF

With this change, calls around midnight work as expected. For example:

./resume_claude.sh "00:21"

If 00:21 has already passed today, the script waits until 00:21 tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment