You can run an AI coding agent on a schedule on Windows with Task Scheduler and the agent's non-interactive mode. The hard part is not starting the run. It is finding out when a run did not happen. Scheduled agent work fails quietly: the PC was asleep, the task ran as the wrong user, the sign-in expired, or the run stalled, and nothing tells you. This guide shows a working setup and the five settings that turn silent failures into visible ones.

Silent failure is the common complaint

This is not a Windows problem. It shows up on every platform that schedules agents. One user of a desktop assistant reported that every scheduled task had stopped running two weeks earlier, and that restarting the app triggered no catch-up runs (Claude Code issue 66976). On an open-source agent platform, a user wrote that "three agents died within four minutes and nothing restarted them for 3h15m" (Paperclip issue 15461). A developer running agents on a self-hosted automation tool found one had stopped reporting and "nobody noticed for 3 days" (dev.to).

Design for that from the start: every run should leave a record, and a missing record should be loud.

A working setup with Task Scheduler

Step 1. Write a script that runs the agent and logs the result. Claude Code's non-interactive mode is claude -p, which runs a prompt and exits (headless mode).

# C:\agents\morning-review.ps1
$stamp = Get-Date -Format 'yyyy-MM-dd_HHmm'
$log   = "C:\agents\logs\morning-review_$stamp.log"
Set-Location C:\src\myapp

claude -p "Read docs/review-checklist.md and report anything that fails it. Do not change files." `
       --output-format json *> $log

if ($LASTEXITCODE -ne 0) {
    Add-Content C:\agents\logs\FAILED.txt "$stamp morning-review exit $LASTEXITCODE"
}

Step 2. Register the task with the settings that matter.

$action   = New-ScheduledTaskAction -Execute 'pwsh.exe' `
            -Argument '-NoProfile -File C:\agents\morning-review.ps1' `
            -WorkingDirectory 'C:\src\myapp'
$trigger  = New-ScheduledTaskTrigger -Daily -At 7:30am
$settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -WakeToRun `
            -ExecutionTimeLimit (New-TimeSpan -Hours 1)
Register-ScheduledTask -TaskName 'Agent morning review' `
            -Action $action -Trigger $trigger -Settings $settings

The five settings that prevent silent failures

Problem Setting What it does
PC was asleep at run time -WakeToRun Wakes the PC for the task. Needs wake timers allowed in the power plan
PC was off or the slot was missed -StartWhenAvailable Runs the task as soon as possible after a missed start
Run hangs forever -ExecutionTimeLimit Stops a run that exceeds the limit, so the next one can start
Wrong folder -WorkingDirectory Starts in the project, not in System32
No evidence A dated log per run A missing log file means the run did not happen

Three failures the settings do not fix

The task runs as a different session. A task set to run whether or not you are logged on runs without your desktop session. Tools that keep a sign-in in your user profile may not find it, and anything that opens a browser to sign in will hang. Test the task with "Run" from Task Scheduler while signed in, then test it again after signing out, and read the log both times.

PATH is not what your terminal has. A command that works in your terminal can be "not recognized" in a scheduled task, because the task did not load your profile. Use full paths to executables, or set PATH at the top of the script.

Permission prompts with nobody to answer. A non-interactive run cannot ask you to approve a command. Pre-approve only the tools the job needs. Do not give a scheduled job blanket permission to run anything on a machine that holds real data.

Add a check for missing runs

The log tells you a run failed. It cannot tell you a run never started. Add a second small task that runs later in the day and checks that today's log exists:

$today = Get-Date -Format 'yyyy-MM-dd'
if (-not (Get-ChildItem C:\agents\logs -Filter "morning-review_$today*.log")) {
    Add-Content C:\agents\logs\FAILED.txt "$today morning-review did not run"
}

Point anything you already look at every day at FAILED.txt: a desktop shortcut, a notification script, an email. The check is only useful if you see it.

Cap the cost

A scheduled agent that loops is a scheduled bill. Keep the prompt narrow, set the time limit, and watch usage for the first week. If you use a metered API key rather than a subscription, set a spending limit at the provider as well.

How CPLai handles scheduled work

CPLai has scheduling built in, and it is designed around the failures above (Scheduling).

  • Schedule types. Daily, weekly, interval, multi-time, time-window and cron, all in your machine's local time zone.
  • Runs with the app closed. The installed Windows service launches scheduled work when the desktop app is closed.
  • A record of every run. Each schedule has a history of its last 50 runs. Skipped and failed runs say why, and a failed run sends you a notification.
  • Honest catch-up. A run blocked by capacity is held for up to 30 minutes, then CPLai waits for the next occurrence instead of launching hours late. It does not backfill every missed slot after downtime.
  • Silent runs are caught. CPLai watches for silence, not just errors. A run that produces no output for a set time is treated as stuck, its session is closed, and the run says so.
  • Missed-run signals. Fleet health reports agents that have missed several expected runs, and separates your own pause from a real problem.
  • Budget caps. Each agent has monthly, daily and per-run caps. Reaching a cap disables the agent and blocks further launches (Usage and Costs).

The limits are worth stating. The PC has to be on and the AI providers reachable. Signing out of Windows changes how the service runs work, so a setup that works in your terminal may need attention for a signed-out run.

Sources