AI agents overnight workflow: queue tasks at night, review at breakfast

AI agents overnight workflow: queue tasks at night, review at breakfast

An overnight AI agent workflow means you queue well-scoped coding tasks in the evening, let agents run them unattended on a machine that stays on, and review the resulting pull requests in the morning. This guide covers where to run the agents, which tasks are worth queuing, how to write them, the commands to run them, and a short morning review routine.

In shortTL;DR
  • Overnight agents need a machine that stays awake: a cloud session, a scheduled cloud task, a VPS or a hosted box, not a sleeping laptop.
  • Queue tasks with a clear definition of done and a test the agent can run; vague tasks come back as vague diffs.
  • Give each task its own branch or git worktree so parallel agents never edit the same files.
  • Run unattended agents with an explicit tool allowlist and turn limits, and never with production credentials.
  • Spend 15 minutes each morning triaging pull requests: merge, send back with one instruction, or close.

What is an AI agents overnight workflow?

An AI agents overnight workflow turns the hours you sleep into working hours for coding agents: you queue tasks in the evening, agents run them unattended, and you review pull requests in the morning. It works when three things are true: the agents run somewhere that stays on, each task can be finished without you, and you review the output before it ships.

The routine has three parts:

PartWhenTimeOutput
QueueEvening15 to 30 minutesWritten tasks, one per branch
RunOvernightHours, unattendedCommits, test results, pull requests
ReviewMorning15 minutesMerged, sent back or closed

The value is not that agents work while you sleep; it is that your daytime attention goes to decisions and review instead of typing. A team that does this well wakes up to small, tested pull requests that need ten minutes each, not a pile of half-finished experiments.

Where should overnight agents run?

Run overnight agents on a machine that never sleeps: a cloud session, a cloud scheduled task, a VPS or a hosted box. A laptop with the lid closed stops the agent, and a laptop kept awake in a bag is a poor server.

OptionSurvives a closed laptopSetupBest for
Laptop kept awakeOnly while awake and plugged inNoneOne-off long tasks at your desk
Claude Code cloud sessionsYesConnect GitHub, set up an environmentAd hoc tasks on GitHub repos
Cloud scheduled tasksYesWrite the task once, add triggersRecurring nightly jobs
VPS with tmux or headless runsYesServer admin, security, updatesFull control, any agent
Hosted always-on boxYesSubscriptionPersistent setup without admin

Claude Code's cloud scheduled tasks (formerly routines) are built for the recurring case. A task is a saved prompt plus repositories and connectors, with triggers: a schedule (hourly, nightly, weekly or once), an API call, or a GitHub event. They run on Anthropic-managed infrastructure, are available on Pro, Max, Team and Enterprise plans, and are created at claude.ai/code/routines or with /schedule in the CLI. The minimum interval is one hour, and runs push to claude/-prefixed branches unless your prompt says otherwise.

For a deeper comparison of the always-on options, see how to run Claude Code 24/7.

Which tasks are good for overnight runs?

Good overnight tasks are well defined, verifiable by tests or a build, and low risk if they come back wrong. If you cannot describe "done" in two sentences, the task is not ready for an unattended run.

Good overnight tasksKeep for the daytime
Fix a reproducible bug with a failing test"Make the app faster"
Add tests for an untested moduleRedesign a core data model
Upgrade a dependency and fix breakagesMigrations on production data
Implement a small feature with a clear specFeatures with open product questions
Clear lint or type errors across a folderSecurity-sensitive auth or payment changes
Write or update docs from codeAnything needing production credentials
Triage and label new issuesLarge refactors without test coverage

A useful filter: would you hand this task to a capable contractor who cannot reach you until morning? If yes, it is an overnight task.

How do you write a task that finishes unattended?

State the goal, the context, the definition of done, how to verify it, and where to stop. An unattended agent cannot ask you what you meant, so the task text has to answer the questions it would ask.

