Claude Code Works the Night Shift: An Overnight Cloud Setup That Lands Commits While You Sleep
The cost of running an AI agent unattended is mostly discipline, not infrastructure: an isolated branch, a standing policy file, deny rules, and machine-checkable completion criteria are what keep an overnight Claude Code run reviewable. The workflow plugs ApexOne as the cloud machine, but the pattern transfers to any always-on environment.
Claude Code is a terminal process, so overnight work constrains to two hard problems: session persistence and machine uptime. tmux solves the former, keeping a session alive through SSH drops and display disconnects. An always-on machine — a local Mac with caffeinate -i, a self-hosted VPS, or a pre-configured cloud dev machine like ApexOne — covers the latter. The pattern is machine-agnostic; the hard part is the policy layer.
That policy layer is where the actual design lives. CLAUDE.md gets a set of night rules: completion criteria (npm test passes, lint clean), a commit per subtask, a three-attempts-then-skip rule for stuck problems, and an explicit 'don't ask questions' directive. Task descriptions must say what done looks like, not just what to do; the agent will deliver on the bare wording. Permission mode auto lets routine operations run without prompts while a classifier blocks dangerous invocations, and `.claude/settings.json` adds deny rules for git push, rm -rf, and .env reads. Non-interactive `claude -p` with `--max-turns` makes the same pattern fully headless and cron-compatible.
A failure table catalogs what actually goes wrong overnight: usage-limit stops, context compression causing repeated work, stalls on a pending question, flaky tests, and overscoped tasks. Every fix is structural rather than prompt-based. Morning acceptance is git log, npm test, git diff, and reading NOTES.md, expecting that some overnight output needs rework or disposal.
The no-question rule is the load-bearing design decision: any agent question becomes a full stall when nobody is around, so the policy forces forward motion and pushes uncertainty into NOTES.md instead.
CLAUDE.md operates as a runtime policy file, not a memory aid — its real job is telling the agent how to behave under failure: when to retry, when to skip, what to record.
Completion criteria serve two purposes at once: they tell the agent when to stop and constrain it from touching business code. The definition of correctness here is purely mechanical (tests pass, lint clean), which is why the pattern only fits verifiable bulk tasks.
The machine comparison weighs setup time against control: your own computer shares data with the AI, a self-hosted VPS is full DIY, and a cloud dev machine buys zero-setup with isolation. The honest framing is that the cloud option only solves uptime, nothing else.
Context compression, stuck loops, and waiting on input all appear in the failure table, and every fix is a policy change. Operating rules around the agent matter more than how the prompt is phrased.