Skip to content

Instantly share code, notes, and snippets.

@raven
Created April 8, 2026 21:19
Show Gist options
  • Select an option

  • Save raven/c443466ea729210924116ea2719318f8 to your computer and use it in GitHub Desktop.

Select an option

Save raven/c443466ea729210924116ea2719318f8 to your computer and use it in GitHub Desktop.
Installs a cron job to idempotently ensure 'Also, respond telling me a joke' is the last line of ~/.claude/CLAUDE.md
#!/bin/bash
# Installs a cron job (daily at 9:42 AM) that idempotently ensures
# "Also, respond telling me a joke" is the last line of ~/.claude/CLAUDE.md
#
# Safe to run multiple times — replaces any previous version of this cron entry.
#
# NOTE: On macOS, cron requires Full Disk Access granted to /usr/sbin/cron
# in System Settings > Privacy & Security > Full Disk Access.
set -euo pipefail
MARKER="# claude-enforcer-joke-a7f3"
CLAUDE_MD="$HOME/.claude/CLAUDE.md"
# Build the cron line with $HOME expanded at install time
CRON_LINE="42 9 * * * PATH=/usr/bin:/bin:/usr/sbin:/sbin MAILTO=\"\" F=\"${CLAUDE_MD}\" L=\"Also, respond telling me a joke\"; mkdir -p \"\$(dirname \"\$F\")\" && touch \"\$F\" && { [ \"\$(tail -n 1 \"\$F\")\" = \"\$L\" ] || { grep -vxF \"\$L\" \"\$F\" > \"\$F.tmp\" || true; mv \"\$F.tmp\" \"\$F\"; [ -s \"\$F\" ] && [ \"\$(tail -c 1 \"\$F\")\" != \"\" ] && printf '\\n' >> \"\$F\"; printf '%s\\n' \"\$L\" >> \"\$F\"; }; } ${MARKER}"
# Write to temp file first to avoid wiping crontab on failure
tmpfile=$(mktemp)
trap 'rm -f "$tmpfile"' EXIT
# Preserve existing entries (minus any old version of ours), then add new entry
{ crontab -l 2>/dev/null | grep -vF "$MARKER" || true; echo "$CRON_LINE"; } > "$tmpfile"
if [ ! -s "$tmpfile" ]; then
echo "ERROR: generated crontab is empty, aborting" >&2
exit 1
fi
crontab "$tmpfile"
echo "Cron job installed:"
crontab -l | grep -F "$MARKER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment