How to run Claude Code 24/7 so agents keep working while you sleep

How to run Claude Code 24/7 so agents keep working while you sleep

To run Claude Code 24/7, move it off your laptop to a machine that never sleeps, such as a VPS inside tmux, Anthropic's cloud sessions, or a hosted agent box. This guide explains why local sessions stop, compares five setups, and gives commands for each.

In shortTL;DR
  • Claude Code runs as a local process, so when your laptop sleeps or the terminal closes, the agent stops.
  • Keeping a laptop awake with caffeinate or systemd-inhibit works for one night, but lid closes, updates and battery still end sessions.
  • A VPS with tmux keeps interactive sessions alive after you disconnect; claude -p with cron runs unattended jobs.
  • Anthropic's cloud sessions and scheduled tasks run on their infrastructure; scheduled tasks can run at most once an hour.
  • Whatever you choose, cap turns and budget, keep production credentials away, and review every pull request.

Why does Claude Code stop when your laptop sleeps?

Claude Code stops when your laptop sleeps because it is a normal process on your computer: it reads files, runs commands and talks to Anthropic's API from your machine. When the machine sleeps, the process is frozen and its network connections drop, so the agent makes no progress until you wake it.

The same thing happens in less obvious ways:

  • Closing the terminal ends the claude process and its session.
  • Closing the lid sleeps most laptops, even with an app holding the system awake.
  • OS updates and restarts kill everything that was running.
  • Network changes (leaving the office Wi-Fi, a VPN reconnecting) can break a long-running session.

Even Remote Control, which lets you steer a local session from your phone, depends on this. Anthropic's docs say it plainly: your computer has to stay on and the claude process has to keep running. Remote Control reconnects after sleep, but nothing happens while the laptop is asleep.

So "run Claude Code 24/7" really means one thing: run it on a machine that is always on, always online and safe to leave unattended.

What are the options for running Claude Code around the clock?

There are five practical setups, from free and fragile to managed and hands-off. Pick based on how long your tasks run and whether you need your local environment.

SetupRuns when laptop is closedYour local files and toolsEffortBest for
Keep the laptop awakeNo (lid must stay open, power plugged in)YesMinutesOne long task tonight
VPS with tmuxYesOnly what you install on the serverAn hour or twoInteractive sessions you reattach to
Headless claude -p on a scheduleYes, if on a serverServer's copyAn hourRepeatable unattended jobs
Anthropic cloud sessions and scheduled tasksYesNo, fresh clone each runMinutesGitHub-hosted repos, recurring jobs
Hosted agent boxYesA persistent server you controlMinutesOngoing agent work steered from a phone

The sections below cover each one with the commands you need.

How do you keep a laptop awake for Claude Code?

You can stop a laptop from idle-sleeping with a built-in command, which is enough to let one long Claude Code task finish overnight. Keep it plugged in and the lid open.

On macOS, caffeinate holds the system awake while a command runs. The -i flag prevents idle sleep, and -s prevents system sleep but, per the caffeinate man page, only on AC power:

terminal (macOS)
caffeinate -is claude

On Linux with systemd, systemd-inhibit holds a sleep lock for the life of a command. The handle-lid-switch lock also blocks the low-level lid handling (systemd-inhibit docs):

terminal (Linux)
systemd-inhibit --what=sleep:idle:handle-lid-switch --why="Claude Code task" claude

On Windows, set the sleep timeout on AC power to 0 (never) with powercfg (Microsoft docs), and set it back afterward:

PowerShell
powercfg /change standby-timeout-ac 0

This approach has hard limits. Your laptop is busy and hot all night, a forced update can still restart it, and you can't take it with you. Running an agent with broad permissions on the machine that holds your SSH keys, browser sessions and personal files is also a real risk. Use it for a one-off, not as a routine.

How do you run Claude Code on a VPS with tmux?

