Scheduled Tasks for Claude Code and Codex: What Runs While Your Mac Sleeps

We scheduled a headless Claude Code run with launchd, watched it fix a regression on its own branch, and checked what each scheduler does about sleep, missed runs and repeats.

21 min read

To run Claude Code or Codex on a schedule, choose the scheduler by where the work has to happen. If the task only needs what's on GitHub, use a cloud scheduler: Claude Code's cloud scheduled tasks or a Codex scheduled task on ChatGPT web keep running while your laptop is closed. If it needs files on your machine, use Claude's Desktop app, the ChatGPT desktop app, or an OS scheduler such as launchd or cron that runs claude -p or codex exec. A sleeping computer then delays or skips the run. Whichever you pick, have the agent work on its own branch and write a report, and merge only after you've reviewed it.

A ghost coding assistant works by lamplight beside a clock, calendar, and completed change ready for morning review.

We checked every scheduler below against its vendor's documentation on November 15, 2026. We ran one recipe for real: a launchd job on macOS 26.4.1 that started Claude Code 2.1.325 headless, let it fix a failing test on its own branch, and left a report. We also ran the Codex version of the same script once by hand. Everything else is documented, not run, and labelled that way. Agentastic publishes this guide. Its own scheduled tasks are described from the app's documentation and source code, not from a run.

The short answer#

Where a scheduler runs decides most of what follows: whether your laptop has to be awake, and whether the agent can see your local files.

SchedulerRuns onNeeds your computer onSees local files
Claude Code cloud scheduled tasksAnthropic's cloudNoNo, a fresh clone from GitHub
Claude Desktop scheduled tasksYour computerYes: app open, computer awakeYes
/loop in a Claude Code sessionYour computer, inside one sessionYes: session runningYes
Codex scheduled tasks, ChatGPT webOpenAI's cloudNoNo
Codex scheduled tasks, ChatGPT desktop appYour computer, for local projectsYes: app runningYes
launchd or cron running claude -p or codex execYour computer or a serverYes, that machineYes
GitHub Actions with Claude's or OpenAI's actionGitHub's runnersNoNo, a checkout
Agentastic, local taskYour MacYes: app running, Mac awake, screen onYes
Agentastic, task on an SSH remote machineYour remote hostNo, but the host must be upYes, on the host

The second question is what happens when a run can't start on time. This is where the schedulers differ most, and most guides skip it.

SchedulerTime passes while asleep or closedPrevious run still goingShortest interval
Claude Code cloudRuns anywayNot documented1 hour
Claude DesktopSkipped; one catch-up run for the latest missed time in the past 7 daysSkipped1 minute if Claude sets it, 1 hour in the form
/loopNo catch-up for missed timesFires once when Claude is idle1 minute
Codex scheduled tasksNot documentedNot documentedMinutes, for a task inside a chat
launchd StartCalendarIntervalOne run on wake, however many were missed; none if the Mac was shut downYour script's lock decides1 minute
cronSkippedYour script's lock decides1 minute
Agentastic, localOne run once the app can start itWaits; one run at a time per task1 minute
Agentastic, SSH remoteOne catch-up run after the host's server restartsOne run at a time per task1 minute

Sources are linked in each section below. The Agentastic rows come from its source code: the scheduler turns any number of missed times into one run, and the remote server queues one catch-up run when it restarts.

Which one to use#

  • The laptop will be closed and the job only needs GitHub: a Claude Code cloud scheduled task, or a Codex scheduled task on ChatGPT web. Both start from a fresh copy of the repository.
  • The job needs local files, a local database or work you haven't pushed: Claude Desktop scheduled tasks, the ChatGPT desktop app, or launchd or cron on that machine. Keep the computer awake at the scheduled time, or accept a late or skipped run.
  • You want one setup for Claude Code and Codex, kept in version control: an OS scheduler and a script, like the recipe below. The script owns the lock, the branch and the report, so switching agents changes one block.
  • You want a check every few minutes while you work: /loop in the Claude Code session you already have open.
  • The job should comment on pull requests or run with your CI: GitHub Actions with Claude Code's action or OpenAI's Codex action.
  • You already run your agents in Agentastic, or the job has to outlive your laptop on your own server: Agentastic scheduled tasks, locally or on an SSH remote machine.

