Skip to main content
MindStudio
Pricing
Blog About
My Workspace
WorkflowsAutomationProductivity

How to Keep Your Claude Code Agent Running 24/7 Without a Mac Mini

Learn how to prevent your Mac or PC from sleeping so your Claude Code agent stays active around the clock without buying dedicated hardware.

MindStudio Team
How to Keep Your Claude Code Agent Running 24/7 Without a Mac Mini

The Real Problem: Your Machine Won’t Stay Awake

If you’ve been using Claude Code for extended tasks — refactoring a large codebase, building a feature across multiple files, running automated test cycles — you’ve probably run into this: you walk away, come back an hour later, and the agent is dead. Your laptop went to sleep. The process stopped. Progress lost.

Keeping your Claude Code agent running 24/7 is a legitimate operational challenge, and the obvious fix people reach for is buying a Mac Mini or a dedicated machine that stays on permanently. That works, but it’s overkill for most use cases. You don’t need new hardware — you need to stop your existing machine from interrupting what’s already running.

This guide covers the practical, low-cost ways to keep Claude Code alive around the clock using the hardware you already have, plus when it makes sense to move to a cloud server instead.


Why Sleep Mode Kills Long-Running Agents

When a computer enters sleep mode, it suspends all running processes. For short tasks, this doesn’t matter much. For a Claude Code agent working through a complex, multi-step task over several hours, any interruption means starting over.

There are three main things that typically kill a running agent:

  • System sleep (idle sleep) — The whole machine suspends. This kills your process completely.
  • Display sleep — The screen turns off but the system stays active. Usually not a problem on its own.
  • Terminal session timeout — If you’re running Claude Code over SSH or in a remote terminal, a dropped connection ends the session immediately.

The solutions below address each of these scenarios. Most people need to solve at least two of them together.


Keep Your Mac Awake for Claude Code

Use the caffeinate Command

The simplest Mac solution is the built-in caffeinate command. It prevents the system from sleeping for as long as it runs — no app install required.

To prevent sleep indefinitely until you cancel:

caffeinate

To keep the system awake only while a specific process is running:

caffeinate -w <PID>

Replace <PID> with the process ID of your Claude Code session. Find it by running echo $$ in the same terminal before starting.

The most useful flags:

  • -i — Prevents idle sleep (system stays awake, display can still dim)
  • -s — Prevents sleep even on battery power
  • -d — Keeps the display from sleeping
  • -t <seconds> — Automatically stops after a set duration

For most cases, run this before starting Claude Code:

caffeinate -i &

The & sends it to the background so you can keep using the same terminal window.

Adjust Energy Settings Permanently

For a persistent change that doesn’t require running a command each time:

  1. Open System SettingsBattery (macOS Ventura and later) or System PreferencesEnergy Saver
  2. Under Power Adapter, enable Prevent automatic sleeping when the display is off
  3. Set sleep to Never while plugged in

This applies globally, not just when Claude Code is running. For most people, that’s fine. If you prefer precision, use caffeinate and trigger it only when needed.

Use pmset for Granular Control

pmset gives you more control over Mac power behavior from the terminal:

# Prevent sleep while plugged in
sudo pmset -c sleep 0

# Prevent system sleep without changing display settings
sudo pmset -c disablesleep 1

# Restore defaults when done
sudo pmset -c sleep 10

The -c flag applies to AC power only. Use -b for battery and -a for both.

Use Amphetamine (Free App)

Amphetamine is a free Mac App Store app that puts a small icon in your menu bar. Click it to prevent sleep for a set duration, indefinitely, or conditionally — for example, “while a specific app is running.”

It’s a clean option if you prefer a GUI and don’t want to remember terminal syntax.


Keep Your Windows PC Awake

Adjust Power Options via Settings

The quickest approach:

  1. Open SettingsSystemPower & sleep
  2. Under Sleep, set When plugged in, PC goes to sleep after to Never

This keeps the system running indefinitely while plugged in. Reverse it when you’re done with long-running tasks.

Use the Command Line

For a command-line approach, use powercfg in Command Prompt (as Administrator):

rem Set system sleep timeout to never while on AC power
powercfg /change standby-timeout-ac 0

rem Restore to 30 minutes when done
powercfg /change standby-timeout-ac 30

For a more targeted solution, this PowerShell script prevents sleep while it’s running:

