Short answer

Coding agents can run overnight usefully when the work is split into tasks of about an hour each, every task has criteria the system checks, the agent can't ask questions or touch production, and hard limits on rounds, time and money park anything that stalls. Without those, a night run mostly produces a long transcript and a bill.

The idea is obvious once you have it. You go to sleep at eleven, the agents work until seven, and in the morning there is a stack of finished, reviewed changes waiting for you. Eight hours a night is more than most teams get from a contractor in a day.

Most first attempts go differently. The agent stops after twenty minutes to ask a question nobody is awake to answer. Or it spends the night retrying the same failing test. Or it finishes something that looks done and isn’t, and the morning goes on figuring out what it actually did. Running agents overnight is not a prompt problem. It is a set of conditions that have to be true before you close the laptop.

Why overnight agent runs fail

An unattended run removes the one thing that quietly holds an interactive session together: you. In a normal session you answer questions, approve commands, notice when the agent is going in circles and say “that’s enough”. At night, every one of those moments becomes either a stall or a mistake.

So the failures sort into three groups. The agent waits for something that never comes (a question, a permission). The agent keeps going when it should stop (loops, runaway cost, a wrong plan pursued for hours). Or the agent stops when it shouldn’t, declaring a task done that isn’t. Each group has a fix, and none of the fixes is “use a smarter model”.

How long can an agent work without help

The honest answer comes from METR, which measures how long a task, in human working time, a model can complete with a given probability. The headline number has grown fast. The number that matters for a night shift is the second line on this chart.

How long a task the best model can finish

Human working time, at 50% and 80% success, log scale

  • 50% success
  • 80% success
0.1 min1 min10 min100 min1,000 minGPT-4, 2023o3, 2025Opus 4.6, 202650% success, GPT-4, 2023: 4 min50% success, Sonnet 3.5, 2024: 20.5 min50% success, Sonnet 3.7, 2025: 60.4 min50% success, o3, 2025: 119.7 min50% success, GPT-5, 2025: 203 min50% success, Opus 4.5, 2025: 293 min50% success, Opus 4.6, 2026: 718.8 min80% success, GPT-4, 2023: 0.9 min80% success, Sonnet 3.5, 2024: 2.6 min80% success, Sonnet 3.7, 2025: 12.1 min80% success, o3, 2025: 30 min80% success, GPT-5, 2025: 38.3 min80% success, Opus 4.5, 2025: 49.4 min80% success, Opus 4.6, 2026: 69.9 min50% success 718.8 min80% success 69.9 min0.1 min1 min10 min100 min1,000 minGPT-4, 2023Opus 4.6, 202650% success, GPT-4, 2023: 4 min50% success, Sonnet 3.5, 2024: 20.5 min50% success, Sonnet 3.7, 2025: 60.4 min50% success, o3, 2025: 119.7 min50% success, GPT-5, 2025: 203 min50% success, Opus 4.5, 2025: 293 min50% success, Opus 4.6, 2026: 718.8 min80% success, GPT-4, 2023: 0.9 min80% success, Sonnet 3.5, 2024: 2.6 min80% success, Sonnet 3.7, 2025: 12.1 min80% success, o3, 2025: 30 min80% success, GPT-5, 2025: 38.3 min80% success, Opus 4.5, 2025: 49.4 min80% success, Opus 4.6, 2026: 69.9 min718.8 min69.9 min
Source: METR time horizons, Horizon v1.1 data.
Data as a table
50% success80% success
GPT-4, 20234 min0.9 min
Sonnet 3.5, 202420.5 min2.6 min
Sonnet 3.7, 202560.4 min12.1 min
o3, 2025119.7 min30 min
GPT-5, 2025203 min38.3 min
Opus 4.5, 2025293 min49.4 min
Opus 4.6, 2026718.8 min69.9 min

At 50% success, the best model on that list handles tasks of about twelve hours. At 80% it is a little over an hour. METR also warns that its current task suite can’t measure reliably above sixteen hours, so the newest models’ top numbers are less certain.