Claude Code's own schedulers (documented, not run)#

Anthropic documents three ways to repeat Claude Code work without a script. We read all three on November 15, 2026; Anthropic's comparison has a side-by-side table.

Cloud scheduled tasks#

Cloud scheduled tasks, formerly called routines, run on Anthropic-managed cloud machines, so they keep going when your computer is off. They're a research preview on the Pro, Max, Ultra, Team and Enterprise plans. Besides a schedule, a task can start from an HTTP call to its API endpoint or from a GitHub event. You manage them at claude.ai/code/routines or with /schedule in the CLI, which needs a claude.ai login rather than an API key.

What matters for unattended work:

  • Interval: once an hour at most. Five-field cron expressions are read as UTC unless they start with CRON_TZ=. A run set for exactly 9:00 can start several minutes late, so Anthropic suggests a time like 9:07.
  • Where the work happens: every run clones the repository again, starts from the default branch, and pushes to a branch prefixed claude/ unless the prompt says otherwise. Branch protection on GitHub is how you limit what it can push.
  • Permissions: runs start in auto mode. An action that matches an ask rule, or one that auto mode keeps blocking, puts a permission prompt in the run's session and waits until someone answers it.
  • What "Succeeded" means: only that the session ended without Claude Code reporting a failure. Work it couldn't finish shows up in the transcript, not in the status.
  • GitHub connection: if it's missing or expired, the task skips runs for up to 72 hours, then turns itself off.
  • Limits and cost: 100 scheduled runs an hour per account, and Run now plus API calls share 30 an hour per task. Runs use your plan's usage like an interactive session.

Desktop scheduled tasks#

Desktop scheduled tasks run on your own computer, inside the Claude desktop app, so they can use local files, tools and uncommitted work. They fire only while the app is open and the computer is awake.

  • Missed runs: if the computer was asleep or the app was closed, the run is skipped. When the app starts or the computer wakes, it looks back seven days and starts exactly one catch-up run, for the most recent missed time, with a notification. Anthropic's example: a task set for 9am might run at 11pm.
  • Overlaps: a run is also skipped while the previous run is still going, or while other scheduled tasks are already running.
  • Where it works: by default in the folder you chose, uncommitted changes included. Tick Worktree in the task's edit form to give each run its own worktree.
  • Permissions: each task has its own permission mode, and "always allow" answers are saved per task. Anthropic suggests clicking Run now once to answer the prompts before you rely on the schedule.
  • Staying awake: the app has a keep-awake setting, but closing a laptop's lid still puts it to sleep.

The task's prompt is saved on disk at ~/.claude/scheduled-tasks/<task-name>/SKILL.md, so you can edit it like any other file.

/loop inside a session#

/loop repeats a prompt inside the session you have open, as often as once a minute, in your local time zone. It's meant for keeping an eye on something while you work, not for overnight jobs:

  • Tasks fire only while Claude Code is running and idle. Close the terminal and they stop, unless you've moved the session to the background.
  • There's no catch-up. If a run comes due while Claude is busy, it fires once when Claude is free, not once per missed time.
  • Recurring tasks expire after seven days.
  • Runs are spread out a little: a recurring task can fire up to half its interval late, capped at 30 minutes.

Codex's own schedulers (documented, not run)#