$code = @"
[DllImport("kernel32.dll")]
public static extern uint SetThreadExecutionState(uint esFlags);
"@
$type = Add-Type -MemberDefinition $code -Name "Win32" -Namespace Win32Functions -PassThru
$type::SetThreadExecutionState([uint32]"0x80000001") | Out-Null
Write-Host "Sleep prevented. Press Ctrl+C to stop."
while ($true) { Start-Sleep -Seconds 60 }

Save it as nosleep.ps1 and run it in a separate PowerShell window alongside your Claude Code session.

Use PowerToys Keep Awake

If you use Microsoft PowerToys, the Keep Awake module handles this without any command line work. Enable it from the PowerToys dashboard, set a duration or leave it indefinite, and Windows won’t sleep until you turn it off.

It’s arguably the cleanest Windows option — maintained by Microsoft and easy to toggle on and off.


Keep Sessions Alive with tmux or screen

Preventing sleep solves one problem. But there’s a second problem: if the terminal window closes — whether you closed it accidentally, lost an SSH connection, or restarted your shell — the process dies with it.

The fix is a terminal multiplexer. Both tmux and screen let you start a session, detach from it, and reattach later without killing what’s running inside. This is especially important for SSH sessions where connection drops are common.

Using tmux

Install tmux if you don’t have it:

# macOS
brew install tmux

# Ubuntu/Debian
sudo apt install tmux

Start a named session:

tmux new -s claude

Inside the session, start Claude Code. When you want to step away without killing the session, detach with Ctrl+B, then D.

The session keeps running in the background. To come back:

tmux attach -t claude

List all running sessions:

tmux ls

tmux sessions persist across terminal restarts as long as the machine doesn’t reboot. If your SSH connection drops, Claude Code keeps running and you can reattach when you reconnect.

Using screen

screen is an older alternative that works the same way:

# Start a named session
screen -S claude

# Detach: Ctrl+A, then D

# Reattach
screen -r claude

tmux has more features and better documentation, but both work well. Use whichever you’re already comfortable with.

Using nohup for Simpler Cases

If you’re running a script that invokes Claude Code (rather than an interactive session), nohup keeps it running after the terminal closes:

nohup your-claude-script.sh > output.log 2>&1 &

Output goes to output.log. The process continues even after you log out.


Run Claude Code on a Cloud Server

If you need true 24/7 uptime without leaving your laptop on all the time, a small cloud server is a practical alternative to buying a Mac Mini. It costs a fraction of the price and you only pay for what you use.

Choose a Provider

Any major cloud provider works. Here’s a quick comparison:

ProviderRecommended specApproximate cost
AWS EC2t3.medium (2 vCPU, 4GB RAM)~$30–35/month
DigitalOcean2GB RAM / 1 vCPU Droplet~$12/month
HetznerCX22 (2 vCPU, 4GB RAM)~$5–6/month
Fly.ioshared-cpu-2x with 2GB RAM~$15–20/month

For Claude Code, you generally want at least 2GB of RAM and a reasonably fast CPU. The heavier the codebase you’re working with, the more RAM you’ll want.

Set Up Your Environment

Once you have a server:

  1. SSH in and install your dependencies (Node.js, git, your language runtime)
  2. Install Claude Code and authenticate with your Anthropic API key
  3. Clone your repository
  4. Start a tmux session and run Claude Code inside it

With this setup, Claude Code runs on a machine that’s always on, always connected, and reachable from anywhere via SSH.

Handle Automatic Restarts After Reboots

Servers reboot occasionally for maintenance. To make sure Claude Code restarts automatically, use PM2:

npm install -g pm2
pm2 start your-claude-script.js
pm2 startup   # generates a startup command for your OS
pm2 save      # saves the current process list

Or write a simple systemd service on Linux:

[Unit]
Description=Claude Code Agent
After=network.target

[Service]
Type=simple
User=youruser
WorkingDirectory=/home/youruser/project
ExecStart=/home/youruser/run-claude.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

Save it to /etc/systemd/system/claude-agent.service, then:

sudo systemctl enable claude-agent
sudo systemctl start claude-agent

Layer Your Reliability

No single approach covers every failure mode. Here’s how the strategies stack together:

LayerProblem it solvesRecommended tool
Prevent sleepMachine suspends mid-taskcaffeinate / pmset / Power Options / PowerToys
Session persistenceTerminal closes mid-tasktmux / screen
Process recoveryCrashes or unexpected exitsPM2 / systemd
Always-on infrastructureDon’t want laptop running 24/7Cloud VPS

