To run Claude Code overnight, give it small tasks with clear acceptance criteria, a permission setup that doesn’t need you, tests to check its own work, and a branch of its own. Then keep the computer awake and review the result in the morning. The hard part isn’t starting the run. It’s making sure the agent doesn’t sit for seven hours waiting for a yes, run out of quota at 2 a.m., or leave you a branch you can’t trust.
This guide covers each of those in order: planning, permissions, limits, guardrails, scheduling and the morning review. The last part shows how AgentVera’s night shift handles the same steps.
Plan the night before you start it
An agent at night can’t ask you anything. Everything it needs has to be in the task.
Write tasks the agent can finish alone
Good overnight tasks are small, clear and checkable:
- “Add input validation to the three forms in
src/settings/. Done whenpnpm testpasses and each form rejects an empty email.” - “Migrate
utils/date.tsfrom moment to date-fns. No behavior change. All existing tests must pass.” - “Write tests for
billing/invoice.tsuntil coverage of that file is above what it is now. Don’t change the source.”
Bad overnight tasks are vague or need a decision: “clean up the API”, “improve performance”, “pick a state library”. The agent will make a choice you’ll disagree with, or stop and wait.
Write the acceptance criteria
For each task, write down when it counts as done:
- Which tests or checks must pass.
- Which files it may touch, and which it must not.
- What to do if it gets stuck. For example: “If you can’t make it pass, commit what you have and write why in NOTES.md.”
Put the project rules where the agent reads them
Conventions, test commands and forbidden areas belong in CLAUDE.md so every session sees them. Keep it short. Overnight it is your only voice in the room.
Prefer several small tasks to one big one
Five independent tasks of an hour each give you five reviewable branches. One five-hour task gives you one large diff and one chance for it to go wrong.
Decide how permissions work while you sleep
In an interactive session, a permission prompt just waits. Overnight that means a whole night lost to a single question. Settle this before you go to bed.
For non-interactive runs (claude -p), the CLI reference gives you these options:
| Option | What it does |
|---|---|
--allowedTools "Bash(npm test)" "Read" "Edit" | These run without a prompt |
--permission-mode dontAsk | Only pre-approved tools run; anything else is denied |
--permission-mode auto | A classifier checks each action; blocked actions don’t run and Claude keeps going |
--permission-prompts none | Prompts are denied instead of waiting for an answer (v2.1.259 or later) |
--dangerously-skip-permissions | No prompts at all; only for isolated containers or VMs |
A practical default for overnight work is dontAsk with a tight allow list, plus a deny rule for git push. If you’re thinking about skipping permissions entirely, read what —dangerously-skip-permissions really skips first.
Put limits on the run
Two print-mode flags keep a run from going on forever:
--max-turns 40stops after that many agentic turns and exits with an error. There is no limit by default.--max-budget-usd 5.00stops once estimated API spend reaches that amount. It’s a client-side estimate and spend can go past it, so leave some headroom. It matters if you pay per API call, not on a subscription.
A full overnight command might look like this:
git worktree add ../night-validate-forms -b night/validate-forms
cd ../night-validate-forms
claude -p "$(cat tasks/validate-forms.md)" \
--permission-mode dontAsk \
--allowedTools "Read" "Edit" "Bash(pnpm test *)" "Bash(git add *)" "Bash(git commit *)" \
--max-turns 60 \
--output-format json > ../logs/validate-forms.json
The run happens in its own git worktree, so it never touches your working copy. For interactive sessions, claude -w <name> creates the worktree for you.
Plan around usage limits
On a subscription, Claude Code has a rolling 5-hour limit and a weekly limit. A long night can hit either one, and the run stops until the window resets. We cover the details in Claude Code usage limits.
A few habits help:
- Start heavy work early in the evening, so a reset can fall inside the night.
- Use a cheaper model for simple tasks such as tests, docs and renames.
- Keep context small. Short tasks and a lean CLAUDE.md burn fewer tokens. See Claude Code token usage.
- Don’t stack ten agents on one account and expect all of them to finish.
Use tests as guardrails
Without tests, “done” only means the agent stopped. With tests, you have something to check.
- Make tests part of the definition of done. “Done when
pnpm testandpnpm typecheckpass.” - Forbid editing tests to make them pass, unless that’s the task. Say so in the task and in CLAUDE.md.
- Commit after each passing step. Small commits are easy to review and easy to revert.
- Never push or deploy. Deny
git pushand anything that touches production. The morning is for deciding what ships.
Schedule the run
If you start runs by hand at midnight, you’ll stop doing it after a week. Two ways to schedule:
- cron or launchd. A crontab line such as
0 23 * * 1-5 /path/to/night.shstarts a script on weeknights. The script runs oneclaude -pper task file and writes the logs. - An orchestrator that keeps a queue, runs tasks in parallel, retries and writes a report. That’s what the rest of this post covers.
Either way, the machine must be on and not asleep. On a Mac, caffeinate or a keep-awake setting is enough.
Review in the morning
Plan 20 to 30 minutes for review:
- Read the summary first: what finished, what got stuck, what is still running.
- For each finished branch, read the diff, not just the agent’s message. Check the tests ran.
- Look for risky changes: migrations, auth, dependencies, CI config,
.env. - Merge what’s good, send back what isn’t, with a note, and requeue what got stuck with a clearer task.
How AgentVera’s night shift handles this
AgentVera puts these steps into one place. The night shift is on the Pro and Team plans.
A queue per project
Open a project’s Details page and go to the Night shift tab, or use the Night shift button on the home screen. Each project and each group has its own shift. You type a task under Add a task for tonight and press Add to queue. The placeholder sums up the rule: “Write the acceptance criteria; the agent can’t ask questions at night.”
For each task you choose who does it:
- An open agent. It works in its own folder and conversation, and isn’t closed afterwards. Tasks given to the same agent run in order.
- Open a new agent. A Claude Code or Codex agent in its own worktree, on a
night/<date>-<slug>branch. It closes when the task is done.
The options include Run each task in its own worktree and branch (recommended), Open a GitHub PR for finished tasks and As a draft PR.
The window and the rules
The default window is 23:00 to 07:00. With Start automatically every night, the shift starts on its own. At most at once sets how many tasks run in parallel: 2 by default, up to 6. You can also press Start now, or End the shift early. Ending it means nothing new starts, running agents finish, and the report is written.
Night shift agents follow fixed rules:
- They’re told you are asleep, so they don’t ask questions.
- They commit but don’t push.
- They run the tests.
- They end with a done or stuck marker. Without one, the agent is nudged up to twice, then the task is marked stuck.
- Requests that need approval aren’t approved overnight. They’re listed in the morning report.
Each task shows a status: Queued, Running, Done, Stuck, Error or Cancelled. A stuck task can be put back with Requeue.
To cut down on approvals that wait until morning, set the agent’s Permissions level to Auto. On Pro and Team you can also let auto approval answer safe requests such as reads, tests and lint.
Keep the machine awake
The night shift doesn’t run with the computer off. The app must be open and the computer awake. Turn on Keep the computer awake under Settings → Notifications. It works like caffeinate: the Mac won’t sleep while AgentVera is open, though the display can still turn off.
Scheduled tasks for recurring work
For jobs that repeat, such as a nightly dependency check or a weekly cleanup, use scheduled tasks. They live on the project Details page under Scheduled, and they’re on every plan.
- Pick a preset or write a cron expression. A preview shows the next runs.
- If the agent is busy when the time comes, choose to wait, send anyway or skip.
- The agent can be started if it’s stopped, and Run now fires a task immediately.
- Failed runs can be reported to Telegram.
Like the night shift, they run only while the app is open. Runs missed while the app was closed aren’t made up later.
When an account hits its limit
With account switching (Pro and Team), you set up a chain of at least two Claude or Codex accounts. When one has 3% or less left of its 5-hour or weekly limit, agents move to the next account, and the conversation can move with them. Expired logins are skipped. If you’ve set up a chain, an agent at its limit overnight keeps going on the next account instead of stopping. Check your provider’s terms before using several accounts.
Hear about problems, not everything
Telegram can send errors, approval requests, limit warnings, failed scheduled tasks and the night shift’s morning report. /night shows the queue, adds a task or starts the shift from your phone. See notifications and approvals for the full list.
The morning report and review inbox
When the shift ends, you get a desktop notification and a Markdown report saved on disk. Past reports are listed under Morning reports. The Telegram version carries counts only: done, PRs opened, stuck and still running.
Finished work also lands in the review inbox, a tab in the right panel that covers every agent and project. Each card shows:
- the changed files,
- risk notes for migrations, auth, dependencies, CI and
.env, - size notes, such as 800 or more lines changed, 300 or more deleted, or no tests,
- the Verify result and the agent’s last reply.
From each card you can Approve, Send to queue to put the branch in the merge queue, or Send back with a note for the agent.
Overnight checklist
- Each task is small, independent and has written acceptance criteria.
- CLAUDE.md lists the test commands and the files not to touch.
- Permissions are settled: allow list,
dontAskor auto, andgit pushdenied. - Each task runs on its own branch or worktree.
- Turn or budget limits are set for scripted runs.
- Heavy work fits your usage limits, or a second account is ready.
- The computer stays on and awake.
- You’ll hear about errors without being woken up for every turn.
- Review time is blocked out for the morning.
Wrapping up
Running Claude Code overnight works when the night is planned. That means small tasks with clear done conditions, permissions that don’t wait for you, tests that check the work, branches that keep main safe, and a morning review that decides what ships. You can do all of it with claude -p, cron and a few flags. AgentVera’s night shift puts the queue, the rules, the limits and the morning report in one place, so you can spend the morning reviewing instead of setting things up.
Read more:
To try AgentVera, start at the home page.