Home/Advanced Claude Code Patterns/Episode 2
AdvancedEpisode 2 of 412 min

Schedule Automations with Claude Code

Run your workflows on a schedule — daily reports, weekly summaries.

Scheduling Automations

You've built automations that work. Now let's make them run automatically — every day, every week, whenever you need them, without you lifting a finger.

The concept

Scheduling means telling your computer: "Run this command at this time." Your computer handles the rest, even while you sleep.

Every operating system has a built-in scheduler:

  • Mac: launchd (or the simpler cron)
  • Linux: cron
  • Windows: Task Scheduler

We'll cover each one.

What you can schedule

Anything you can run from the terminal. If your workflow is:

bash
cd ~/weekly-report
claude "Generate this week's sales report"

You can schedule that exact command to run every Monday at 8am.

Scheduling on Mac with cron

Cron is the simplest option for Mac users. Open Terminal and type:

bash
crontab -e

This opens a file where you add scheduled tasks. The format is:

minute hour day-of-month month day-of-week command

Example: Run every Monday at 8am:

0 8 * * 1 cd ~/weekly-report && claude "Generate this week's sales report" > ~/weekly-report/output/latest.md 2>&1

Breaking it down:

  • 0 8 = at 8:00 (0 minutes, 8 hours)
  • * * = any day of month, any month
  • 1 = Monday (0=Sunday, 1=Monday, etc.)
  • The command: change to folder, run Claude, save output

Example: Run every day at 9am:

0 9 * * * cd ~/daily-briefing && claude "Generate today's briefing" > ~/daily-briefing/output/briefing.md 2>&1

Example: Run first of every month:

0 9 1 * * cd ~/monthly-report && claude "Generate monthly summary" > ~/monthly-report/output/monthly.md 2>&1

Save and exit (in vim: press Escape, type :wq, press Enter).

Scheduling on Mac with launchd

For more robust scheduling, use launchd. Create a plist file:

bash
nano ~/Library/LaunchAgents/com.me.weeklyreport.plist

Add this content:

xml
<?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.me.weeklyreport</string>
    <key>ProgramArguments</key>
    <array>
        <string>/bin/bash</string>
        <string>-c</string>
        <string>cd ~/weekly-report && claude "Generate this week's report"</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>8</integer>
        <key>Minute</key>
        <integer>0</integer>
        <key>Weekday</key>
        <integer>1</integer>
    </dict>
</dict>
</plist>

Load it:

bash
launchctl load ~/Library/LaunchAgents/com.me.weeklyreport.plist

Scheduling on Linux with cron

Same as Mac. Open your crontab:

bash
crontab -e

Add your schedule:

0 8 * * 1 cd ~/weekly-report && claude "Generate report" > ~/weekly-report/output/latest.md 2>&1

Scheduling on Windows with Task Scheduler

  1. Search for "Task Scheduler" in the Start menu
  2. Click "Create Basic Task"
  3. Name it (e.g., "Weekly Sales Report")
  4. Choose trigger: Weekly, select Monday, set time to 8:00 AM
  5. Choose action: "Start a program"
  6. Program: cmd
  7. Arguments: /c cd C:\Users\You\weekly-report && claude "Generate report"
  8. Finish

For PowerShell users, use powershell instead of cmd:

powershell -Command "cd ~\weekly-report; claude 'Generate report'"

Making scheduled tasks reliable

Always use full paths:

Instead of ~/weekly-report, use /Users/yourname/weekly-report. Scheduled tasks sometimes run in a different context.

Log the output:

Add > output.log 2>&1 to capture what happens. If something fails, you can check the log.

Test manually first:

Before scheduling, run the exact command in your terminal. If it works manually, it'll work scheduled.

Handle errors:

If your automation might fail (API down, file missing), add checks:

Check if the input file exists before processing. If not, create an error.md explaining the file was missing.

Notification when done

You might want to know when a scheduled task completes. Add a notification:

Mac (terminal-notifier):

bash
brew install terminal-notifier
# Then add to your command:
&& terminal-notifier -title "Report Ready" -message "Weekly report generated"

Or send yourself an email by including that in your automation:

After generating the report, draft an email to me summarizing the key points.

Example: fully automated weekly pipeline

Here's a complete scheduled workflow:

The command (saved as a script for clarity):

Create ~/scripts/weekly-sales.sh:

bash
#!/bin/bash
cd ~/sales-pipeline
claude "Generate the weekly pipeline review. Read all CSVs in /input. Save report to /output/pipeline_$(date +%Y-%m-%d).md"
terminal-notifier -title "Pipeline Report" -message "Ready in ~/sales-pipeline/output"

Make it executable:

bash
chmod +x ~/scripts/weekly-sales.sh

The schedule (cron):

0 8 * * 1 ~/scripts/weekly-sales.sh >> ~/logs/weekly-sales.log 2>&1

Every Monday at 8am: run the script, log the output, notify when done.

Debugging scheduled tasks

If your scheduled task isn't working:

  1. Check the logs — Did it run at all? What error appeared?
  2. Check paths — Use absolute paths everywhere
  3. Check permissions — Can the scheduler access the files and run the commands?
  4. Test manually — Run the exact command yourself

Next up

Scheduled automations are powerful, but they can fail silently. In the next lesson, you'll learn about error handling — what to do when things go wrong, how to make your automations more resilient, and how to debug issues quickly.

Connect to APIs Using Claude CodeNext: Handle Errors in Claude Code Workflows