How to Run Coding Agents Overnight
Published August 27, 2026 · by the AQ team
Running a coding agent overnight takes four things: a machine that stays awake after your laptop lid closes, an agent configured to proceed without permission prompts, guardrails enforced by infrastructure rather than by the prompt, and a morning review routine you actually follow. Get those four right and agents like Claude Code and Codex can grind through migrations and refactors while you sleep. Get any wrong and you wake up to a dead session, a stuck permission dialog, or a branch you cannot trust.
Why overnight runs are worth setting up
Long tasks (a dependency upgrade that touches 200 files, a test backfill, a framework migration) take agent-hours, and overnight hours are the ones you were not going to use anyway. Subscription plans for the major agent CLIs meter usage in rolling windows, so capacity that resets while you sleep is lost unless something is running. And overnight is naturally parallel: nobody is waiting on any single task.
Step 1: put the agent on a machine that stays awake
A laptop is the wrong machine for this. Sleep suspends every running process, and an agent mid-task does not resume gracefully hours later: shell commands time out, network calls fail, a multi-step plan dies partway through. Disabling sleep works until the battery dies or the OS updates itself at 3am. The two reliable homes for an overnight run are:
- A VM you control, with tmux. Start a named tmux session on a small Linux VM, launch the agent inside it, and detach; the session runs on with your laptop closed. Our guides to running Claude Code on a cloud VM and running Codex on a cloud VM walk this end to end.
- A vendor cloud sandbox. As of August 2026, Claude Code on the web runs sessions on Anthropic-managed VMs that persist after you close the browser, and Codex cloud runs each task in an OpenAI-managed sandboxed container preloaded with your repository. Zero setup, but the environment is ephemeral, vendor-defined, and outside your network. See background agents vs cloud agents for the landscape.
The VM route in one screen:
# On the VM, once per task: a session that outlives your connection
tmux new -s upgrade-deps
claude # or codex, or any terminal agent
# Detach with Ctrl-b then d. Close the laptop. In the morning:
ssh dev-box
tmux attach -t upgrade-deps
Step 2: configure the agent to proceed without you
An agent that stops to ask "may I run npm test?" at 11:40pm has ended its own shift. Every mainstream CLI can reduce or remove prompts; match the mode to the isolation you have.
For Claude Code, as of August 2026 the permission-modes documentation lays out the ladder. In non-interactive mode (claude -p) with --permission-mode dontAsk, only tools you pre-approved run at all, which Anthropic recommends for locked-down scripts:
claude -p "run the test suite and fix failures" --permission-mode dontAsk --allowedTools "Read" "Edit" "Bash(npm test)"
The fully unattended flag, --dangerously-skip-permissions, approves everything, and Anthropic's own guidance is to use it only inside a container or VM, as a non-root user. There is also an auto mode, where a classifier model reviews each action instead of you. Deny rules in settings files hold in every mode, including the bypass mode, which makes them the right place for hard lines like blocking pushes to main.
Codex has the same shape: codex exec runs a task headlessly (prompt in, result out, exit) with a sandbox whose network access is restricted by default, and Codex cloud tasks run with internet access off during the agent phase unless you enable it for the environment, as of August 2026.
Step 3: write the task like a night-shift handoff
Overnight prompts fail in predictable ways: vague scope, no definition of done, no instruction for what to do when blocked. Write the prompt the way you would brief a contractor who cannot call you:
- One task per session, scoped to what one focused engineer could finish in a night.
- A checkable definition of done: "all tests in packages/api pass, npm run typecheck is clean" beats "fix the tests".
- Commit etiquette: commit in small increments with real messages, on the task's own branch, and push before finishing so nothing lives only on the machine.
- A stop rule: if blocked or uncertain, write findings to a NOTES.md and stop, rather than improvising around the blocker.
If you run several tasks at once, give each its own git worktree so agents never trample each other's checkout, and be realistic about how many parallel agents one person can review.
Step 4: guardrails in infrastructure, not in the prompt
A prompt is a request, and a confused model or a hostile piece of text the agent read can route around it. The guardrails that hold at 3am are the ones no context window can bypass:
| Guardrail | How |
|---|---|
| The agent cannot touch main | Work on a dedicated branch; branch protection requires CI and a human approval to merge |
| Credentials are scoped | No production secrets on the machine; a git identity that can push branches but not force-push or delete |
| Blast radius is one checkout | Isolated worktree or VM per task; nothing shared with your daily environment |
| Network is bounded | Egress limited to what the task needs; both Anthropic and OpenAI restrict sandbox network access by default in their cloud offerings as of August 2026 |
| Spend is bounded | Plan usage windows, budget flags, or API spend caps so a looping agent costs a bounded amount |
Step 5: wire up a finish signal
You want to know at breakfast whether the run finished, stalled, or stopped early, without reading logs. Claude Code's hooks fire shell commands on lifecycle events: the Stop hook runs when the agent finishes responding, the Notification hook when it is waiting on input. Point either at a push-notification service and the run reports itself; our guide to getting notified when Claude Code finishes covers the options.
The morning review is the actual product
An overnight run produces a branch, not shipped code. The routine that keeps the practice trustworthy: read the diff commit by commit, run the tests yourself rather than trusting the agent's claim, check the definition of done against what actually changed, and skim the session for the decisions the diff does not show. The session review guide and our checklist for verifying agent work break this into a repeatable process.
Do not let the review collapse into a solo rubber stamp. A July 2026 LeadDev analysis of 25,264 agent-generated pull requests across 2,361 popular GitHub repositories found that in 79 percent of agentic PRs the same developer both reviewed and modified the agent's contribution, and only about one in eight workflows involved multiple humans. Overnight runs invite that failure mode: you briefed the agent, so you are the worst-placed person to notice what it misunderstood. A second human in the loop is what makes scaling up overnight agents safe rather than reckless.
Where AQ fits
AQ is the multiplayer coding harness where engineering teams run AI coding agents like Claude Code and Codex together: shared live terminals, a code editor, and app previews, in your own cloud. In this guide's terms, AQ is the VM-plus-tmux pattern with the overnight glue already built. Agents run as real CLIs (Claude Code, Codex, Cursor Agent, Kimi, Grok, or plain shells) in persistent tmux sessions on your team's VM, so a session started at 6pm is still running at 6am regardless of what your laptop did, and it streams live to the browser so you can check on it from any device, including your phone.
The setup steps above map to things AQ does by default. Each workspace gets its own isolated git worktree on a branch named ai/{id}-{slug} with dependencies installed automatically, so parallel overnight tasks never collide, and a one-click rebase brings a branch up to date with main in the morning. Agents commit and open PRs with per-user GitHub auth, and every PR is tracked on its workspace, so the morning starts from a list of what landed where. The read-through has a place to happen too: the session is still there in the workspace terminal, and teammates can open the same workspace and look at the same session, which is how a second human gets into the loop before merge. Each engineer signs into the CLIs with their own Claude or OpenAI account, and AQ never marks up model usage.
Two plans. Free is a personal sandbox for one person: AQ creates a private machine in an isolated network, nothing to install, no time limit, which is enough to try an overnight run tonight. Team is $50 per user per month in early access (standard $200, billed monthly), covering VMs you connect from your own cloud or a dedicated always-on AQ-managed VM in its own isolated network, rate locked for your first 12 months. If you are one engineer with tmux muscle memory, the manual pattern above is enough. AQ earns its keep when overnight runs stop being a personal experiment and become something a team does, watches, and reviews together.
Frequently asked questions
Is it safe to run Claude Code unattended overnight?
It can be, if the isolation matches the permission mode. As of August 2026, Anthropic's documentation is explicit: the fully unattended flag, --dangerously-skip-permissions, belongs only inside a container or VM, running as a non-root user. For a locked-down run, non-interactive mode with --permission-mode dontAsk executes only tools you pre-approved. Layer infrastructure guardrails on top: a dedicated branch, branch protection on main, scoped credentials, and bounded network egress.
Can I just leave my laptop open overnight instead of using a VM?
You can, but it is the least reliable option. Sleep suspends every running process, and preventing sleep for eight hours fights the operating system, the battery, and automatic updates. A small cloud VM with tmux costs a few dollars a month and removes the whole failure class: the session runs server-side and you reattach in the morning from any machine.
How do I know when an overnight agent run finishes or gets stuck?
Wire the agent to report itself. Claude Code hooks run shell commands on lifecycle events: the Stop hook fires when the agent finishes responding, and the Notification hook fires when it is waiting for input. Point either at a push notification and you learn at breakfast whether the run completed, stalled on a question, or stopped early, without reading logs first.
What should an overnight agent prompt include?
Four things: one scoped task per session, a checkable definition of done (name the exact commands that must pass), commit etiquette (small commits with real messages on the task's own branch, pushed before finishing), and a stop rule telling the agent to write up findings and halt when blocked instead of improvising around the blocker. Vague prompts produce the branches you distrust in the morning.
Can I run multiple coding agents overnight at once?
Yes, and overnight is the natural time for it, since nobody is waiting on any single task. The requirement is isolation: one git worktree or VM per task so agents never share a checkout, and separate branches so each result reviews independently. The practical ceiling is not compute, it is your morning: every branch still needs a real human review before it merges.