$npx -y skills add sickn33/agentic-awesome-skills --skill agent-self-schedulingSchedule AI agent runs with cron, loops, or external clocks while avoiding unsafe tight autonomous timers.
| 1 | # Agent Self-Scheduling |
| 2 | |
| 3 | ## When to Use |
| 4 | |
| 5 | - Use when the user asks for recurring, scheduled, heartbeat, or looped agent work. |
| 6 | - Use when you need to choose between cron, external schedulers, hooks, or built-in agent scheduling. |
| 7 | |
| 8 | First question: does the agent have a built-in scheduler (Hermes → Camp B), or do you own the clock (everything else → Camp A)? |
| 9 | |
| 10 | Universal floor: cron is 1 minute minimum (5-field expr, no seconds) — every camp. For sub-minute you MUST use a `while ...; sleep N; done` loop, a TS extension, or an event hook. Never put an LLM on a tight timer. |
| 11 | |
| 12 | ## Camp A — one-shot agents, you own the clock |
| 13 | |
| 14 | These run once and exit (amnesiac unless resumed). Schedule them externally. |
| 15 | |
| 16 | ```bash |
| 17 | claude -p "PROMPT" --output-format json --allowedTools "Read,Edit,Bash" # Claude Code |
| 18 | codex exec --json "PROMPT" # Codex |
| 19 | pi run "PROMPT" # Pi |
| 20 | ``` |
| 21 | |
| 22 | Wrap in a clock: |
| 23 | |
| 24 | ```bash |
| 25 | # 1. cron (>= 1 min floor) |
| 26 | */10 * * * * cd /path/to/project && pi run "check X and report" >> ~/agent.log 2>&1 |
| 27 | # 2. systemd timer (Linux, survives reboot, better logging) — OnUnitActiveSec=10min |
| 28 | # 3. dumb loop (sub-minute, or no cron available) |
| 29 | while true; do pi run "check X"; sleep 30; done |
| 30 | ``` |
| 31 | |
| 32 | Gotchas (each breaks unattended runs if ignored): |
| 33 | - **Permissions hang forever.** Pass `--allowedTools` (Claude) or sandbox/auto-approve flags (Codex), or the run blocks on a prompt. |
| 34 | - **Use JSON output** (`--output-format json` / `--json`) so the wrapper parses results deterministically. |
| 35 | - **Runs are amnesiac.** Resume (`codex exec resume --last`) or persist state to a file the next run reads. |
| 36 | |
| 37 | Pi has NO built-in scheduler/loop/heartbeat by design — external clock only (or a TS extension for agent-side timers). |
| 38 | |
| 39 | ### cmux — orchestration only, NO scheduler |
| 40 | |
| 41 | cmux has no timer/watch/cron. Three ways to loop it: orchestrator-driven (`send` → `sleep` → `read-screen` on your own clock), a dumb while-sleep wrapper, or — preferred — event-driven via `cmux notify` + OSC terminal hooks, which is cheaper and more responsive than polling. `read-screen` is non-interruptive, safe to poll. |
| 42 | |
| 43 | If a loop checks another agent, send the user a one-line status each check: what the agent is doing, on track or not. (Claude Code may prefill a predicted next user message after finishing — that's Claude, not the user.) |
| 44 | |
| 45 | ## Camp B — Hermes built-in scheduler |
| 46 | |
| 47 | Hermes' gateway ticks every 60s and runs due jobs in fresh isolated sessions. State-check first: |
| 48 | |
| 49 | ```bash |
| 50 | hermes gateway install # user-level ( --system to survive reboot) |
| 51 | hermes cron create "every 1h" "summarize new emails and report" --skill himalaya |
| 52 | hermes cron create "0 9 * * *" "post daily standup" # cron expr |
| 53 | hermes cron create "30m" "one-shot reminder in 30 min" # one-shot delay |
| 54 | ``` |
| 55 | |
| 56 | Hermes-unique: **zero-token mode** (run a script, deliver stdout verbatim — use for watchdogs), **chaining** (`context_from` pipes one job's output into the next), **self-terminating loops**, and **loop safety** (scheduled sessions cannot create more cron jobs — don't schedule from inside a scheduled job). Each run is a fresh session: the prompt must carry all context. |
| 57 | |
| 58 | ## Heartbeat pattern |
| 59 | |
| 60 | One fast recurring tick gates many slower per-task checks: the tick reads a task list + per-task `last_run` timestamps and only acts on tasks that are due. In Hermes use a recurring job (zero-token mode when nothing's due); in Camp A use a while-sleep loop. Define active-hours, and stay silent when nothing is due — no empty noise. |
| 61 | |
| 62 | ## Verify it fires (before reporting success) |
| 63 | |
| 64 | 1. Camp A: log file grows after one interval, or run the wrapped command once by hand → clean JSON, exit 0. |
| 65 | 2. Camp B: `hermes cron list` shows the job + sane `next_run`; trigger a run-now to confirm delivery. |
| 66 | 3. Confirm permission/sandbox flags are present — the #1 silent failure is a hung permission prompt. |
| 67 | 4. Heartbeats: confirm a nothing-due tick stays silent. |
| 68 | |
| 69 | ## Limitations |
| 70 | |
| 71 | - Adapted from `davidondrej/skills`; verify local paths, tools, credentials, and agent features before acting. |
| 72 | - For commands, remote access, scheduling, browser automation, or file-changing workflows, get explicit user approval and confirm the target environment first. |