OpenAI renamed Codex automations to scheduled tasks. We read the documentation on November 15, 2026.

  • Where you create them: in the ChatGPT desktop app or on ChatGPT web. All tasks and their runs appear under Scheduled in the desktop app's sidebar, which works as an inbox with an unread marker for runs that need you.
  • Local or cloud: in the desktop app a task can work on a local project, either in the project folder or in its own worktree. OpenAI's instruction is to keep the computer on and the app running when a task needs local files. Tasks on the web can't use a local folder.
  • Two kinds: a standalone task starts a new chat for every run and reports in Scheduled. A task inside an existing chat returns to that chat with its context, and can repeat every few minutes. Custom schedules accept an iCalendar RRULE.
  • Event triggers: on ChatGPT web and mobile, eligible plans can also start a task from a Gmail, Slack or GitHub event instead of a clock.
  • Permissions: runs are unattended and use your default sandbox settings. In read-only mode, anything that edits files or reaches the network fails, so OpenAI suggests the narrowest access that lets the task succeed.
  • Cleanup: frequent schedules create a lot of worktrees. Archive runs you don't need, and don't pin runs unless you mean to keep their worktrees.

OpenAI's documentation doesn't say what happens to a run that comes due while the computer is asleep.

Codex CLI can't create or manage scheduled tasks. OpenAI points CLI users to the web or desktop app for that, and suggests using the CLI to prepare and test the prompt first. To schedule the CLI itself, run codex exec from launchd, cron or a CI job, as in the recipe below. OpenAI's dots are a different product: an always-on agent with its own cloud computer that keeps working while yours is off. Access depends on your plan and region.

Recipe: a nightly agent run with launchd (tested)#

This is the recipe we ran on November 15, 2026. A small Python repository had a commit that broke a test. At the scheduled time, launchd started a script. The script made a fresh worktree on a new branch, ran Claude Code headless to find and fix the failure, committed the result, and wrote a report for the morning. Nothing was pushed or merged.

You need macOS, git, jq, Claude Code signed in, and whatever your tests need (Python here). The job lives in its own folder, outside the repository:

nightly/ nightly.sh # the wrapper: lock, branch, agent, report prompt.md # what the agent should do settings.json # what the agent may not do dev.example.nightly-agent.plist # when launchd starts it

The design rule: the script owns git, the agent owns the fix. The script creates the branch, commits and writes the report, so the agent never needs permission to commit or push, and a confused run can't touch anything but its own branch.

The prompt#

Tell the agent that nobody is there to answer, what "done" looks like, and what to leave to the script:

You are running unattended as a scheduled nightly check. Nobody can answer questions. 1. Run `python3 -m unittest -q`. 2. If every test passes, change nothing and reply "No failures." 3. If a test fails, find the cause. Check `git log -p -3` for the change that broke it. Fix the code, not the tests, then run the tests again. 4. Do not commit, push, or create branches. The wrapper script does that. 5. End with a short report: what failed, the cause (file and line), what you changed, and the final test result.

What the agent may not do#

settings.json denies the actions the script keeps for itself. Claude Code checks deny rules first, and no allow rule can override one (permission rules). A shell rule such as Bash(git push *) doesn't catch the same program called by its full path or inside sh -c, though, so treat these rules as guard rails, not a sandbox. Branch protection on your git host is the backstop.

json
{ "permissions": { "deny": [ "Bash(git push *)", "Bash(git commit *)", "Bash(gh *)", "SendMessage", "ListAgents" ] } }

The last two stop the job from messaging other Claude Code sessions on the same machine. Drop them if you want it to report to a session you have open.

The wrapper script#

This is nightly.sh exactly as it ran in our final test:

