{"skill":{"slug":"cron-gate","displayName":"Cron Gate","summary":"Pre-checks sessions for new messages via a zero-token Python script to trigger expensive OpenClaw crons only when new activity exists, saving tokens.","description":"# Cron Gate\n\n**Stop wasting tokens on crons with nothing to do.**\n\nEvery OpenClaw cron that spawns an isolated LLM session burns tokens — prompt loading, Weave files, tool calls — even when there's nothing new to process. If you run memory integration across 5 sessions twice a day, that's 10 LLM wake-ups. Most of them find nothing and go back to sleep, having burned ~40K tokens each.\n\nCron Gate is a zero-token Python gatekeeper that checks for new activity *before* triggering expensive LLM crons. No new messages? No wake-up. No tokens burned.\n\n## How It Works\n\n```\nSystem crontab (free)          OpenClaw cron (expensive)\n        │                              │\n   gate.py runs              disabled, waiting\n        │                              │\n   checks sessions.json       ┌───────┘\n        │                     │\n   new activity? ─── yes ───► triggers cron via API\n        │\n       no ──► exits silently (0 tokens)\n```\n\n1. A lightweight Python script runs on system crontab (zero LLM cost)\n2. It reads `sessions.json` to check `updatedAt` timestamps\n3. Compares against its own state file (last time it triggered each session)\n4. Only calls the OpenClaw gateway API to trigger crons for sessions with genuinely new messages\n5. Idle sessions never wake up — they cost nothing until someone talks in them\n\n## Install\n\n### 1. Copy the gate script\n\n```bash\ncp gate.py /opt/scripts/cron-gate.py\nchmod +x /opt/scripts/cron-gate.py\n```\n\n### 2. Configure your session-to-cron mapping\n\nEdit the `SESSION_CRONS` dict in `gate.py` to map your session keys to their integration cron IDs:\n\n```python\nSESSION_CRONS = {\n    \"agent:main:telegram:group:-1234567890\": {\n        \"evening\": \"your-evening-cron-id-here\",\n        \"morning\": \"your-morning-cron-id-here\",\n    },\n    \"agent:main:discord:channel:9876543210\": {\n        \"evening\": \"another-cron-id\",\n        \"morning\": None,  # skip morning for this session\n    },\n}\n```\n\n**Finding your session keys:** Look in `~/.openclaw/agents/main/sessions/sessions.json`\n\n**Finding your cron IDs:** Run `/crons` in chat or check the OpenClaw dashboard\n\n### 3. Disable the original crons\n\nFor each integration cron you're gating, disable it (but don't delete — the gate script triggers them on-demand):\n\n```\n/cron update <cron-id> enabled=false\n```\n\nOr ask your agent: \"Disable all memory integration crons — they'll be triggered by the gate script now.\"\n\n### 4. Add system crontab entries\n\n```bash\n# Evening integration window (adjust times to match your schedule)\n5 6 * * * /usr/bin/python3 /opt/scripts/cron-gate.py evening >> /var/log/cron-gate.log 2>&1\n\n# Morning integration window\n5 18 * * * /usr/bin/python3 /opt/scripts/cron-gate.py morning >> /var/log/cron-gate.log 2>&1\n```\n\n## Usage\n\n```bash\n# Dry run — see what would trigger without actually doing it\npython3 gate.py --dry-run evening\n\n# Force a specific slot (ignore time-of-day check)\npython3 gate.py morning\n\n# Normal operation (auto-detects slot from UTC hour)\npython3 gate.py\n```\n\n## Time Windows\n\nThe script auto-detects which slot to run based on UTC hour:\n- **Evening:** 4-8 UTC\n- **Morning:** 16-20 UTC\n\nOverride by passing `evening` or `morning` as an argument. When run from crontab with an explicit slot argument, the time window check is bypassed.\n\n## State File\n\nActivity timestamps are stored in `/opt/scripts/cron-gate-state.json` (configurable). This is how the gate knows what's \"new\" — it compares each session's `updatedAt` against the last time it triggered that cron.\n\nTo reset (re-trigger everything on next run):\n```bash\nrm /opt/scripts/cron-gate-state.json\n```\n\n## Token Savings\n\nReal-world numbers from the first deployment:\n- **Before:** 10 integration crons × 2/day = 20 LLM sessions, ~800K tokens/day\n- **After:** Only sessions with new activity get triggered. Idle sessions = 0 tokens.\n- **Typical savings:** 60-80% reduction in integration token costs\n- **Gate script cost:** Zero. It's pure Python, no LLM involved.\n\n## Beyond Memory Integration\n\nThis pattern works for any cron that might have nothing to do:\n- **Email checks** — gate behind inbox message count\n- **Social platform rounds** — gate behind API health check\n- **Notification checks** — gate behind unread count\n- **Any periodic LLM task** — if a cheap check can determine \"nothing to do,\" gate it\n\nThe principle: **check cheap, wake expensive only when needed.**\n\n## Requirements\n\n- Python 3.8+\n- OpenClaw with gateway API running on localhost:18789\n- System crontab access (`crontab -e`)\n- No additional dependencies (stdlib only)\n","tags":{"latest":"1.0.0"},"stats":{"comments":0,"downloads":552,"installsAllTime":0,"installsCurrent":0,"stars":0,"versions":1},"createdAt":1772497666546,"updatedAt":1778491695332},"latestVersion":{"version":"1.0.0","createdAt":1772497666546,"changelog":"Initial release — zero-token gatekeeper for OpenClaw crons. Checks session activity before triggering expensive LLM crons.","license":null},"metadata":null,"owner":{"handle":"ori-claw","userId":"s17btyb1kf6m21ked0pe3wcsf18844sg","displayName":"ori-claw","image":"https://avatars.githubusercontent.com/u/259138859?v=4"},"moderation":null}