Agent Guardrails & Monitoring · Guide
How do I safely monitor Claude Code cron jobs and overnight headless agents?
Running `claude -p` or automated AI scripts from crontab or GitHub Actions fails silently in three ways: interactive permission walls hang the process forever, zombie processes trigger skip-cascades on the next tick, and standard cron never alerts when a job fails to start. Wrapping each job with `agenttracking wrap --every` plus a local guard fuse gives you dead-man's-switch alerts, masked stderr tails, and hard loop protection.
By Gorden Wübbe · Updated 2026-11-25
Why standard crontab fails for AI coding jobs
Classic cron was designed for deterministic 5-second shell scripts that exit 0 or 1. When you schedule a headless Claude Code triage job, automated dependency updater, or nightly report generator, you inherit both Unix cron failure modes and LLM agent failure modes.
If cron daemon restarts, permissions break, or a previous zombie run holds a lockfile, your scheduled agent simply never runs—and cron sends zero email because nothing exited with an error.
Headless & cron failure checklist
Protect every unattended AI job against all five failure modes below:
| Failure mode | What happens silently | How to prevent & monitor |
|---|---|---|
| Permission wall hang | Headless CLI waits forever for Allow? prompt | Set explicit non-interactive permission scope + agenttracking guard --max-minutes 30 |
| Missed / skipped schedule | Cron daemon stopped, host rebooted, or lockfile stuck | Wrap with agenttracking wrap --every 24h so missing starts trigger alerts |
| Infinite tool retry loop | Failing test or flaky API burns tokens for hours | Enable agenttracking guard --max-failures 5 --max-calls 80 |
| Secret leak in error logs | Stderr dumps Authorization: Bearer ... into alert emails | Use --tail 20 — Agent Tracking automatically masks tokens, API keys & DB URLs locally |
| Silent regression in output | Script exits 0 even though the generated check failed | Record named assertions with wrap --check <name> --version <v> |
When you pass --tail 20 to agenttracking wrap, the CLI masks Bearer tokens, GitHub/Anthropic/OpenAI/Stripe/AWS/Slack/Telegram keys, database URIs, and SSH headers locally before sending the last 20 lines of stderr.
Discover unwrapped crons and wrap them safely
agenttracking doctor parses your local crontab -l offline (never sending raw commands) and prints exact wrap suggestions with inferred --every intervals. wrap preserves your command's stdout, stderr, and exit code 1:1:
# 1. Inspect existing crontab locally (zero network calls) agenttracking doctor # 2. Before (blind cron — silent if it hangs or never starts): # 0 3 * * * /opt/agents/nightly-triage.sh # 3. After (missed-run watchdog + duration + masked stderr tail): 0 3 * * * agenttracking wrap --name nightly-triage --every 24h --tail 20 -- /opt/agents/nightly-triage.sh # 4. Works identically in GitHub Actions or systemd timers: agenttracking wrap --name ci-review --kind codex --tail 20 -- ./scripts/run-review.sh
One morning briefing instead of 40 noisy cron mails
Healthy jobs stay quiet all night and roll up into a single daily briefing at the hour and IANA time zone you pick. Only real failures, suspected hangs, runaway loops, or missed schedules fire immediate Telegram, Slack, Discord, or email alerts.
Frequently asked questions
Does `agenttracking wrap` change my script's exit code or stdout?
No. wrap streams stdout and stderr untouched and exits with the exact exit code of the wrapped command so pipes, systemd, and CI runners behave identically.
What happens if agenttracking.co is temporarily unreachable when my cron runs?
Your cron job still executes normally without delay. Telemetry events spool locally and flush on the next run; hooks and wrappers never break production scripts.
Can I use `wrap` with GitHub Actions, Codex CLI, or Python agent scripts?
Yes. Pass --kind cron, --kind codex, --kind agy, or --kind custom to wrap any CLI command or CI step.
How many cron jobs can I monitor for free?
Up to 5 agents/cron jobs are free forever—including Telegram, Slack, Discord, webhook, and email alerts plus the daily morning briefing.
Primary sources & documentation
Read next & try live
How do I stop Claude Code runaway costs and infinite retry loops?How do Claude Code hooks work for alerts, stuck sessions and guardrails?How do I monitor Claude Code and AI coding agents for stuck or waiting sessions?Try interactive fleet demo (no login) →Start free (incl. Telegram/Slack) →