bash
#!/bin/bash # nightly.sh: one unattended Claude Code pass on a fresh branch, left for review. # Usage: nightly.sh /path/to/repo set -uo pipefail REPO="$(cd "${1:?usage: nightly.sh /path/to/repo}" && pwd)" JOB="$(cd "$(dirname "$0")" && pwd)" DAY="$(date +%Y-%m-%d)" BRANCH="nightly/$DAY" WORKTREE="$JOB/runs/$DAY" LOG="$JOB/logs/$DAY" LOCK="$JOB/.lock" echo "$(date '+%F %T') start; inherited PATH=$PATH" export PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin" mkdir -p "$JOB/runs" "$JOB/logs" "$JOB/reports" # One run at a time. mkdir is atomic, so a second copy stops here. if ! mkdir "$LOCK" 2>/dev/null; then if kill -0 "$(cat "$LOCK/pid" 2>/dev/null)" 2>/dev/null; then echo "another run is still going; exiting" exit 0 fi echo "removing a stale lock" rm -f "$LOCK/pid" rmdir "$LOCK" mkdir "$LOCK" || exit 1 fi echo $$ > "$LOCK/pid" trap 'rm -f "$LOCK/pid"; rmdir "$LOCK"' EXIT # One run per day: the report doubles as the stamp. A second trigger does nothing. if [ -e "$JOB/reports/$DAY.md" ]; then echo "already ran today; see reports/$DAY.md" exit 0 fi # A fresh worktree from main, so the run never touches work in progress. # If a crashed run left the branch behind, this fails instead of piling on. git -C "$REPO" worktree add --quiet -b "$BRANCH" "$WORKTREE" main || exit 1 cd "$WORKTREE" || exit 1 # The agent. Nobody can answer a prompt, so anything that would ask is denied. claude -p "$(cat "$JOB/prompt.md")" \ --model sonnet \ --permission-mode auto --permission-prompts none \ --setting-sources project --settings "$JOB/settings.json" --strict-mcp-config \ --max-budget-usd 2 \ --output-format json > "$LOG.json" 2> "$LOG.err" AGENT_EXIT=$? # The script commits, not the agent, and records whether the tests pass. if python3 -m unittest -q > "$LOG.tests" 2>&1; then TESTS=pass; else TESTS=fail; fi git add -A git commit --quiet -m "Nightly agent run $DAY (tests: $TESTS)" || echo "no changes to commit" # A report to read in the morning. { echo "# Nightly run $DAY" echo echo "- Branch: $BRANCH (worktree: $WORKTREE)" echo "- Agent exit code: $AGENT_EXIT" echo "- Tests after the run: $TESTS" echo "- Cost reported by Claude Code: \$$(jq -r '.total_cost_usd // "unknown"' "$LOG.json")" echo echo "## Changes" echo git diff --stat main...HEAD echo echo "## Agent summary" echo jq -r '.result // "No result; see the .err log."' "$LOG.json" } > "$JOB/reports/$DAY.md" echo "$(date '+%F %T') done; report: $JOB/reports/$DAY.md"

The lines that matter most for unattended runs:

  • export PATH=…: launchd starts jobs with PATH=/usr/bin:/bin:/usr/sbin:/sbin. Our log line showed exactly that. Claude Code's native installer puts claude in ~/.local/bin, and Homebrew's tools live in /opt/homebrew/bin, so without this line the job can't find either.
  • The lock and the stamp: mkdir either creates the lock folder or fails, with no gap in between, so two copies can't both get past it. A lock left by a crashed run is removed when its process ID is no longer alive. The day's report file then stops a second run on the same day.
  • --permission-mode auto --permission-prompts none: auto mode lets a classifier approve routine actions. In print mode with nothing attached to answer prompts, an action that would still ask is denied anyway. --permission-prompts none, in Claude Code 2.1.259 and later, also tells Claude that nobody can approve it, so it doesn't keep retrying, and removes tools that ask a person a question (headless mode). Auto mode needs a supported model, which is why the script pins --model sonnet.
  • --setting-sources project and --strict-mcp-config: your personal settings, hooks and MCP servers stay out of the run. The repository's own .claude/settings.json, hooks included, still applies, and print mode shows no trust dialog, so only schedule repositories you trust.
  • --max-budget-usd 2: a spending cap for this run. It only works in print mode.
  • --output-format json: the result arrives as JSON, with the agent's final message in result and Claude Code's cost estimate in total_cost_usd.

The launchd job#

