To run AI agents overnight on a Mac mini or an old MacBook, you need a machine that does not sleep, a way to start the work unattended, and a way to check the result in the morning. On a Mac that stays plugged in, the DIY version is pmset to disable sleep, tmux or launchd to keep the agent alive, claude -p to run it without a prompt, and Tailscale to reach it. If you would rather not touch a terminal, link the spare Mac to an agent workspace like Universe and put the long-running and scheduled work on it.
This guide covers both routes, and what actually goes wrong at 3am, which the terminal recipes mostly skip.
Why can't my laptop just run the agent overnight?#
Your laptop is the worst machine for the job, for three reasons that have nothing to do with the agent.
- It sleeps when you close the lid. A MacBook stays awake with the lid shut only in closed-display mode, which needs the Mac on power with an external display and an external keyboard or mouse attached. In a bag on the way home it is asleep, and so is your agent.
- It goes where you go. Wi-Fi drops, the charger stays at the office, the battery runs flat at 2am.
- It restarts for updates. A macOS update that restarts overnight ends every terminal session, and nothing brings them back.
Even the vendors say so. As of September 2026, Anthropic's documentation for Claude Code Desktop's local scheduled tasks says they "only fire while the app is open and your computer is awake." A run the computer sleeps through is skipped, with one catch-up run on wake, and a "Keep computer awake" setting prevents idle sleep, but "closing the laptop lid still puts it to sleep." Its cloud routines (a research preview) keep running with your computer off, but they work on a fresh clone of a repository, can be scheduled no more often than hourly, and cannot see files on your Mac.
So "always-on" really means four things: a machine that does not sleep, a process that survives a disconnect or reboot, credentials that are there at 3am, and a way to see what happened.
Mac mini or an old MacBook: which should host the agent?#
Both work. An agent like Claude Code or Codex does its thinking on the model provider's servers, so the host mostly runs a CLI, reads and writes files, and waits. You do not need a powerful machine unless the agent also builds apps, runs test suites or renders video.
| Base Mac mini | Old MacBook you already own | |
|---|---|---|
| Cost to start | Buying one | Nothing |
| Power at rest | Apple lists 4W idle for the 2024 M4 model | Depends on the model; Intel laptops draw more than Apple silicon |
| Sleep behaviour | A desktop: turn off sleep and it stays up | Needs the lid open, or closed-display mode with a display and keyboard |
| After a power cut | Can restart itself automatically | Runs on battery until it can't |
| Risks | Few | Battery ageing from being plugged in all year; check health in System Settings > Battery |
| Best for | A permanent box under the desk | Trying the idea before spending money |
The electricity is cheap. At 4W all year a Mac mini uses about 35 kWh, around $6 at 17 cents per kWh. Even an average of 20W is about 175 kWh, roughly $30. Plug in your own rate.
Two things to check on an older Mac: it must run a macOS version your tools support (Universe needs macOS 13 or later, on Apple silicon or Intel), and it should have a reliable network connection. Ethernet beats Wi-Fi for a box nobody looks at.
How to run AI agents overnight on a Mac mini yourself: pmset, tmux, launchd and headless Claude Code#
This is the recipe most guides give, trimmed to what matters. It is a good choice if you live in a terminal.
1. Stop the Mac sleeping#
On a Mac mini, turn off sleep on power and let it recover from a power cut:
sudo pmset -c sleep 0 disksleep 0 # never sleep on AC power
sudo pmset -a autorestart 1 # restart after a power failure (desktops)
sudo pmset -a womp 1 # wake for network access
pmset -g # check what is actually set
caffeinate works when you only need it for one job: caffeinate -s blocks system sleep while the Mac is on AC power, and caffeinate -i <command> holds the Mac awake until that command exits. Neither stops a MacBook sleeping when you shut the lid. There is an undocumented pmset disablesleep 1 that does, but it also keeps a laptop awake in a closed bag, so don't use it on a machine that travels.
2. Keep the agent alive past a disconnect#
For an interactive session you can reattach to, run it in tmux:
tmux new -s overnight
claude # start the work, then press Ctrl-b d to detach
tmux attach -t overnight # tomorrow, from anywhere
For a job that should start by itself, use launchd, macOS's own scheduler. A LaunchAgent in ~/Library/LaunchAgents with a StartCalendarInterval runs a script at a set time. Unlike cron, launchd runs a job it missed while the Mac was asleep when the Mac next wakes. It does nothing for a Mac that is switched off.
3. Run the agent without anyone at the keyboard#
Claude Code's non-interactive mode is claude -p. The flags that matter overnight are the ones that stop it waiting, and stop it running forever:
claude -p "$(cat ~/jobs/nightly-brief.md)" \
--permission-mode acceptEdits \
--allowedTools "Read,Edit,Bash(git log *),Bash(npm test *)" \
--permission-prompts none \
--max-turns 40 \
--max-budget-usd 5 \
--output-format json > ~/jobs/out/$(date +%F).json
Per Anthropic's CLI reference as of September 2026:
--permission-prompts none(v2.1.259 or later) denies anything that would otherwise wait for a human, and removes the tool the agent uses to ask you questions.--max-turnsstops a run after a set number of agentic turns, and exits with an error.--max-budget-usdstops spending at a dollar figure.--output-format jsonincludestotal_cost_usdand asession_idyou can pass to--resume.
Two traps. First, --bare, which the docs recommend for scripts, never reads your subscription login or the keychain; it wants an API key. Second, a session started over SSH may not be able to read the login keychain, and then reports that you are not logged in. Start long jobs from a logged-in GUI session, or test the SSH path before you go to bed.
Prefer a narrow --allowedTools list over --dangerously-skip-permissions. An overnight run with every check turned off is a run nobody reviews until it is too late.
4. Reach it from anywhere#
Turn on Remote Login in System Settings > General > Sharing, install Tailscale on both machines, and ssh to the Mac mini by its Tailscale name from home, a café or your phone. Keep Screen Sharing and SSH off the public internet. If you use FileVault, which you should, the Mac waits at the login screen after a restart until someone types the password. That is a real trade-off for a box you plan to never touch.
What breaks when an AI agent runs overnight?#
The recipes stop at "and it keeps running." Most overnight failures happen after that.
- Usage limits. A Claude Pro or Max plan, or a ChatGPT plan, has usage windows. Hit one at 1am and the run stops. With a bare script, stopped can look like finished. Check the exit code, and read the result and cost out of the JSON.
- A session that loses its thread. Resume a session whose conversation file the CLI has cleaned up and you get
No conversation found with session ID. We covered why in Claude Code deletes your conversations after 30 days. - A question nobody answers. An agent that stops to ask "should I overwrite this file?" waits all night. In
-pmode, deny prompts outright and put the answers in the brief. - Runaway cost. A loop that retries the same failing test for six hours costs money even on a subscription, because it spends your usage window. Cap turns and spend, and give the job a clear stopping condition.
- Work that needs your logins. A script on a headless box cannot use a website you are signed into on your laptop. More on that under security below.
- Silence. The run finished, failed, or never started, and you find out when you open a terminal. Log to a file with the date in the name, and look at it before anything else.
Can I run agents overnight without the terminal?#
Yes, and this is the part the terminal guides skip. Universe is a Mac app that runs Claude Code, Codex, Gemini or Grok on the model account you already pay for. One of its features is exactly this situation: link a spare laptop, or the machine under the desk, and the agents keep working after you close the lid.
How it works, in plain terms:
- Install Universe on the spare Mac and sign in to the same account. Your Macs join one fleet.
- Move a long-running session to it. The work runs on the spare and the window stays on your laptop. Artifacts, the files the agent makes, come back home.
- Keep scheduled work on the Mac that stays on. A schedule such as "every weekday at eight" runs on a Mac, and Universe can register a wake with macOS so a due job runs. A Mac that is switched off runs nothing, which is why the spare matters.
Some things you get without writing any of the guard code above:
- Several model accounts, in order. Add more than one Claude login, API key or ChatGPT login. When the first is rate-limited, the next takes over and the transcript says so. When every account is spent, it falls back to the CLI's own login.
- Cost on every answer. Each agent answer records which account paid and what it cost, shown on hover.
- Nothing sends while you sleep. Sending, paying and posting wait for a person to press the button. A night's work ends as files and drafts, not emails already sent.
Be clear about the limits before you plan a night around it:
- A turn running on another Mac has the model's own tools, but not Universe's. It can read and write files, which sync back, but it cannot drive Universe's browser or make its typed artifacts. For browser work overnight, set that work up in Universe on the spare Mac itself.
- A schedule that fires while every Mac is off does not run. Schedules do not run in Universe's cloud.
- AGI mode keeps prompting until a person presses Stop. Do not count on a built-in spending cap. Don't leave it on overnight unless you are comfortable with what that account can spend.
- It is Mac only. There is no phone app, so you check in from another Mac.
Every plan includes schedules and your other Macs, including the free one; plans differ only in amounts. See pricing, or read the features page for the rest.
How do I see what my agents did overnight?#
On the DIY route, you SSH in, tmux attach, and read logs. That works, and it is a lot of work to do before coffee.
In Universe, the morning review happens in the app:
- Transcripts. Every session keeps its conversation, so you read what the agent did rather than guessing from the files.
- Notifications. macOS banners open the exact session or room that finished. Rooms show unread counts, including agent turns that landed while you were away.
- Files where you expect them. Everything an agent makes is a real file in the session's folder: a sheet, a document, a deck. Up to 24 earlier versions of each file are kept, with a diff, so you can see what changed overnight and restore it if the agent made things worse.
- Search. ⌘K with
?searches the words of every conversation.
If the overnight job is a recurring report, scheduling a weekly report that reads your files goes through writing the brief so the morning output is usable.
Is it safe to leave an AI agent running unattended?#
It can be, if you keep the credentials and the blast radius small.
- Keep browser logins on the Mac that can decrypt them. Chrome's cookies on a Mac are encrypted with a key in that Mac's Keychain. Copying a browser profile to a VPS either does not work or means handing your signed-in sessions to a server you do not control. Universe copies a Chrome profile into its own folder on the same Mac, and those profiles never leave it or sync. On the spare, sign in to sites in Chrome on the spare itself. Letting an agent work on sites behind your login covers this in detail.
- Scope what it can touch. Give the agent the folders the job needs, not your home directory. On the DIY route that means
--allowedTools, not skipped permissions. - Use a separate macOS user on the spare for agent work, so a mistake cannot reach your personal files.
- Don't expose the box. SSH and Screen Sharing go through Tailscale or a VPN, never a forwarded port.
- Remember what syncs. If you use a workspace with sharing or multiple Macs, some data leaves the machine. In Universe, work happens on your Mac and the model runs on your own account. What syncs to Universe's cloud when you are signed in is what sharing and your other Macs need: artifacts, sessions and transcripts.
A checklist for your first overnight run#
Start small. One boring, well-scoped job that works every night beats an ambitious one that fails in a new way each morning.
- Pick a scoped task with a clear finished state: "summarise yesterday's commits into
notes/2026-09-16.md", not "improve the codebase." - Run it once by hand while you watch. Note every permission prompt and every question it asks, and answer them in the brief.
- Set a budget and a turn cap.
--max-budget-usdand--max-turnson the DIY route. In Universe, choose an account you are happy for it to spend, and add a fallback account if the job must finish. - Write a stop condition into the prompt. "If the tests still fail after three attempts, stop and write down what you tried."
- Check the host. Sleep off, on power, logged in, network up. On a laptop, lid open or closed-display mode.
- Make failure visible. A dated log file or a notification. Silence is not success.
- Review in the morning before building on it: read the transcript, diff the files, and keep or undo.
Where Universe fits, and where it doesn't#
If you are a developer with a Mac mini, a tmux habit and code in a repository, the DIY route is solid and free, and Claude Code's own cloud routines are a good option for repo work that must run with every machine off. You may not need anything else.
Universe fits when the overnight work is not only code: research into a sheet, documents from a folder of files, work in a browser signed in as you. It also fits when more than one person needs to see the results, or you would rather link a second Mac than maintain launchd plists and SSH keys. It is honest about what it can't do: no cloud execution, no phone app, and turns moved to another Mac without Universe's own tools.
Download Universe for Apple silicon or Intel, macOS 13 or later, and try it on the Mac you already have before buying another one.
Questions#
- Does Claude Code keep running when I close my MacBook lid?
- Usually not. Closing the lid puts a MacBook to sleep unless it is on power with an external display, keyboard and mouse attached, which is Apple's closed-display mode. Anthropic's own docs say Claude Code Desktop's local scheduled tasks skip runs while the computer sleeps, and that closing the lid still puts it to sleep. For overnight work, use a machine that stays on.
- How much electricity does a Mac mini use running 24/7?
- Very little at rest. Apple publishes 4W idle and 65W maximum for the 2024 M4 Mac mini. At 4W all year that is about 35 kWh, roughly $6 at 17 cents per kWh. An agent mostly waits on the model's servers, so real use sits near idle, with bursts when it builds, renders or runs tests.
- Can I use an old MacBook as an AI agent server?
- Yes, if it can run a current enough macOS and stays plugged in with sleep turned off. Keep the lid open or use closed-display mode, check battery health in System Settings, and give it a wired or reliable Wi-Fi connection. Universe needs macOS 13 or later, on Apple silicon or Intel.
- Do I need a VPS to run AI agents overnight?
- No. Agents like Claude Code do their thinking on the model provider's servers, so any machine that stays awake can host them. A VPS makes sense for code in a repository. It is a poor fit for work that needs your Mac's files or a browser signed into your accounts, because those logins cannot safely move to someone else's server.
- What happens if an overnight agent hits its usage limit?
- On a single subscription, work stops until the limit window resets, and a script that does not check for it can look finished when it is not. Guard against it by checking the exit status and cost in the JSON output, capping turns and spend, or adding a second account that takes over when the first is rate-limited.