跪拜 Guibai
← All articles
Frontend · JavaScript · Programmers

Running Claude Code Overnight: tmux, Permission Modes, and a Cloud VM That Does the Setup

By ErpanOmer ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Running AI coding agents unattended overnight turns a prompt-by-prompt session into a batch job, but only if you handle process persistence, permission guardrails, and task framing. The permission and prompt-hygiene patterns here transfer to any CLI-based agent, not just Claude Code, and the decision to move to a preconfigured cloud VM reflects a real shift in how developers are buying compute for AI workloads.

Summary

Long Claude Code tasks die when your terminal session drops or your laptop sleeps. The fix is a two-part setup: tmux keeps the process alive outside the session, and the machine stays powered on. tmux lets you detach with `Ctrl+B D` and reattach later, and `tmux capture-pane` gives a quick progress read from a phone. For overnight runs, the default permission prompts will stall the job; starting with `--permission-mode auto` lets a classifier pass normal operations while blocking dangerous ones like force-pushes or piping downloaded scripts to bash. Project-level deny rules in `.claude/settings.json` ban `git push`, `rm -rf`, and reading `.env` as a final guard.

The quality of the output depends almost entirely on the task description written before bed. The article recommends creating a dedicated branch, writing project conventions into `CLAUDE.md` (test commands, commit-per-step, "don't ask, decide and record"), and phrasing the task as goal plus acceptance criteria. Two advanced moves: `claude -p` for fully unattended non-interactive runs with `--max-turns`, and a Stop hook that pings a webhook when the job finishes. On machine choice, the author switched from self-managed VPS to ApexOne, a cloud development VM that comes with Claude Code, Docker, and toolchains preinstalled, boots in two minutes, and auto-sleeps when idle. The guide closes with a checklist of failure modes (usage caps, context compression, clueless loops) and a morning acceptance sequence: `git log`, `npm test`, `git diff`, and reading `NOTES.md`.

Takeaways
— tmux detaches the Claude Code process from the SSH or terminal session so it survives disconnects; never use `exit` to leave, use `Ctrl+B D`.
— `tmux capture-pane -t work -p -S -50` prints recent output without attaching, so you can check progress from a phone.
— `--permission-mode auto` uses a classifier to allow normal operations (installs, tests, edits) and block dangerous ones (force-push, executing downloaded scripts); `--dangerously-skip-permissions` should only run on an isolated VM.
— Project `.claude/settings.json` can hard-deny `Bash(git push:*)`, `Bash(rm -rf:*)`, `Read(./.env)`, and `Read(./.env.*)` as a last line of defense.
— Write a pre-start git commit on a dedicated branch so you can roll back any damage.
— `CLAUDE.md` rules should include the exact test command, commit-per-step, and a policy to make a decision and record it in NOTES.md instead of asking.
— Task descriptions should be structured as goal plus acceptance criteria, so Claude knows when it is done.
— `claude -p` runs non-interactively, logs to a file, and `--max-turns` prevents infinite loops; it can be scheduled with cron.
— A Stop hook can curl a webhook URL to notify you when the task completes.
— Overnight runs commonly fail from usage caps (recover with `claude --continue`), context compression (use `/compact` and NOTES.md), or loops on a single test (set a 3-attempt limit and skip).
— Morning acceptance: check `git log`, run `npm test`, review `git diff main...branch`, and read `NOTES.md`; expect some output to be rework or discarded.
Conclusions

The 80% rule for task description is plausible because overnight AI delegation removes the feedback loop; whatever you write is the only correction mechanism available.

Permission modes and deny rules are what make unattended AI coding safe enough to try; without them, the default ask-on-every-action behavior stalls the job, and the all-access mode gives the model your whole machine.

The move to a preconfigured cloud VM with auto-sleep reflects a growing pattern: developers are paying for short-lived, disposable environments rather than maintaining always-on VPSes, because most overnight tasks are bursty, not continuous.

The article's advice to let the agent decide and record rather than ask is a direct acknowledgement that a human-in-the-loop model doesn't scale to unattended runs; you trade perfect decisions for a reviewable audit trail.

Concepts & terms
tmux
A terminal multiplexer that runs persistent sessions independent of the shell that spawned them. Detaching with `Ctrl+B D` leaves processes running, so they survive SSH drops or a closed laptop.
permission-mode auto
A Claude Code startup flag that uses a built-in classifier to automatically allow routine operations (edits, test runs, installs) and block dangerous ones (force-pushes, executing untrusted scripts), removing the need to answer interactive prompts.
Claude Code hooks
User-defined commands that execute on specific lifecycle events, such as when the agent stops. A Stop hook can fire a curl request to a webhook, sending a notification when an unattended task finishes.
From the discussion
Featured comments
咬代码的兽

tmux keep-alive plus clear acceptance criteria is indeed key. If the permission whitelist is not tightened, running overnight is risky. Thanks for sharing the pitfalls. I usually browse practical articles on this kind of AI programming tools on ai345 by category, and the updates are quite fast.

ErpanOmer

❤️

See top comments, translated →
Source: juejin.cn ↗ Google Translate ↗ Backup ↗