A LaunchAgent runs as you, inside your login session, so Claude Code finds the login you already made. StartCalendarInterval is the key to use. Apple's guide to scheduling timed jobs explains that, unlike cron, launchd starts a calendar job on wake if the Mac was asleep at the scheduled time. If the Mac was shut down, the job waits for the next scheduled time. The launchd.plist manual page on macOS 26.4.1 adds that several missed times are merged into one run.

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>dev.example.nightly-agent</string> <key>ProgramArguments</key> <array> <string>/bin/bash</string> <string>/Users/you/nightly/nightly.sh</string> <string>/Users/you/src/shop</string> </array> <key>StartCalendarInterval</key> <dict> <key>Hour</key> <integer>3</integer> <key>Minute</key> <integer>7</integer> </dict> <key>StandardOutPath</key> <string>/Users/you/nightly/launchd.log</string> <key>StandardErrorPath</key> <string>/Users/you/nightly/launchd.log</string> </dict> </plist>

Ours had scratch-folder paths and afternoon start times so we could watch it fire. launchd passes ProgramArguments straight to the program with no shell in between, so write full paths, not ~ or $HOME.

Load it, check it, run it once on demand, and remove it:

bash
plutil -lint ~/nightly/dev.example.nightly-agent.plist launchctl bootstrap gui/$(id -u) ~/nightly/dev.example.nightly-agent.plist launchctl print gui/$(id -u)/dev.example.nightly-agent | grep -E 'state|runs|last exit' launchctl kickstart gui/$(id -u)/dev.example.nightly-agent # run now, outside the schedule launchctl bootout gui/$(id -u)/dev.example.nightly-agent # unload it

A job you bootstrap from your own folder is gone after you log out or restart. To keep it, copy the plist into ~/Library/LaunchAgents, which launchd loads at every login. We bootstrapped ours from a scratch folder and booted it out after each test, so nothing stayed scheduled.

What happened#

We ran the job twice from launchd, each time on a different broken commit. The second run used the final script shown above.

Run 1Run 2
The broken commit<= changed to < in restock_neededmax(0, …) removed from reorder_quantity
launchd started it14:31:05, for 14:3114:37:05, for 14:37
Agent time15.8 s, 6 turns7.8 s, 5 turns
Tokens: input, cache writes, cache reads, output10, 8,849, 84,849, 6978, 7,002, 68,713, 556
Claude Code's cost estimate$0.05$0.04
Permission denials00
OutcomeFixed; 5 of 5 tests pass; one commit on nightly/2026-11-15The same

Both runs used Sonnet 5.5 through --model sonnet. The cost figure is Claude Code's own estimate at list prices; on a Pro, Max or Ultra plan the usage comes out of your subscription instead (Anthropic's cost guide).

This is the report run 1 left behind:

# Nightly run 2026-11-15 - Branch: nightly/2026-11-15 (worktree: /tmp/seo-sched-demo.cYTt9G/nightly/runs/2026-11-15) - Agent exit code: 0 - Tests after the run: pass - Cost reported by Claude Code: $0.0508709 ## Changes stock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ## Agent summary **Failed:** `test_stock.RestockTests.test_threshold_is_inclusive`. It expected `["mugs"]` for a quantity of 5 at threshold 5 and got `[]`. **Cause:** The latest commit, fe63166 "Simplify restock filter", changed `<=` to `<` in `restock_needed` at `stock.py:6`. That made the threshold exclusive, which contradicts the docstring ("at or below the threshold"). **Change:** I restored `quantity <= threshold` in `stock.py`. I didn't touch the tests, and nothing is committed. **Result:** All 5 tests pass.

Then we tried to make it run twice. A second trigger on the same day printed already ran today; see reports/2026-11-15.md and exited without starting Claude Code. While the lock was held by a running process, a new copy printed another run is still going; exiting. With a lock left behind by a dead process, it printed removing a stale lock and carried on.

We didn't put the Mac to sleep across a scheduled time. The sleep behavior in the tables above comes from Apple's documentation, not from our test.

Review, then merge#

The run leaves a branch and a worktree. Read the diff, run the tests yourself, and only then merge:

bash
cd ~/src/shop git log --oneline main..nightly/2026-11-15 git diff main...nightly/2026-11-15 (cd ~/nightly/runs/2026-11-15 && python3 -m unittest -q) git merge --ff-only nightly/2026-11-15 git worktree remove ~/nightly/runs/2026-11-15 git branch -d nightly/2026-11-15

