agent-tracking

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 · Updated 2026-11-25

Diesen Guide auf Deutsch lesen

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.

03:00 Day 1OK (42s)03:00 Day 2OK (45s)03:00 Day 3MISSED (no start)03:15 Day 3Alert fired
Dead-man's-switch with --every 24h: if a scheduled run never starts or hangs silently, the server raises an alert automatically.

Headless & cron failure checklist

Protect every unattended AI job against all five failure modes below:

Failure modeWhat happens silentlyHow to prevent & monitor
Permission wall hangHeadless CLI waits forever for Allow? promptSet explicit non-interactive permission scope + agenttracking guard --max-minutes 30
Missed / skipped scheduleCron daemon stopped, host rebooted, or lockfile stuckWrap with agenttracking wrap --every 24h so missing starts trigger alerts
Infinite tool retry loopFailing test or flaky API burns tokens for hoursEnable agenttracking guard --max-failures 5 --max-calls 80
Secret leak in error logsStderr dumps Authorization: Bearer ... into alert emailsUse --tail 20 — Agent Tracking automatically masks tokens, API keys & DB URLs locally
Silent regression in outputScript exits 0 even though the generated check failedRecord named assertions with wrap --check <name> --version <v>
Automatic secret masking

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