overnight task template
Goal: [one sentence, the outcome you want]Context:- Relevant files: [paths]- Related issue or error: [link or pasted text]- Constraints: [libraries to use or avoid, style rules]Done when:- [observable result, e.g. "the failing test in auth.test.ts passes"]- npm run lint and npm test pass- A pull request is open with a summary of what changed and whyStop and leave a note in the PR description instead of guessing if:- The fix needs a database schema change- You need to change more than [N] files- Tests fail for reasons unrelated to this task

The "stop" section matters as much as the goal. Without it, an agent that hits an unexpected problem will try to solve it, and you wake up to a sprawling change in code you did not ask it to touch. Our guide to writing tasks for AI coding agents has more templates and examples.

The evening routine: queue the work

Spend 15 to 30 minutes turning your backlog into two or three ready tasks, each on its own branch. This is the part that decides how good the morning is.

  1. Pick the tasks. Choose two or three items from the "good overnight tasks" column. Start small until your review routine is solid.
  2. Write each task with the template above. Paste error messages and file paths instead of describing them.
  3. Check the environment. The agent must be able to install dependencies and run tests. A task that cannot run npm test cannot verify itself.
  4. Isolate each task. One branch per task, and if tasks run in parallel on one machine, one git worktree per task. Our guide to git worktrees for AI agents covers the setup and cleanup.
  5. Set the limits. Decide the model, the permission mode, the tools the agent may use, and a turn limit.
  6. Start the runs and confirm each one has begun before you close the laptop.

How do you run the tasks?

Use cloud sessions or scheduled tasks if your code is on GitHub and you want no server, or headless claude -p runs on a machine you control.

On an always-on Linux server, a short script can work through a queue file, one worktree per task. It uses documented flags from the headless docs and CLI reference: -p for non-interactive runs, --permission-mode dontAsk so anything not pre-approved is denied instead of waiting for you, --allowedTools for the allowlist, --max-turns as a stop, and --output-format json for a log you can read in the morning.

run-overnight.sh
#!/usr/bin/env bashset -euo pipefailcd ~/code/my-appgit fetch originmkdir -p ../logswhile IFS='|' read -r slug taskfile; do  [ -z "$slug" ] && continue  git worktree add "../wt-$slug" -b "agent/$slug" origin/main  (    cd "../wt-$slug"    npm ci    claude -p "$(cat "$taskfile")" \      --permission-mode dontAsk \      --allowedTools "Read" "Edit" "Write" "Bash(npm test *)" \        "Bash(npm run lint)" "Bash(git add *)" "Bash(git commit *)" \        "Bash(git push origin agent/*)" "Bash(gh pr create *)" \      --max-turns 100 \      --output-format json > "../logs/$slug.json"  ) || echo "$slug failed, see logs" >> ../logs/failures.txtdone < tasks.txt

Each line of tasks.txt looks like fix-login-redirect|tasks/fix-login-redirect.md. Run the script inside tmux so it survives your SSH session ending. The JSON output includes cost fields, which makes the morning check faster.

For recurring work, such as a nightly dependency check or issue triage, a cloud scheduled task is simpler: write the prompt once, add a nightly schedule trigger, and remove any connectors the task does not need. Anthropic's docs note that scheduled tasks draw down your subscription usage like interactive sessions, and each trigger type has its own hourly limit.

Warning

--dangerously-skip-permissions removes every check. Anthropic's permission docs restrict it to containers and VMs; use an allowlist instead, and never put production credentials on the machine.

The morning review: 15 minutes, three outcomes

Triage every pull request into merge, send back, or close, and do it before your first meeting. The review is where the overnight workflow pays off or falls apart.

  1. Scan the summaries. Read each PR description and the agent's notes. Anything flagged "stopped because" goes straight to the send-back pile.
  2. Check CI. Red builds are send-backs, with the failure pasted in.
  3. Read the diff. For small, green PRs, read every line. Look for changes outside the task's scope, weakened tests and new dependencies.
  4. Decide. Merge if you would have accepted it from a teammate. Send back with one specific instruction ("keep the API shape, fix only the null check"). Close if the approach is wrong, and rewrite the task for tonight.
  5. Check the cost. Glance at /usage or your logs and note any task that used far more than expected.
  6. Refill tonight's queue while the context is fresh.