For overnight work that gap is the whole story. One eight-hour task handed over at 11 p.m. is roughly a coin toss. Eight one-hour tasks, each checked and committed before the next starts, give you a high chance that most of them land, and the ones that fail fail early and on their own. The night is not one job. It is a queue.

What has to be true before you go to sleep

Here is the checklist I use. If any item is missing, I’d rather not start the run.

  1. The work is a queue of small tasks. Each one fits in about an hour of human-equivalent work and can be merged on its own. Big tickets get split during the day, while you are around to split them well.
  2. Every task has criteria the system can check. A command that exits 0 only when the task is done. See acceptance criteria an agent can’t talk its way around.
  3. Stopping is gated. The agent can’t end a task until the checks pass. In Claude Code a Stop hook does this, as I describe in why agents stop halfway.
  4. Nobody needs to answer anything. Questions and permission prompts are handled up front, or the run is configured so that they are denied rather than waited on.
  5. A reviewer that isn’t the writer. A second model, or a fresh context, reads each diff and the check output before it counts as done.
  6. The blast radius is small. A sandbox or container, a branch per task, no production credentials, no ability to push to main or deploy.
  7. Hard limits. Maximum rounds per task, wall-clock time per task, money per night, and a rule that two rounds without progress parks the task with a note.
  8. A morning report. Per task: done, parked, or failed, with the diff, the commands and their exit codes, and the cost.

Most of this is the same discipline you’d apply to any production agent. The night just removes your chance to compensate for missing pieces.

How to run Claude Code unattended

Claude Code’s non-interactive mode is the building block. claude -p "<prompt>" runs a single task and exits with code 0 on success and non-zero on failure, so a script can branch on the result. A few options matter for a night run:

  • --permission-mode auto has a classifier review actions instead of you. dontAsk is stricter: anything that would prompt is denied, and only what your allow rules cover runs.
  • --permission-prompts none is meant for exactly this situation, when nobody is available. Anything that would wait for a person is denied, Claude is told not to retry it, and tools like AskUserQuestion are removed so the agent can’t stall on a question.
  • --allowedTools with permission rules such as Bash(npm test *) lets you allow specific commands rather than the whole shell.
  • --max-budget-usd puts a ceiling on spend for the run.
  • --output-format json returns the result with the session ID and total_cost_usd, which is most of what a morning report needs.
  • --bare skips loading hooks, plugins and CLAUDE.md from the machine. That is good for reproducible CI, but if your Stop hook is the thing keeping the agent honest, don’t use bare mode, because hooks won’t run in it.

Two details from the docs are worth knowing before you write the wrapper. If you stop a run with SIGTERM, Claude Code exits with code 143 and records no result for the interrupted turn. And Stop hooks have a cap of eight consecutive continuations, after which Claude Code ends the turn anyway, so a hook alone is not your loop limit. Your wrapper should count rounds and time per task itself.

Anthropic’s own write-up on harnesses for long-running agents adds a pattern that suits nights well: each session starts by reading a progress file and the git log, checks that the app still runs, works on one feature, commits, and leaves the environment clean for the next session. A night of that is a night of small, recoverable steps.

One task in an overnight queue

  • Agent
  • Automated check
  • Person
Take nexttaskfrom aqueuewritten inthe dayAgentworksheadless,sandboxed,own branchCheckscriteriacommandsrun by thesystemReviewerdifferentmodelreads thediffCommit orparklimitsdecideMorningreportdiffs,exitcodes,costfindings go backnext taskTake next taskfrom a queue written in the dayAgent worksheadless, sandboxed, own branchCheckscriteria commands run by thesystemReviewerdifferent model reads the diffCommit or parklimits decideMorning reportdiffs, exit codes, cost
Illustrative diagram, not measured data.
Steps as text
StepWhat happens
1. Take next taskStep — from a queue written in the day
2. Agent worksAgent — headless, sandboxed, own branch
3. ChecksAutomated check — criteria commands run by the system
4. ReviewerAgent — different model reads the diff
5. Commit or parkStep — limits decide
6. Morning reportPerson — diffs, exit codes, cost
Loopfindings go back: back from step 4 to step 2
Loopnext task: back from step 5 to step 1