For most developers using Claude Code at home: caffeinate + tmux covers the majority of cases with zero added cost.

For teams running Claude Code on shared infrastructure or CI-like pipelines: cloud VPS + systemd or PM2 is the more reliable path.


Extend What Claude Code Can Do with MindStudio

Keeping Claude Code alive 24/7 is the infrastructure layer. Once it’s running unattended, the next question is: what happens around the coding work itself?

If you want Claude Code to send notifications when a task finishes, trigger downstream workflows based on results, or pull in live information mid-task, MindStudio’s Agent Skills Plugin is worth knowing about. It’s an npm SDK (@mindstudio-ai/agent) that gives Claude Code direct access to 120+ typed capabilities as simple method calls:

  • agent.sendEmail() — notify yourself when a long overnight task completes
  • agent.searchGoogle() — pull in live documentation or dependency info mid-task
  • agent.runWorkflow() — trigger a MindStudio workflow to handle downstream steps

This is particularly useful for unattended scenarios. If Claude Code finishes a task at 3am, it can fire off a Slack message or email through MindStudio without any manual intervention on your part.

You can also build the inverse: use MindStudio’s scheduled background agents to kick off Claude Code tasks on a schedule, and have MindStudio handle everything around the coding work — project updates, Airtable logging, stakeholder notifications. The two complement each other without much setup.

You can try MindStudio free at mindstudio.ai.


Frequently Asked Questions

Does caffeinate work on Apple Silicon Macs?

Yes. caffeinate is a standard macOS command that works on all Apple Silicon and Intel Macs running macOS 10.8 or later. No installation needed — it’s included with the OS.

Will running my laptop 24/7 damage it?

Modern laptops handle extended uptime fine. Keeping a MacBook or Windows laptop plugged in and awake for days at a time is normal from a hardware perspective. The main considerations are heat (make sure there’s ventilation) and battery health (most modern Macs and PCs have charge limit options to help). A laptop sitting at a desk plugged in, not moving, tends to have fewer wear issues than one being carried around daily.

What happens if Claude Code crashes mid-task?

Claude Code can often resume or restart tasks depending on how it was configured. If you’re using PM2 or systemd, the process restarts automatically. For long tasks, it’s worth structuring your prompts to checkpoint progress — having the agent commit code at logical stopping points so a restart doesn’t mean starting from scratch. This is one area where building structured workflows around your agent helps significantly.

Is a VPS cheaper than a Mac Mini?

Short term, yes. A DigitalOcean or Hetzner VPS capable of running Claude Code costs $10–30/month. A Mac Mini starts at $599. At $15/month, a VPS breaks even with the Mac Mini in about three years. The Mac Mini wins if you want local hardware you fully control with no ongoing subscription. The VPS wins if you want to start immediately at low cost and are comfortable with a monthly fee.

Can I run Claude Code on a Raspberry Pi?

Technically yes, but with significant limitations. A Raspberry Pi 4 or 5 with 4–8GB of RAM can run it. Performance will be slower than a cloud server, and you’ll still have the sleep/uptime challenges of any local machine. For simple, low-intensity tasks it can work. For anything involving large codebases or frequent API calls, a VPS is a better option at similar or lower cost.

Does Claude Code work in headless server environments?

Yes. Claude Code is a terminal-based tool and doesn’t require a display. It runs on headless Linux servers, inside Docker containers, and in any environment where you have shell access and the necessary runtime dependencies installed. This makes it well-suited for cloud server deployments.


Key Takeaways

  • Prevent sleep first. On Mac, caffeinate -i & is the easiest solution. On Windows, use Power Options or PowerToys Keep Awake.
  • Use tmux or screen. These keep your session alive even if the terminal closes or an SSH connection drops — nothing dies, you just reattach.
  • A cloud VPS costs less than a Mac Mini. $10–30/month gets a server that’s always on; no local machine left running.
  • Layer your reliability. Sleep prevention + session management + process recovery together cover most failure modes.
  • MindStudio extends Claude Code’s reach. Once your agent is running unattended, the Agent Skills Plugin adds email, search, workflow triggers, and 120+ other capabilities with minimal setup.

If you’re building toward a fully automated coding pipeline — agents that run, report, and coordinate without you watching — MindStudio is a practical place to start.

Presented by MindStudio

No spam. Unsubscribe anytime.