You can do most of this from a phone: PR descriptions, CI status and small diffs read fine on a small screen, and you can send a follow-up instruction to the agent. Our guide on using Claude Code from your phone covers the setups. For tips on reviewing agent-written code efficiently, see AI code review.

Guardrails for safety and cost

Unattended agents need limits you set in advance, because nobody is there to press Escape.

  • Isolation: run on a separate machine or container, never the laptop with your SSH keys, browser sessions and password manager.
  • Least privilege: a GitHub token that can push branches and open PRs, with branch protection on main so the agent cannot merge.
  • Allowlists over bypass: pre-approve the commands each task needs and deny the rest.
  • Stops: --max-turns per task, and on API billing --max-budget-usd, which stops a headless run when estimated spend reaches your cap.
  • Right-sized models: routine tasks on a cheaper model; save the strongest models for tasks that justify them.
  • No loops on long contexts: recurring checks belong in scheduled tasks with fresh sessions, not in a session that has been open all day.

Where a hosted box fits

A hosted box gives you a VPS-style persistent machine for agents without the server admin. It suits people who want overnight runs on their own setup (installed tools, cloned repos, project config) but do not want to patch and secure a server.

Orkio rents an isolated, always-on cloud box where Claude Code and Codex keep working after you close the app; agents run on your own Claude account with no markup on model usage. You queue tasks from your phone or the web in the evening and review the pull requests in the morning, and Insights shows what each project and merged pull request cost. The Starter box is $19 a month.

Start tonight

You can run your first overnight task today with whatever setup you already have.

  • Pick one bug with a reproducible failing test.
  • Write it with the template: goal, context, done when, stop if.
  • Choose where it runs: a cloud session, a scheduled task, or tmux on a server.
  • Give it its own branch and a tool allowlist.
  • Start it, confirm it is running, and close the laptop.
  • Tomorrow, spend 15 minutes on review and write down what the agent needed that the task did not say.

After a week of this, you will know which kinds of tasks your agents finish reliably, and the queue will start to fill itself. For a wider look at the tools in this space, see our guide to background coding agents.

Frequently asked questions

Can Claude Code run overnight while my laptop is closed?

Not on the laptop itself, because Claude Code stops when the machine sleeps. Run it in a cloud session, as a cloud scheduled task, or on an always-on server such as a VPS or hosted box, and review the results in the morning.

How many tasks should I queue for one night?

Start with two or three tasks you would be happy to review in 15 minutes. Add more only once your morning review keeps up, because unreviewed pull requests pile up faster than agents produce them.

What tasks are bad for overnight agents?

Anything that needs product decisions, access to production, or judgment you cannot write down: redesigns, data migrations on live systems, security-sensitive changes and vague requests such as improving performance in general. Keep those for daytime sessions.

How do I stop an overnight agent from using all my usage limits?

Give each task a narrow scope, use a cheaper model for routine work, cap agentic turns with a flag such as max-turns in headless runs, and avoid long-running loops. Check your usage screen each morning and adjust the next night's queue.

Do scheduled cloud tasks count against my Claude plan?

Yes. Anthropic's docs say cloud scheduled tasks draw down subscription usage the same way interactive sessions do, and each way of starting a run also has its own hourly limit.

SOURCES

  1. Claude Code docs: Automate work with scheduled tasks
  2. Claude Code docs: Run Claude Code programmatically (headless)
  3. Claude Code docs: Choose a permission mode
  4. Claude Code docs: CLI reference
  5. Claude Code docs: Use Claude Code in the cloud
  • #ai agents
  • #claude code
  • #automation
  • #workflow
Orkio team

The team building Orkio. We write about putting AI to work: coding agents that run overnight, always-on boxes and pull requests ready by morning.

Keep reading

All posts

07:06 · YOU MERGED #128

Go to sleep. Wake up to pull requests.

Start for $19 a month
© 2026 Orkio · Hosted in Europe TürkçeStatus