For run 1, the whole diff was one line:

diff
- return sorted(name for name, quantity in items.items() if quantity < threshold) + return sorted(name for name, quantity in items.items() if quantity <= threshold)

On a shared repository, push the branch and open a pull request instead of merging locally, so the change goes through the same review and CI as everyone else's. The agent can't push, so you decide when that happens.

The same job with Codex#

Only the agent block changes. We used a copy of the script with a separate branch name (nightly-codex/<date>), report name and this block, and ran it once by hand against a third broken commit, in a clean environment like launchd's:

bash
CODEX="$HOME/.bun/bin/codex" # use the output of `command -v codex` in your own shell # codex exec never stops to ask; the sandbox decides what it may do. "$CODEX" exec "$(cat "$JOB/prompt.md")" \ --ignore-user-config \ --sandbox workspace-write \ --ephemeral \ --json -o "$LOG.txt" < /dev/null > "$LOG.jsonl" 2> "$LOG.err" AGENT_EXIT=$?

With Codex CLI 0.167.2 the whole run took 21 seconds. A commit had dropped the sorted() call, so names came back in insertion order. Codex restored the call and left this summary in $LOG.txt:

- Failed: `test_sorted_by_name`. - Cause: commit `36402c8` removed sorting in `stock.py:6`, returning items in insertion order. - Fix: restored `sorted(...)`; tests unchanged. - Final result: all 5 tests pass. No commits or branches created.

Codex reports tokens rather than a price: 80,844 input, 71,808 of them cached, and 460 output, in the turn.completed event of the JSON stream. The flags, from OpenAI's non-interactive mode guide:

  • --sandbox workspace-write: codex exec is read-only by default. Workspace-write lets it edit the worktree, but commands that write elsewhere or reach the network fail.
  • --ignore-user-config: skips your ~/.codex/config.toml, so your personal MCP servers and notification scripts stay out of the run. Sign-in still comes from your Codex home folder.
  • --ephemeral: doesn't save the session to disk.
  • < /dev/null: if standard input is a pipe, codex exec reads it as extra context. Closing it keeps the script from waiting on input when another program starts it.

Two problems we hit are worth knowing before you schedule the CLI. This Mac had a broken copy of codex in /opt/homebrew/bin that the script's PATH would have found first, so the script calls the working copy by its full path. And that working copy is a Node.js launcher: with launchd's default PATH it failed with env: node: No such file or directory, which is one more reason the script sets its own PATH.

The cron version (not run)#

On a Linux server, or if you prefer cron on a Mac, the same script works from a crontab line. We didn't run this one:

7 3 * * * /bin/bash /home/you/nightly/nightly.sh /home/you/src/shop >> /home/you/nightly/cron.log 2>&1

cron skips any time that passes while the machine is asleep or off, and Apple's guide calls cron deprecated on macOS in favor of launchd. On an always-on server that doesn't matter, and the lock and the stamp do the same job. Sign in to Claude Code or Codex on the server first, and check that the job's user can reach those credentials without a desktop session.

Keep the computer awake for the run (documented, not run)#

Every scheduler that runs on your own computer depends on that computer being awake. Three macOS tools help, and we tried none of them in this test:

  • caffeinate -i keeps the Mac from idle-sleeping while a command runs. Put /usr/bin/caffeinate and -i in front of /bin/bash in ProgramArguments and a long run won't be cut short by idle sleep.
  • pmset repeat can wake the Mac on a schedule, for example sudo pmset repeat wakeorpoweron MTWRFSU 03:00:00 for a job at 3:07. The pmset manual allows only one repeating wake-or-power-on event and one repeating sleep-or-shutdown event at a time.
  • App settings: Claude's desktop app has a keep-awake setting for its scheduled tasks. Agentastic's Keep the Mac awake while agents work stops idle sleep while an agent is already working, which helps a run finish rather than start. In both apps, closing a laptop's lid still puts it to sleep.

If the machine must be reachable every night, a small always-on Mac or a Linux server is simpler than any of these.