Running Claude Code on a small Linux server inside tmux gives you an interactive session that keeps going after you disconnect. You SSH in, start the agent, detach, and reattach later from any computer.

  1. Create a server. Any Linux VPS with 2 GB of memory or more is a reasonable start. Create a non-root user and log in with SSH keys, not passwords.

  2. Install the basics. You need git and tmux, plus whatever your project needs to build and test (Node, Python, Docker).

  3. Install Claude Code with the native installer from the Claude Code docs:

    server
    curl -fsSL https://claude.ai/install.sh | bashclaude --version
  4. Clone your repository and give the server a GitHub credential scoped to the repos it needs (a deploy key or a fine-grained token).

  5. Start a tmux session and launch Claude Code inside it:

    server
    tmux new -s agentscd ~/work/my-appclaude

    On first run, Claude Code prints a login link you can open on your laptop or phone.

  6. Detach with Ctrl+b then d. The session keeps running after you close SSH.

  7. Reattach later with tmux attach -t agents.

To steer the server session from your phone, start it with Remote Control instead: run claude remote-control inside tmux (server mode, which can host several sessions) or claude --remote-control for a normal session that is also reachable from the Claude app. Remote Control needs a Pro, Max, Team or Enterprise plan; API keys are not supported. The Remote Control docs themselves recommend tmux or screen on remote machines so the session survives SSH disconnects.

For a full server hardening checklist (firewall, users, updates, backups), see our guide to setting up a remote development server.

How do you run Claude Code headless with claude -p?

Headless mode runs one task non-interactively and exits, which makes it ideal for cron, systemd timers and CI. Add -p (or --print) to any claude command, as described in Run Claude Code programmatically.

The flags that matter for unattended runs:

FlagWhat it does
-p "task"Runs the task without the interactive UI, then exits
--allowedTools "..."Pre-approves specific tools or commands, such as Bash(git commit *)
--permission-mode acceptEditsLets Claude write files without prompting; other shell commands still need allow rules
--permission-prompts noneDenies anything that would wait for a human, instead of hanging
--max-turns 40Stops after a set number of agentic turns
--max-budget-usd 5Stops once estimated API spend reaches the cap
--output-format jsonReturns the result, session ID and estimated cost as JSON

Here is a nightly job that updates dependencies on a fresh branch and writes a log:

~/bin/nightly-claude.sh
#!/usr/bin/env bashset -euo pipefailexport PATH="$HOME/.local/bin:$PATH"   # make sure cron can find claudecd ~/work/my-appgit fetch origin && git checkout main && git pull --ff-onlygit checkout -b "claude/deps-$(date +%F)"claude -p "Update patch-level npm dependencies. Run npm test. If tests fail, revert the change that broke them. Commit with a clear message and summarize what changed." \  --permission-mode acceptEdits \  --allowedTools "Bash(npm install *),Bash(npm test),Bash(git add *),Bash(git commit *)" \  --permission-prompts none \  --max-turns 40 \  --max-budget-usd 5 \  --output-format json > ~/logs/claude-$(date +%F).json

Schedule it with cron (run crontab -e):

crontab
0 2 * * * /home/dev/bin/nightly-claude.sh >> /home/dev/logs/cron.log 2>&1

A few details from the docs save debugging time. claude -p exits with code 0 on success and non-zero on failure, so your script can branch on it. With --output-format json you can capture session_id and later continue the same conversation with claude -p "..." --resume "$session_id". Cost figures in the JSON are client-side estimates and can differ from your bill. For CI and scripts that should behave the same on every machine, --bare skips local hooks, plugins, MCP servers and CLAUDE.md, but it needs an API key instead of your subscription login.

Tip

Write headless prompts like a ticket for a colleague who can't ask questions: the goal, the files involved, the command that proves it works, and what to do if it fails. Our guide on how to write tasks for AI coding agents has templates.

Can Anthropic run Claude Code in the cloud for you?

Yes. Claude Code has two cloud features that keep working when your computer is off: cloud sessions and scheduled tasks. Both run on Anthropic-managed infrastructure against a fresh clone of a GitHub repository.

Cloud sessions start from claude.ai/code, the Claude mobile app, or your terminal with claude --cloud "Fix the login bug". You can pull a cloud session into your local terminal later with claude --teleport.

Scheduled tasks (formerly called routines) are saved prompts that run on a schedule, on an API call or on GitHub events such as a new pull request (scheduled tasks docs). As of October 2026:

  • They are in research preview and available on Pro, Max, Team and Enterprise plans.
  • You create them at claude.ai/code/routines, in the desktop app, or with /schedule in the CLI.
  • The minimum interval is one hour.
  • Runs push to branches prefixed with claude/ and count against your plan's usage.
  • The default environment only allows a list of common package registries and development domains, so tasks that call your own services need network settings changed.

