Created
March 4, 2026 05:13
-
-
Save ds17f/1a44bd56c922daf4d6d0d96d60bfc91b to your computer and use it in GitHub Desktop.
claude-later: sleep until a time then run claude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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