Bad and good ways to run agents overnight

Some setups look like overnight automation and aren’t.

The worst is one big prompt with “keep working until it’s done” and full permissions. It produces exactly one of three outcomes: an early stop, a long loop or a large diff nobody can review. The second worst is a cron job that runs an agent with no checks, so every morning starts with reading transcripts to find out what happened, which costs more time than the night saved.

The setup that works is boring. A queue prepared during the day. One task per agent run. Checks the system runs. A reviewer. Branches, not main. Limits that park rather than retry. And a short report, so the morning takes ten minutes, not two hours. Security deserves its own line here: OWASP lists prompt injection and excessive agency among the top risks for LLM applications, and an agent reading issue text at 3 a.m. with nobody watching is exactly where both matter. Keep the night shift away from secrets and production, and see guardrails for AI coding agents for the layers.

What a day looks like when agents work at night

Here is a model of one developer’s 24 hours with and without a night queue. The hours are illustrative, not measured, and they assume the queue is prepared during the day and the agents’ work is reviewed by a second model before a person sees it.

A developer's day with and without a night queue

Hours of work happening on the product, illustrative

  • Person working
  • Agents working
  • Nothing happening
Person onlyPerson only, Person working: 8 h8 hPerson only, Nothing happening: 16 h16 h24 hAgents in working hoursAgents in working hours, Person working: 8 h8 hAgents in working hours, Agents working: 6 h6 hAgents in working hours, Nothing happening: 10 h10 h24 hAgents day and nightAgents day and night, Person working: 8 h8 hAgents day and night, Agents working: 14 h14 hAgents day and night, Nothing happening: 2 h2 h24 hPerson onlyPerson only, Person working: 8 h8 hPerson only, Nothing happening: 16 h16 h24 hAgents in working hoursAgents in working hours, Person working: 8 h8 hAgents in working hours, Agents working: 6 h6 hAgents in working hours, Nothing happening: 10 h10 h24 hAgents day and nightAgents day and night, Person working: 8 h8 hAgents day and night, Agents working: 14 h14 hAgents day and night, Nothing happening: 2 h24 h
Model, not measured data. Assumes the person still works 8 hours, agents run while tasks are ready, and about 2 hours a night are lost to tasks parked for a person.
Data as a table
Person workingAgents workingNothing happening
Person only8 h0 h16 h
Agents in working hours8 h6 h10 h
Agents day and night8 h14 h2 h

The interesting change is not the agent hours. It is what the person’s eight hours become. Less implementation, more writing the next day’s queue: specs, criteria, splitting work into pieces an agent can finish reliably, and settling the questions the night parked. That is a different job, and I think it is a better one. A small team working this way gets most of a second shift without hiring one, and the limiting factor becomes how well they can say what they want.

Questions

Can I leave Claude Code running overnight?

Yes, with claude -p in a script, a permission mode such as auto or dontAsk, --permission-prompts none so nothing waits for an answer, a budget cap, and a Stop hook that blocks until your checks pass. Run it in a sandbox on a separate branch.

How long can an AI coding agent work on its own?

METR’s data shows the best current models complete about an hour of human work with 80% success and around twelve hours with 50% success. For unattended runs, plan around the 80% figure and split longer work into a queue.

How do I stop an overnight agent from running up a big bill?

Set a spend cap such as --max-budget-usd, limit rounds and wall-clock time per task in your wrapper, and park any task that makes no progress for two rounds instead of retrying it.

What should an overnight agent not be allowed to do?

It should not hold production credentials, push to main, deploy, or run destructive commands. Give it its own branch, a sandbox and only the tools each task needs.