Cloud options fit well when your repo is on GitHub and the task needs nothing from your machine. They fit less well when you need a persistent environment: a database with seeded data, a long-running dev server, tools you installed once, or a task that runs more often than hourly.

How do you keep an unattended Claude Code agent safe?

An unattended agent should be able to do its job and nothing else. Set limits on what it can touch, how long it runs and what it can spend before you walk away.

  • Isolate the machine. Run unattended agents on a server or container with no personal files, no browser sessions and no production credentials.
  • Prefer allow rules over skipping permissions. --dangerously-skip-permissions lets the agent run any command. If you use it, do so only on a disposable, isolated box. Explicit --allowedTools rules or --permission-mode auto are safer defaults.
  • Protect branches. Let agents push only to feature branches, and require pull request review on main with GitHub branch protection.
  • Cap every run. Use --max-turns and --max-budget-usd so a confused agent stops instead of looping.
  • Treat outside content as untrusted. Issues, web pages and dependency READMEs can carry instructions aimed at the agent. Read about prompt injection in coding agents before you let an agent act on public input.
  • Log everything. Keep the JSON output or session transcripts so you can see what happened before you merge.

Where a hosted box fits

A hosted agent box is a managed, always-on server set up for coding agents, so you get the VPS benefits without building and maintaining the server yourself. It suits people who want agents to keep working overnight but don't want to manage SSH keys, tmux, updates and GitHub credentials.

Orkio is one option: it rents an isolated cloud server in Europe where Claude Code and Codex keep running after you close the app or your laptop. You connect your Claude account and GitHub once, give agents tasks from your phone or the web, and review the pull requests they open. Agents use your own Claude account, so there is no markup on model usage; the Starter box is $19 a month (pricing).

How to start running Claude Code 24/7 tonight

Pick the smallest setup that fits, then grow into the next one when it starts to hurt.

  1. Tonight, one task: plug in, keep the lid open, and run caffeinate -is claude (macOS) or the systemd-inhibit equivalent.
  2. This week, regular overnight work: set up a VPS with tmux and Claude Code, and turn on Remote Control so you can check in from your phone.
  3. Recurring jobs: turn the tasks you repeat into claude -p scripts with turn and budget caps, or into scheduled tasks if the repo lives on GitHub.
  4. Before every unattended run: isolated machine, scoped GitHub access, branch protection, caps set, logs on.
  5. Every morning: review the pull requests like a teammate's work, and refine your task prompts based on what went wrong. Our overnight AI agent workflow covers a morning review routine in detail.

Frequently asked questions

Does Claude Code keep running if I close my laptop lid?

Usually not. Closing the lid puts most laptops to sleep, which pauses the claude process and drops its network connection. Remote Control sessions reconnect when the machine wakes, but no work happens while it sleeps.

Can I run Claude Code on a VPS with my Claude subscription?

Yes. Install Claude Code on the server, run claude, and sign in through the login link it prints, which you can open on any device. For scripts and CI, claude setup-token generates a long-lived token from a Claude subscription.

How much does it cost to run Claude Code all day?

You pay for the machine and for model usage separately. A small VPS costs a few dollars to a few tens of dollars a month, and model usage comes out of your Claude plan limits or is billed per token with an API key. Long unattended sessions use limits quickly, so set turn and budget caps.

Is it safe to run Claude Code with permissions skipped overnight?

Only inside an isolated machine or container with nothing valuable on it. Skipping permissions lets the agent run any command, so keep it away from production credentials, personal files and your main laptop. Prefer explicit allow rules or auto mode where you can.

What is the difference between Remote Control and cloud sessions?

Remote Control lets you steer a Claude Code session that runs on your own machine from a phone or browser, so that machine must stay on. Cloud sessions run on Anthropic's infrastructure, so they continue when your computer is off, but they work on a fresh clone of your repository instead of your local environment.

SOURCES

  1. Claude Code docs: Run Claude Code programmatically
  2. Claude Code docs: Remote Control
  3. Claude Code docs: Scheduled tasks
  4. Claude Code docs: CLI reference
  5. caffeinate man page
  6. systemd-inhibit man page
  7. Microsoft Learn: Powercfg command-line options
  • #claude code
  • #background agents
  • #vps
  • #tmux
  • #automation
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