Credentials for unattended runs#

A scheduled run fails fast if its sign-in doesn't work, and an interactive login prompt in an unattended job just hangs or errors. What each tool reads:

ToolWhat an unattended run usesWatch out for
Claude Code, your own MacThe login you made with /login, kept in the macOS KeychainA LaunchDaemon runs outside your login session; use a LaunchAgent
Claude Code, CI or a serverclaude setup-token prints a one-year token; set it as CLAUDE_CODE_OAUTH_TOKENNeeds a Pro, Max, Ultra, Team or Enterprise plan; the token is printed once, not saved
Claude Code with --bareANTHROPIC_API_KEY or an apiKeyHelper scriptBare mode ignores your subscription login and the setup token
Codex CLIThe login saved by codex login, in your Codex home folderTreat ~/.codex/auth.json like a password; don't use it on public CI
Codex CLI, one runCODEX_API_KEY set for that codex exec command onlyBilled to your OpenAI Platform account; never export it for the whole job, because your tests run repository code
Claude Code cloud tasksNothing local; a GitHub connection on your accountWithout it, runs are skipped for up to 72 hours, then the task turns off

Sources: Anthropic's authentication and headless mode pages, and OpenAI's non-interactive mode and authentication pages.

Put a review gate on every scheduler#

A scheduled agent should end with something you can read, never with a merge. Every option above can be set up that way:

  • Claude Code cloud tasks push to claude/ branches. Protect main on GitHub so nothing else is possible, and read the run's transcript, because "Succeeded" doesn't mean the work got done.
  • Claude Desktop tasks work in your folder by default. Tick Worktree so each run's changes stay apart from yours.
  • Codex scheduled tasks can run in their own worktree, and every run with findings lands in the Scheduled inbox.
  • Your own script decides everything, which is the point of the recipe: a new branch per day, a report, no push, and you merge.
  • Agentastic starts each scheduled agent in its own worktree and branch, and the run opens as an ordinary agent session that you review like any other.

If the job fixes CI failures, it needs more than a branch: a record of which failures it already tried, a limit on attempts, and a way to tell flaky infrastructure from a real bug. Our scheduled CI-failure agent guide covers that, so we don't repeat it here.

Scheduled tasks in Agentastic#

Agentastic schedules agent runs too. We haven't run it for this guide; this section comes from the scheduled tasks documentation and the app's source code, checked on November 15, 2026.

You compose the run in Agent Home the way you would start it now: repository, base branch, agent, environment, prompt, attachments and plugins. Then choose Schedule This Task… instead of sending. The task keeps a snapshot of all of that, so a later run starts the same way even if you change your defaults. Each run launches a whole agent session, with its own worktree and branch.

  • Schedules: once, every N minutes (one minute at least), daily, weekly, monthly or a cron expression, each with a time zone. Presets such as Find critical bugs start you off with a prompt and a default time.
  • Any agent: the snapshot names the agent, so the same scheduler runs Claude Code, Codex or any other agent Agentastic supports. A task can also run a plain shell command.
  • Memory between runs: each task can keep notes outside the repository, so tonight's run knows what last night's already reported.
  • Missed runs and overlaps: if any number of scheduled times pass while the app is closed or the Mac is asleep, the app's scheduler makes one run when it can, and records the original due time. Each task runs one at a time by default, so a run that comes due while the previous one is still going waits its turn.
  • What "Launched" means: the run history records each run as pending, running, launched, waiting, completed, failed, cancelled, retrying or skipped. Launched means the agent started, not that it finished the job, and Waiting means it needs a person, for example to sign in.

Local tasks run inside the app, so Agentastic has to be running. Agent launches also wait until the Mac is awake with its screen on, or has no display connected at all; shell tasks don't wait for the screen. On a laptop whose screen sleeps at night, a 3:00 agent run starts when you wake the screen.

For runs that mustn't depend on your Mac, add the repository from an SSH remote machine. Its scheduled tasks are stored and run by Agentastic's server on that host, so they fire whether or not your Mac is awake. The host needs the agent's CLI installed and signed in, just like the recipe above. If the host's server restarts, a run it interrupted is marked failed and one catch-up run is queued for the time it missed. Plugins, task memory, event triggers and attachments aren't available for remote runs yet, and remote Codex tasks deny any request that would need a person to approve it.

Shell tasks can be created from the terminal with the dev task CLI; agent tasks are composed in Agent Home:

bash
dev task create \ --name "Nightly tests" \ --command "python3 -m unittest -q" \ --schedule daily --hour 3 --minute 7

Troubleshooting#

SymptomLikely causeFix
claude: command not found or env: node: No such file or directory in the job loglaunchd's short default PATHSet PATH at the top of the script, or call the agent by its full path
The job never ranIt isn't loaded, or the Mac was shut down at that timelaunchctl print gui/$(id -u)/<label> shows its state, run count and last exit code
Two runs on the same dayNothing stops a second triggerA lock and a once-a-day stamp, as in the recipe
The job hangs until you kill itIt's waiting on a permission prompt or on standard input--permission-prompts none for Claude Code; < /dev/null for codex exec
Codex can't edit filescodex exec is read-only by defaultAdd --sandbox workspace-write
fatal: a branch named 'nightly/…' already existsA crashed or unfinished run left its branchReview that branch, then merge or delete it; the script won't build on top of it
A Desktop task set for 9am ran at nightA catch-up run after the computer wokeExpected; keep the computer awake, or use a cloud task
A cloud task says Succeeded but nothing changedSucceeded only means the session didn't report a failureRead the run's transcript
An Agentastic agent run waits overnightAgent launches wait for an awake Mac with its screen onWake the screen, or move the repository to an SSH remote machine

Sources#

All checked on November 15, 2026.

To schedule agents next to the ones you already run, download Agentastic for macOS.

Frequently asked questions#

Can Claude Code run tasks on a schedule?#

Yes, in four ways. Cloud scheduled tasks (formerly routines) run on Anthropic's cloud on Pro, Max, Ultra, Team and Enterprise plans. Desktop scheduled tasks run on your computer while the Claude app is open and the computer is awake. /loop repeats a prompt inside an open session. Or an OS scheduler such as launchd or cron runs claude -p.

Does Codex have scheduled tasks?#

Yes. Scheduled tasks, formerly called automations, run from the ChatGPT desktop app or ChatGPT web, and their results land in the Scheduled view. Codex CLI has no scheduler of its own, so for the CLI you run codex exec from launchd, cron or a CI job.

What happens to a scheduled agent when my laptop is asleep?#

It depends on the scheduler. Cloud tasks run anyway. Claude's Desktop app skips the run, then starts one catch-up run on wake for the most recent missed time in the past seven days. launchd's StartCalendarInterval also runs once on wake, while cron skips missed times. /loop doesn't make up missed runs.

How do I stop a scheduled agent from running twice?#

Use a lock so two copies can't overlap, and a once-a-day stamp so a second trigger does nothing. Our script uses mkdir as an atomic lock and treats the day's report file as the stamp. A second trigger on the same day exited without starting an agent.

How should an unattended Claude Code or Codex job sign in?#

Claude Code reuses your saved login when the job runs as you; on macOS that login is in the Keychain, and our launchd job needed nothing extra. For CI, claude setup-token prints a one-year token for CLAUDE_CODE_OAUTH_TOKEN. codex exec reuses the saved CLI login, or takes CODEX_API_KEY for a single run.

Should a scheduled coding agent merge its own changes?#

No. Have it work on its own branch and write a report, deny git push in its permissions, and merge after you have read the diff and rerun the tests. Claude's cloud scheduled tasks push to branches prefixed claude/ by default, so branch protection still applies.

Do Agentastic scheduled tasks run when the app is closed?#

Local scheduled tasks run inside the Agentastic app, so it has to be running, and agent launches wait until the Mac is awake with a usable display. A missed time gets one run as soon as the app can start it. Tasks on an SSH remote machine are run by that host's server whether or not your Mac is awake.