Skip to content

Instantly share code, notes, and snippets.

@ds17f
Created March 4, 2026 05:13
Show Gist options
  • Select an option

  • Save ds17f/1a44bd56c922daf4d6d0d96d60bfc91b to your computer and use it in GitHub Desktop.

Select an option

Save ds17f/1a44bd56c922daf4d6d0d96d60bfc91b to your computer and use it in GitHub Desktop.
claude-later: sleep until a time then run claude
#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: claude-later <time> [claude args...]"
echo " claude-later 2:00am -p \"write hello world in go\""
echo " claude-later 14:30 -p \"summarize my notes\""
exit 1
}
[[ $# -lt 1 ]] && usage
TARGET_TIME="$1"
shift
# Parse target epoch
TARGET_EPOCH=$(date -d "$TARGET_TIME" +%s 2>/dev/null) || {
echo "Error: can't parse time '$TARGET_TIME'" >&2
exit 1
}
NOW_EPOCH=$(date +%s)
# If the time has already passed today, target tomorrow
if [[ "$TARGET_EPOCH" -le "$NOW_EPOCH" ]]; then
TARGET_EPOCH=$(date -d "tomorrow $TARGET_TIME" +%s)
fi
SLEEP_SECONDS=$(( TARGET_EPOCH - NOW_EPOCH ))
WAKE_AT=$(date -d "@$TARGET_EPOCH" "+%Y-%m-%d %I:%M %p")
echo "Sleeping until $WAKE_AT (${SLEEP_SECONDS}s from now)..."
sleep "$SLEEP_SECONDS"
echo "Waking up — updating claude..."
claude update
echo "Running: claude $*"
claude "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment