- Desktop app = unreliable. A task scheduled inside it only runs while the window is open and the machine is awake. Closed window = doesn't run, with no warning.
- Headless mode (claude -p) = the foundation. Non-interactive execution of a single instruction from start to finish, exactly what a scheduler needs.
- OS scheduler = the reliability. launchd (macOS), cron/systemd (Linux), Task Scheduler (Windows). Independent, runs in the background.
A scheduled task configured inside the Claude desktop app only runs while the app is open. The reliable way to run a daily automated task is Headless mode (claude -p) triggered by your OS scheduler, launchd, cron, or Task Scheduler, which keeps running in the background regardless of whether the window is open.
To make Claude Code run a task automatically every day, even when the app is closed, don't rely on a scheduled task inside the desktop app (it only runs while the window is open). Instead, run Claude in Headless mode with the claude -p command (a single instruction, no interactive window), and schedule it with your operating system's native scheduler: launchd on macOS, cron or systemd on Linux, and Task Scheduler on Windows. The scheduler fires the command at the time you set regardless of the app. The only requirement is that the machine is on. If you need it to run even when the machine is off, you move to the cloud (Cloud Routines).
In short (TL;DR)
- Desktop app = unreliable. A task scheduled inside it only runs while the window is open and the machine is awake. Closed window = doesn't run, with no warning.
- Headless mode (
claude -p) = the foundation. Non-interactive execution of a single instruction from start to finish, exactly what a scheduler needs. - OS scheduler = the reliability.
launchd(macOS),cron/systemd(Linux), Task Scheduler (Windows). Independent, runs in the background. - The requirement: The machine must be on. Running while the machine is off requires the cloud, Cloud Routines (requires GitHub).
- Safety: Restrict tools (
--allowedTools), steps (--max-turns) and budget, and run in an isolated directory.
Why a regular desktop scheduled task isn't reliable enough
The Claude desktop app can run "scheduled tasks," and that's convenient for experimentation, but there's one big catch: the task runs inside the app process itself. In practice:
- Closed the window? The task won't run.
- The machine went to sleep? It won't run.
- The app crashed or updated? It won't run, and you'll get no notification that anything was missed.
For real automation, "summarize my emails every morning at 8," "run a site check every night," you need a mechanism that doesn't care whether you've opened the app or not. That mechanism already exists on every machine: the operating system scheduler. It's an independent component running in the background, whose sole job is "run this thing at this time," and it depends on no app being open. All that remains is to have it launch Claude in a form suited for the background, namely Headless mode.
What Headless mode is (claude -p)
Normally you run claude and an interactive session opens in the terminal. That's great for working in front of a screen, but pointless for a scheduler, since there's no human there to type.
Headless mode solves that. You add the -p flag (short for print / prompt) and pass the instruction as a single string:
claude -p "Summarize the last three emails and save to daily-summary.md"
Claude receives the instruction, executes it from start to finish (including tool calls, file writes, MCP calls, based on what you've permitted), returns output to stdout, and exits. No window, no mid-task questions, no waiting. This is exactly the form a scheduler can invoke on its own: one command, in and out. If you want to go deeper into the world of automations and routines in Claude Code, Headless mode is the cornerstone of all of them.
The runner script: the template
Rather than running a bare command from the scheduler, it's worth wrapping it in a small runner script. That gives you one place to manage the path, variables, and restrictions, and a place to write logs. A basic template for macOS/Linux:
#!/bin/bash
# ~/automations/daily-summary.sh
export PATH="$HOME/.local/bin:/usr/local/bin:$PATH"
cd "$HOME/automations/workspace" || exit 1
claude -p "Review today's tasks and write a summary to report.md" \
--allowedTools "Read,Write,Bash" \
--max-turns 12 \
>> "$HOME/automations/logs/daily-$(date +\%F).log" 2>&1
Three points that save headaches: (1) Set PATH explicitly. A scheduler doesn't load your shell profile, and without this it simply won't find the claude command. (2) cd to a fixed, isolated working directory. (3) Redirect output and errors to a log, so you can check after the fact what happened on each run. Once the script works when run manually, connect it to the scheduler.
Scheduling on macOS (launchd)
On macOS the official scheduler is launchd (not cron, which exists but is deprecated on Mac). You define a .plist file in ~/Library/LaunchAgents/, for example com.tzedek.daily-summary.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>com.tzedek.daily-summary</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/Users/you/automations/daily-summary.sh</string>
</array>
<key>StartCalendarInterval</key>
<dict><key>Hour</key><integer>8</integer><key>Minute</key><integer>0</integer></dict>
</dict>
</plist>
Load it once with launchctl load ~/Library/LaunchAgents/com.tzedek.daily-summary.plist, and from that point launchd will run the script every day at 08:00, even if the Claude app is completely closed. If the machine was asleep at the scheduled time, launchd will run the task the moment it wakes up. Important: this still requires the machine to be on (or in a sleep state from which it wakes). A Mac that is fully powered off will not run anything.
Scheduling on Linux (cron / systemd timer)
On Linux there are two ways. The simple one is cron: edit the table with crontab -e and add a single line:
0 8 * * * /home/you/automations/daily-summary.sh
This runs the script every day at 08:00. cron is excellent for servers that are always on (VPS, cloud). The downside: if the machine was off exactly at the scheduled time, cron will not make up the missed run afterward.
The more modern and robust approach is a systemd timer: you define a pair of files, daily-summary.service (what to run) and daily-summary.timer (when). The big advantage is Persistent=true, which causes the timer to complete a missed run when the machine comes back up, exactly what you want for a workstation that isn't always on. In both cases the execution is completely independent of any desktop app.
Scheduling on Windows (Task Scheduler)
On Windows the equivalent mechanism is Task Scheduler. Open it, create a new task (Create Task), and configure:
- Trigger: Daily, at the desired time.
- Action: Start a program, for example
wsl.exerunning a bash script, or directlyclaudewith the parameters. - Settings: Check "Run whether user is logged on or not" so the task runs in the background even when you're not logged in, and "Run task as soon as possible after a scheduled start is missed" to make up any missed run.
The result is the same: Claude Code runs in Headless mode at the time you set, regardless of whether the desktop app is open. Here too, the machine needs to be on at the scheduled time.
Safety: letting the agent run on its own without taking risks
A task that runs on its own, with no human approving each step, requires clear guardrails. Four rules:
--allowedTools, restrict tools. Give only what the task actually needs (for exampleRead,Writeonly for a summary). That way an agent running alone can't suddenly delete files or execute dangerous commands.--max-turns, restrict steps. A ceiling on the number of steps prevents a stuck task from entering a loop that runs for hours and burns tokens.- Budget (
--max-budget-usdetc.). A cost ceiling per run ensures that even a mistake won't surprise you on your bill. - Isolated directory. Always run in a dedicated working directory (the
cdin the runner script), not in your home root or inside a sensitive repo. An autonomous agent needs its own sandbox.
The combination of these four is what turns "an agent that runs on its own" from a recipe for trouble into something you can sleep soundly next to. The full template, the runner script, the launchd/cron/Task Scheduler files, the restrictions, and the logs are packaged as a ready-made kit in the Scheduled Automation Kit, so you can wire up a reliable daily task on your machine without building everything from scratch.
When the cloud is better (Cloud Routines)
All the methods above share one requirement: the machine must be on at run time. That's fine for a server running 24/7, but less so for a laptop you've closed in your bag. If you need a task that runs even when the machine is completely off, the answer is the cloud.
Anthropic offers Cloud Routines, scheduled execution of Claude Code on their infrastructure, with no dependency on any machine of yours. You define a schedule and the task runs in the cloud, at night, while you're on vacation. The cost: it requires connecting a GitHub repository (where Claude works on the code/context), so it's best suited to repo-based workflows. The simple rule: need the task to run only while the machine is already on? A local scheduler (launchd/cron/Task Scheduler) is enough and free. Need reliability even when the machine is off? Cloud Routines.
The bottom line
"An agent that runs on its own every day" isn't magic. It's two components joined together: Headless mode (claude -p) that delivers a single clean execution, and an OS scheduler (launchd, cron/systemd, or Task Scheduler) that fires it at a fixed time with no dependency on an open app. Add safety guardrails (--allowedTools, --max-turns, budget, isolated directory) and the task runs reliably as long as the machine is on. Need more than that, running even when the machine is off, move to Cloud Routines in the cloud. If you want to go deeper, Claude in Hebrew, the central guide and Automations and routines in Claude Code are good places to start. Want me to help you wire up a reliable daily task on your machine, end to end? Book a 1-on-1 private lesson and we'll do it together.
Frequently Asked Questions
How do you get Claude Code to run a task automatically every day, even when the app is closed?
Run Claude Code in headless mode using the claude -p flag (a single instruction, no interactive window), and schedule it with your operating system's scheduler: launchd on macOS, cron or a systemd timer on Linux, and Task Scheduler on Windows. The scheduler fires the command at whatever time you configured, completely independent of the desktop app. The only requirement: your computer has to be on at that moment. If you need tasks to run even when the machine is off, you need the cloud (Cloud Routines).
Why isn't a scheduled task inside the desktop app reliable enough?
Because it runs inside the app's own process. If the window is closed, the computer is asleep, or the app has crashed, the task simply won't run, with no warning whatsoever. An OS-level scheduler (launchd / cron / Task Scheduler) is an independent component that keeps running in the background regardless of whether the app is open.
What is headless mode in Claude Code?
It's a non-interactive way to run Claude Code using the -p flag (for example, claude -p "Summarize the emails"). Instead of opening an interactive session in the terminal, Claude receives a single instruction, executes it to completion, and returns output. That's exactly what a scheduler needs in order to trigger it on its own, with no human sitting in front of the screen.
When is it better to run in the cloud rather than on your own machine? When you need the task to run even if your computer is off or is a laptop you carry around, or when you want full reliability without maintaining a home server. Anthropic offers Cloud Routines, scheduled cloud-based execution of Claude Code. It requires connecting a GitHub repository, but it frees you from depending on a specific machine being powered on.

