Run Claude Code 24/7 on macOS: A Complete Setup Guide
How to set up Claude Code to run continuously on macOS, keeping your Mac awake, scheduling jobs reliably, and monitoring execution without touching your machine.

If Claude Code only runs when you're actively at your machine, you're using about 30% of its potential. The real power emerges when you hand it work overnight, dependency upgrades, test suites, documentation passes, data processing tasks, and wake up to a completed PR.
Running Claude Code 24/7 on macOS is straightforward in theory: keep the machine on, run jobs on a schedule, monitor execution. The practice is trickier. You need to handle power management, permissions, reliability, and cost control. This guide covers the setup that actually works.
Hardware: Which Mac Setup Works Best
Running Claude Code continuously has minimal hardware requirements but specific power constraints.
Desktop machines (Mac mini, Mac Studio): These are ideal. They're designed to run for extended periods, they're not going to sleep, and you don't have to make any configuration changes. Plug in power, set the machine to stay awake, and you're done. If you're building a proper automation system, a Mac mini (£500–700) pays for itself in a few months of reduced manual work.
MacBook with external power: If you're using a MacBook, you can keep it running overnight by plugging it in and disabling sleep. Go to System Settings → Battery → Options → "Prevent automatic sleeping on power adapter when the display is off." This works, but you're running up laptop cooling and battery cycles. It's fine for testing or occasional overnight jobs, but it's not sustainable long-term.
MacBook unplugged: Don't attempt this. Your laptop will sleep, Claude Code will pause, and your overnight automation becomes unreliable. If you're running scheduled jobs, your Mac has to be powered and awake.
The honest recommendation: if you're serious about 24/7 automation, invest in a small desktop machine. The peace of mind and reliability are worth more than the cost.
Keeping Your Mac Awake
Even with external power, modern Macs will sleep by default. You need to disable sleep explicitly.
Method 1: System Settings (Recommended)
- Open System Settings
- Go to Battery (or Energy Saver on older systems)
- Under "Options," toggle "Prevent automatic sleeping on power adapter when the display is off"
- The machine will now stay awake as long as it's plugged in
Method 2: Terminal (For Headless Setups)
If you're accessing your Mac remotely and don't have GUI access, use pmset:
sudo pmset -a sleep 0 disksleep 0This disables sleep entirely. To revert it later:
sudo pmset -a sleep 10 disksleep 10(Sets sleep to 10 minutes, which is safer than permanent.)
Method 3: Schedule Wake with cron
If you want the machine to sleep during the day and wake for overnight jobs:
# Wake at 1am for a scheduled job
pmset repeat wakeorpoweron M 01:00:00This is useful if your machine is in an office and you want to save power during the day.
Scheduling Claude Code Jobs
Two proven approaches: cron (free, built-in) and OpenHelm (desktop app, more features).
Approach 1: Cron + Shell Script
Create a shell script that runs Claude Code:
#!/bin/bash
# ~/scripts/nightly-code-task.sh
LOG_DIR="$HOME/claude-logs"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/$(date +%Y-%m-%d_%H-%M-%S).log"
# Run Claude Code with a specific goal
claude -p "Your task description here" \
--project /path/to/your/project \
>> "$LOG_FILE" 2>&1
# Optional: send notification when done
if [ $? -eq 0 ]; then
osascript -e 'display notification "Claude Code job completed" with title "Automation"'
else
osascript -e 'display notification "Claude Code job failed" with title "Automation"'
fiMake it executable:
chmod +x ~/scripts/nightly-code-task.shThen schedule it with cron:
crontab -eAdd:
0 2 * * * /Users/you/scripts/nightly-code-task.sh(Runs at 2am daily.)
Important: Cron requires Full Disk Access on modern macOS. Grant it in System Settings → Privacy & Security → Full Disk Access, adding /usr/sbin/cron.
Approach 2: OpenHelm Desktop App
OpenHelm is a macOS app specifically built for this. It handles the scheduling, run history, silence detection, and monitoring through a GUI.
Key advantages over cron:
- Silence detection, stops jobs that hang after 10 minutes of no output
- Structured run history, view past runs with status, duration, cost
- Self-correction, failed jobs can automatically queue a corrective retry
- No cron permissions needed, you don't have to fiddle with Full Disk Access
Install from openhelm.ai, then configure jobs through the app. Each job specifies:
- Goal (the prompt Claude Code will execute)
- Project directory
- Schedule (calendar, interval, cron, once, or manual)
- Silence detection timeout
Managing Costs for 24/7 Execution
Claude Code bills by token usage. A long-running job can get expensive if it's looping inefficiently. A few practices keep costs reasonable:
Write tight goals. "Fix failing tests" is better than "improve code quality." The more specific your goal, the fewer tokens Claude Code wastes exploring dead ends.
Set a hard timeout. If you're using cron, wrap Claude Code with timeout:
timeout 7200 claude -p "Your goal" --project /path(Kills the process after 2 hours regardless.)
OpenHelm can configure silence detection timeouts per job, which serves a similar purpose.
Monitor your costs weekly. Check the Anthropic Console and track per-session costs. Overnight jobs that consistently cost £15–30 are normal. Jobs that suddenly spike to £50+ suggest something's looping.
Track runs in a spreadsheet. Date, goal, duration, cost. After a month of data, you'll see patterns, which types of jobs are expensive, which run efficiently.
Handling Job Failures and Monitoring
24/7 execution is only valuable if you catch failures. You can't check logs every morning if nobody's checking logs.
Option 1: Desktop Notifications (Simplest)
The shell script above uses osascript to show a macOS notification when the job completes. You'll see it on your Mac next time you unlock it.
Option 2: OpenHelm Dashboard (Recommended)
If you're using OpenHelm, the dashboard shows every job's status, green for success, red for failure, yellow for in-progress. You can see at a glance if anything failed overnight without needing to check logs.
Option 3: Email or Slack (Best for Teams)
If you want notifications sent to your phone or team Slack:
# After the Claude Code job completes, send a status email
if [ $? -eq 0 ]; then
echo "Claude Code job succeeded at $(date)" | mail -s "Automation: Success" you@example.com
else
echo "Claude Code job failed at $(date)" | mail -s "Automation: FAILED" you@example.com
fiFor Slack, use a webhook:
curl -X POST -H 'Content-type: application/json' \
--data '{"text":"Claude Code job succeeded"}' \
YOUR_SLACK_WEBHOOK_URLSecurity Considerations
Running automated processes on your machine introduces some security considerations worth thinking through.
Credentials and environment variables: Claude Code needs access to your API keys and potentially other credentials to do useful work. Store these in environment variables, not in the goal prompt.
# Good: use environment variables
export API_KEY="sk-..."
claude -p "Deploy the service using $API_KEY" --project /path
# Bad: hardcode in the prompt
claude -p "Deploy using sk-..." --project /pathScope the working directory: Only give Claude Code access to directories it needs. Don't run it against your entire home directory, scope it to the project it's working on.
Monitor permissions: If you've granted Claude Code execute permissions (to run npm install, git push, etc.), be intentional about that. Those are powerful permissions.
Sample Setup: Dependency Updates Every Sunday
Here's a complete, production-ready setup for one realistic use case:
#!/bin/bash
# ~/scripts/weekly-dependency-update.sh
PROJ="/Users/you/projects/myapp"
LOG_DIR="$HOME/claude-logs"
mkdir -p "$LOG_DIR"
LOG_FILE="$LOG_DIR/deps-$(date +%Y-%m-%d).log"
# Run Claude Code with a tight, reviewable goal
timeout 3600 claude -p "
1. Run npm outdated to see available updates
2. Update all packages with npm update
3. Run npm audit fix to address security vulnerabilities
4. Run the full test suite (npm test)
5. If tests pass, create a commit with message 'chore: dependency updates'
6. If tests fail, document the failures and stop
" --project "$PROJ" >> "$LOG_FILE" 2>&1
STATUS=$?
# Notify on completion
if [ $STATUS -eq 0 ]; then
osascript -e 'display notification "Weekly dependency update succeeded" with title "Automation"'
else
osascript -e 'display notification "Weekly dependency update failed, check logs" with title "Automation"'
fi
exit $STATUSSchedule it:
# Runs every Sunday at 1am
0 1 * * 0 /Users/you/scripts/weekly-dependency-update.shMonday morning, you review the PR and merge it. One less thing to procrastinate on.
FAQ
Can I run Claude Code on a headless machine (Mac Studio with no monitor)?
Yes. SSH into the machine, export your API key, and run Claude Code as normal. It runs entirely in the terminal; no display is needed.
What happens if the power fails during a Claude Code job?
The job stops. The tokens spent up to that point are still charged (you've used the compute). When the machine comes back online, it doesn't automatically resume, you'd need to trigger the job again. This is why structured run history is valuable (OpenHelm stores what succeeded and what failed so you don't retry completed work).
Can I run multiple Claude Code jobs in parallel?
Technically yes, but it's usually not a good idea. Multiple processes on the same machine can cause resource contention, and troubleshooting becomes harder. If you need multiple concurrent jobs, consider multiple Mac minis rather than overloading a single machine.
How do I prevent my ISP from cutting internet during long jobs?
Long-running Claude Code jobs will maintain an active connection to the Anthropic API. Most ISPs won't cut a connection for extended duration, but it's worth testing your specific setup with a short 1-hour job first to confirm.
What's the difference between a 24/7 setup and just scheduling regular jobs?
24/7 means the machine is always on and available for immediate execution. Regular scheduling (cron) fires jobs on a timetable. Most developers use both: the machine runs 24/7, and jobs are scheduled on a timetable (nightly, weekly) when they start.
More from the blog
OpenHelm vs runCLAUDErun: Which Claude Code Scheduler Is Right for You?
A direct comparison of the two most popular Claude Code schedulers, how each works, what each costs, and which fits your workflow.
Claude Code vs Cursor Pro: Real Developer Cost Comparison
An honest look at what developers actually spend on Claude Code, Cursor Pro, and GitHub Copilot, and how to get the most from each.