Claude Code Headless Mode and Cron: Nightly Jobs on a VPS
claude -p "<prompt>" runs Claude Code without the interactive UI: it does the task, prints the result and exits. Put that command in a shell script, call the script from cron on a small Linux server, and you have an agent that works overnight. The safe version adds four things: a long-lived token in a chmod 600 file, --permission-mode dontAsk with a short allow list, --max-budget-usd and --max-turns caps, and --output-format json so every run leaves a log with its estimated cost. For web pages that block plain fetches, connect the Apify MCP server with an API token.
Most Claude Code guides stop at the interactive terminal. This one is about the jobs you want done before you sit down: a digest of what changed in the tools you depend on, a refreshed dataset, a report waiting in a folder. The example job below was run for real on 2026-10-21, and the flags, costs and failure modes in this post come from that run and from Anthropic's Claude Code documentation.










