Claude Code Works the Night Shift: An Overnight Cloud Setup That Lands Commits While You Sleep
The project has a pile of unit tests owed. This kind of work has a few characteristics: clear goals, automatically verifiable, large volume but not difficult. That makes it exactly the type suited for Claude Code. The problem is it runs for hours, and no one can keep watch the whole time.
Here's the workflow I now use: ten minutes of setup before bed, the machine runs on its own, twenty minutes of review in the morning. No manual intervention in between.
一、First, think clearly about what needs solving
Claude Code is essentially a terminal process. To keep it working while you sleep, there are two hard constraints:
- The session can't be interrupted: closing the terminal window or an SSH drop kills the process
- The machine can't sleep: closing the laptop lid halts everything
The first is solved with tmux, the second requires a machine that stays on. The rest is configuration.
二、Ten minutes before bed: write the task so it's verifiable
During the day, if it goes off track you can pull it back anytime. At night, it can only follow what you've written. So the quality of the task description directly determines whether you wake up to a pile of usable commits or half an hour of garbage.
1. Create a branch, save a snapshot
git checkout -b night/add-tests
git add -A && git commit -m "chore: snapshot before overnight task"
The branch is insurance. If it breaks, git checkout main gets you back.
2. Write hard rules in CLAUDE.md
CLAUDE.md sits at the project root, and Claude Code reads it on every startup. For overnight tasks I always add these rules:
## Overnight task rules
- Completion criteria: npm test all pass, npm run lint no errors
- Commit after each subtask, commit message explains the change
- When uncertain, choose the simplest, most conventional approach and write the reasoning in NOTES.md
- If the same problem fails 3 attempts, write it in NOTES.md under "Pending" and move on
- Don't stop to ask questions
The last rule is key. No one is there to answer at night; a single question stalls the entire task until sunrise.
3. The task description should state "what done looks like"
Add unit tests for all modules in src/services that don't have tests.
Completion criteria:
1. Cover normal and error branches of every exported function
2. npm test all pass
3. Don't modify business code; if you find a bug in business code, note it in NOTES.md, don't fix it directly
Finally summarize in NOTES.md: which tests were added, which suspicious points were found
"Add tests" is too vague; it could deliver with just two. Give completion criteria so it knows when to stop.
三、Permissions: neither interrupted nor out of control
Claude Code by default asks about every risky operation. During the day that's good; at night it's a disaster. You wake up to find it stopped at "Allow npm install to run?" and the whole night accomplished nothing.
The three modes:
claude --permission-mode acceptEdits # file edits don't ask, executing commands still asks
claude --permission-mode auto # classifier gates: routine pass-through, dangerous blocked
claude --permission-mode bypassPermissions # everything allowed, only for isolated environments
For overnight I use auto. Installing dependencies, running tests, editing files all complete on their own; forced pushes, piping downloaded scripts straight to bash, and similar actions get blocked.
bypassPermissions is only recommended in an isolated container or VM. On a machine holding all your code and keys, it's like removing the fuse.
Add a layer of deny rules as backup, written in .claude/settings.json:
{
"permissions": {
"allow": ["Bash(npm test:*)", "Bash(npm run lint:*)", "Bash(git add:*)", "Bash(git commit:*)"],
"deny": ["Bash(git push:*)", "Bash(rm -rf:*)", "Read(./.env)", "Read(./.env.*)"]
}
}
The idea is simple: whitelist what you want it to do on its own, blacklist what has irreversible consequences. All changes stay on the local branch, reviewed in the morning.
四、tmux: why not just use nohup
Start a session:
tmux new -s night
cd ~/your-project
claude --permission-mode auto
After delegating the task, press Ctrl+B then D to detach, then close the laptop and sleep. The next day:
tmux attach -t night
Common pitfalls:
- Detach with
Ctrl+B D, notexit, which kills the session along with Claude - To peek at progress without entering the session:
tmux capture-pane -t night -p -S -50, most convenient over SSH from a phone - Don't substitute
nohup claude &for tmux. The interactive interface needs a real TTY; in the background it quits easily because it can't get input
五、Fully unattended: claude -p
When the task description is complete enough that no mid-way interaction is needed, use non-interactive mode:
claude -p "Complete the task per TASK.md, commit after tests all pass" \
--permission-mode auto --max-turns 80 > night.log 2>&1 &
It runs until done and exits, with the process logged to night.log. --max-turns is a safety valve against infinite loops on the same problem. Combined with cron it can run on a fixed schedule daily.
For this kind of work that needs no attention, I basically throw it on ApexOne, keeping only a local terminal to watch night.log.
To get a notification in the morning, use a Stop Hook:
{
"hooks": {
"Stop": [
{ "hooks": [ { "type": "command", "command": "curl -s -X POST https://your-bot-webhook -d 'overnight task done'" } ] }
]
}
}
Point it at a WeCom, Feishu, or DingTalk group robot webhook, and you wake to a message saying "done at X o'clock".
六、Choosing the machine
This section is really one sentence: you need a machine that stays on all night and doesn't touch your local files.
| Your own computer | Self-hosted VPS | Cloud dev machine | |
|---|---|---|---|
| Preparation | Basically none | Install OS, Node, Claude Code, Docker | Mostly pre-installed, ready on boot |
| Lid close / network loss | No, needs constant power and sleep prevention | Yes | Yes |
| Isolation from local files | Not isolated | Isolated | Isolated (separate VM) |
| Suitable for | Occasional overnight runs | Long-running services, DIY enjoyment | Not wanting to spend time configuring |
- Your own computer: lowest barrier. On Mac use
caffeinate -ior disable sleep on power in system settings. Cost: AI and all your data on the same machine, so the permission configuration above is essential. - Self-hosted VPS: the most common approach. Start at 2 cores 4GB, fast enough for dependency installation and tests.
- Cloud dev machine: essentially a pre-configured Ubuntu VM with root, Node, Python, Docker, git, tmux all present, bootable in minutes, web terminal even without SSH. I currently use a cloud dev machine called ApexOne (apex1.us) with Claude Code and Codex pre-installed. It boots and runs immediately; it auto-sleeps when idle and wakes when a connection comes in. It still only solves the "machine must stay on" problem, no other magic.
Fundamentally, ApexOne-type cloud dev machines solve one thing: give Claude Code a machine that's on all night, fully equipped, and isolated from your local machine. Claude Code and Codex are pre-installed, so you don't need to configure Node, Docker, and the whole toolchain for a single overnight task.
The three options have no superiority ranking; it's about how much time you're willing to spend "configuring the environment."
七、Failure log
| Symptom | Cause | Handling |
|---|---|---|
| Stops in the middle of the night, shows usage limit reached | Subscription has time-window limits | After quota resets, claude --continue; don't give too much in one task |
| In the later night starts repeating already-done work | Context too long, early details compressed | Have it write progress into NOTES.md, /compact then continue per NOTES.md |
| Nothing happened all night | It's waiting for you to answer | Write "don't ask questions" into CLAUDE.md |
| Stuck on one test | Flaky test, or problem too hard | Rule: skip after 3 failed attempts and record |
| Too many changes to review in the morning | Task too large at once | One goal per night, require commits at each step |
八、Twenty minutes of review in the morning
git log --oneline night/add-tests # what did it commit last night
npm test # did the tests really all pass
git diff main...night/add-tests # look at the actual changes
cat NOTES.md # its summary and uncertain points
Set expectations: overnight output won't all be usable; some will need rework or be discarded. The good news is it runs on a separate branch with a commit at each step, so you pick the usable ones and merge.
九、Checklist
- A machine that can stay online all night, with tmux and Claude Code installed
- Create branch, commit snapshot
-
.claude/settings.jsonwith deny rules -
CLAUDE.mdwith overnight rules (completion criteria, commit each step, don't ask questions) - Task description with clear completion criteria
-
tmux new -s night+--permission-mode autoto start - (Optional) Stop Hook notification configured
-
Ctrl+B D, go to sleep
The applicability boundary of this workflow is also clear: tasks that can be auto-verified, a single controllable goal, results within one night. Conversely, work that needs frequent judgment calls, or requires coordination across multiple repos, is more trouble than it's worth.
Environment for this article
- Machine: ApexOne cloud dev machine (apex1.us), Ubuntu, 2 cores 4GB
- Tools: Claude Code, tmux, git
- Task: add unit tests to a TypeScript project