Can Claude Code run overnight? How to keep it working 24/7
On this page
Keep the machine awake (24/7 on Mac or Linux)Keep the session alive when the terminal closesStop permission prompts from blocking the nightLet it continue after a usage limitLong runs and auto-compactionWhen Claude decides it is done: /goal, Stop hooks and /loopScheduled runs instead of one long sessionGet told when it needs youSafety: what you accept by walking awayKeeping Codex running overnightHow Codeman handles itYes. Claude Code can keep working overnight, or around the clock, as long as nothing stops it, and six things usually do: the computer sleeps, the terminal closes, a permission prompt waits for an answer, a usage limit pauses the session, the context window fills, or Claude decides the task is finished. To keep Claude Code running overnight, remove each one; as of October 2026, each has an official mitigation:
| What stops the run | Official mitigation |
|---|---|
| The computer sleeps | Keep it awake, or use a machine that never sleeps |
| The terminal closes | tmux, or a background session (claude --bg) |
| A permission prompt | Auto mode, allow rules, the Bash sandbox |
| A usage limit | Automatic continue after the reset |
| The context fills | Auto-compaction, with the plan kept in files |
| Claude thinks it is done | /goal, a Stop hook or /loop |
Keep the machine awake (24/7 on Mac or Linux)
A sleeping computer runs nothing. On a Mac, caffeinate holds a sleep assertion for as long as the command it starts:
caffeinate -i claude # prevent idle sleep while claude runs
caffeinate -s claude # prevent system sleep, only on AC power
For a Mac that runs agents 24/7, Apple's sleep settings offer Prevent automatic sleeping when the display is off under System Settings > Energy on desktops, and Prevent automatic sleeping on power adapter when the display is off under Battery > Options on laptops. On a Linux desktop, systemd-inhibit does the same job: systemd-inhibit --what=idle:sleep --why="claude is working" claude. None of this keeps a closed laptop in a bag awake; Will Claude keep running if I lock or close my laptop? covers lids, servers and reboots.
Keep the session alive when the terminal closes
A claude started directly in a terminal ends when that terminal closes. Two ways around it:
tmux. Start the session inside tmux and detach. It keeps running without a window or an SSH connection, which is why Anthropic's Remote Control docs recommend tmux or screen on remote machines:
tmux new -s night # then run claude inside it
# Ctrl-b d detaches; claude keeps running
tmux attach -t night # come back later
Background sessions. To run Claude Code in the background without tmux, claude --bg "fix the flaky auth tests" starts a background session, and /bg moves the session you are in. A supervisor keeps them running after the terminal closes, and claude agents lists them. Agent view is a research preview; background sessions survive sleep but stop if the machine shuts down.
The catch: the automatic continue after a usage limit is not offered in background sessions or -p runs. For a night that may hit a limit, an interactive session inside tmux is the better host.
Stop permission prompts from blocking the night
From v2.1.283, auto mode is the built-in starting permission mode for interactive terminal sessions. A classifier model reviews actions in your place and by default blocks things like curl | bash, force pushes and production deploys. It can still stall: after 3 blocks in a row or 20 in a session, auto mode pauses and Claude Code goes back to prompting (in a -p run the blocked action just doesn't run).
Three more controls narrow what runs without asking:
Allow and deny rules in
settings.json, matched per command:{ "permissions": { "allow": ["Bash(npm run *)", "Bash(git commit *)"], "deny": ["Bash(git push *)"] } }The Bash sandbox (
/sandbox) has the operating system limit which files and hosts shell commands can reach. It covers shell commands only, so Anthropic calls it not sufficient for fully unattended runs on its own.--permission-mode dontAskfor scripts denies anything not pre-approved, so the session never waits for input.
--dangerously-skip-permissions removes the checks. Anthropic says to use it only in isolated environments such as containers or VMs; see Claude Code in Docker.
Let it continue after a usage limit
Claude Code v2.1.234 and later wait in the open session and continue the task after a claude.ai usage limit resets. This is on by default in interactive sessions signed in with a subscription, and the conversation records it as Usage limit reached · continuing automatically at 3:45pm · esc to cancel. Know the edges: it re-arms at most twice in a row, a computer that slept more than about 30 minutes across the reset waits for Enter, and Remote Control sessions don't start the wait on their own (run /rate-limit-options). The switch is Continue automatically at usage limit in /config; Auto-continue Claude Code when your usage limit resets covers the failure cases.
Long runs and auto-compaction
A full context window doesn't end the session: Claude Code clears old tool output and summarizes the conversation. The project-root CLAUDE.md and auto memory are re-injected from disk afterwards, but instructions given only in chat may be lost. Keep the task, its constraints and a progress file in the repository. That includes limits like "don't push": auto mode's classifier re-reads them from the transcript, so a deny rule is the durable version. /autocompact 500k compacts earlier, and if one huge output refills the window every time, auto-compaction stops with an Autocompact is thrashing error instead of looping.
When Claude decides it is done: /goal, Stop hooks and /loop
Claude stops when the work looks done. For an autonomous loop that ends on your terms, give it a condition it can prove:
/goal all tests in test/auth pass and the lint step is clean, or stop after 30 turns
After every turn, /goal has a small fast model check the condition and starts another turn if it isn't met. The goal clears when the condition holds, when the evaluator judges it impossible, or on an error you have to fix, such as an authentication failure or an exhausted credit balance. A usage limit only pauses it, and the automatic continue picks it up again. /goal doesn't change the permission mode, so pair it with auto mode; headless, use claude -p "/goal ...".
A Stop hook does the same with your own script: returning {"decision": "block", "reason": "..."} keeps Claude working, up to eight consecutive continuations unless you raise CLAUDE_CODE_STOP_HOOK_BLOCK_CAP. /loop re-runs a prompt on an interval (/loop 30m check CI and fix failures) or at a pace Claude picks; its tasks live in the session, and recurring ones expire after seven days.
Scheduled runs instead of one long session
For work that should start at 3am rather than run all night, Anthropic lists three schedulers: cloud routines (research preview, run with your computer off, at most hourly), Desktop scheduled tasks (app open, machine awake) and /loop. Cron or a systemd timer with claude -p is the self-hosted route: see Run Claude Code on a schedule.
Get told when it needs you
A Notification hook with the permission_prompt and idle_prompt matchers can push to your phone; Get notified when Claude Code finishes has a working script. With Remote Control (claude remote-control or /remote-control, on Pro, Max, Team and Enterprise), turn on Push when actions required in /config and answer the prompt from the Claude app.
Safety: what you accept by walking away
- Auto mode reduces prompts but does not guarantee safety. The classifier is a per-action check, not an isolation boundary, so a container or VM still adds defense in depth.
- The Bash sandbox still lets commands read most of the machine,
~/.sshincluded, unless you deny those paths. - Work on a branch, read the diff in the morning, and ask for evidence (test output, commands run) and a review in a fresh subagent before you trust "done".
- Every turn spends quota or money, and background sessions draw on the same limits as interactive ones. Bound goals with a turn clause, and cap
-pruns with--max-turns.
Keeping Codex running overnight
OpenAI's long-running work guide uses the same idea: /goal <objective> in an interactive Codex CLI session, plus /goal pause, /goal resume, /goal edit and /goal clear. A goal keeps the existing sandbox and approval policy and pauses when it needs a decision; approvals_reviewer = "auto_review" sends eligible approval requests to a reviewer agent instead. For scripts, codex exec --sandbox workspace-write "<task>" runs without the interactive UI, and OpenAI says to avoid --dangerously-bypass-approvals-and-sandbox unless you are inside a dedicated sandbox VM. To keep Codex running on a Mac, turn on Prevent sleep while running in the ChatGPT desktop app's settings; the CLI has the same as an experimental feature under /experimental, which keeps the machine awake while a turn runs. Codex Cloud tasks keep working while your computer sleeps.
How Codeman handles it
Codeman runs each agent CLI in its own tmux session on your machine, so sessions outlive the browser, the network and a Codeman restart, though not a reboot; Running As A Service keeps Codeman itself up. Everything below is off until you turn it on (Keeping Agents Running):
- Respawn (per session). When a session goes idle, Codeman sends an update prompt asking the agent to record its progress, then
/clear,/initand a kickstart prompt, until the duration you set ends. Idle is read from the screen for Claude and Codex, reported by DeepSeek Harness itself, and inferred more coarsely from output for other CLIs. The Overnight preset waits for 10 seconds of idle and runs 480 minutes. Every cycle costs tokens, and the built-in presets turn on Auto-accept prompts, which answers routine confirmation menus such as plan approvals. - Auto-resume when the usage limit resets (Claude only): Codeman waits until two minutes past the parsed reset time, sends Escape and
continue, and holds respawn cycles meanwhile so/clearcannot wipe the conversation. A pending resume survives a Codeman restart; Claude Code's own wait covers the same ground. - Cron Jobs start an interactive session for any agent type on a schedule.
- Notifications And Approvals: web push with no tab open (HTTPS; on iOS, add Codeman to the home screen), Approve and Deny buttons through the opt-in Approvals Inbox (Claude and DeepSeek Harness only), webhooks to ntfy, Slack or Discord, and an Away Digest of the night.
Two limits. The default Claude Startup Mode is --dangerously-skip-permissions, which Anthropic reserves for isolated environments; for unattended work on your own machine, set it to auto (App Settings → Agents & CLIs → Claude) or use a Docker case. Other CLIs can respawn but get no usage-limit auto-resume.