|
| 1 | +[< Back to Workflows](README.md) |
| 2 | + |
| 3 | +# Routines & Scheduled Tasks |
| 4 | + |
| 5 | +Automated routines that run on a schedule so your codebase stays healthy without manual effort. Claude Code supports three scheduling tiers; pick the one that fits your setup. |
| 6 | + |
| 7 | +## Scheduling Tiers |
| 8 | + |
| 9 | +| Tier | Runs on | Machine required | Session required | Min interval | |
| 10 | +|---|---|---|---|---| |
| 11 | +| **Cloud Routines** | Anthropic cloud | No | No | 1 hour | |
| 12 | +| **Desktop Scheduled Tasks** | Your machine | Yes | No | 1 minute | |
| 13 | +| **`/loop` (in-session)** | Your machine | Yes | Yes | 1 minute | |
| 14 | + |
| 15 | +Cloud Routines support three trigger types: **scheduled** (cron), **API** (HTTP POST), and **GitHub events** (PR opened, releases, etc.). A single routine can combine all three. |
| 16 | + |
| 17 | +> Each plan has a daily cap on scheduled runs. One-off runs do not count toward the cap. Check your current limits at [claude.ai/settings/usage](https://claude.ai/settings/usage). |
| 18 | +
|
| 19 | +--- |
| 20 | + |
| 21 | +## Daily Routines |
| 22 | + |
| 23 | +### Morning PR Digest |
| 24 | + |
| 25 | +**Schedule:** Daily at 8:00 AM |
| 26 | +**Purpose:** Start the day knowing what landed, what's in flight, and what's stuck. |
| 27 | + |
| 28 | +``` |
| 29 | +Read all open PRs and recent commits. Post a Slack message with: |
| 30 | +- What landed yesterday |
| 31 | +- What's in flight (open PRs with recent activity) |
| 32 | +- Anything blocked or stale (PRs older than 3 days with no review) |
| 33 | +Keep it under 10 lines. Do NOT approve or merge any PR. |
| 34 | +``` |
| 35 | + |
| 36 | +**Trigger type:** Cloud Routine (scheduled) or Desktop Scheduled Task |
| 37 | +**Connectors:** GitHub, Slack |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +### Daily Security Scan |
| 42 | + |
| 43 | +**Schedule:** Daily at 8:00 AM |
| 44 | +**Purpose:** Catch sensitive data, dependency vulnerabilities, and risky patterns before they reach production. |
| 45 | + |
| 46 | +``` |
| 47 | +Scan all commits pushed in the last 24 hours for: |
| 48 | +- Hardcoded secrets, API keys, or credentials |
| 49 | +- New dependencies with known CVEs |
| 50 | +- SQL injection, XSS, or command injection patterns |
| 51 | +
|
| 52 | +Create a GitHub issue listing findings by severity (critical/high/medium). |
| 53 | +If nothing found, skip the issue. Do NOT modify any code. |
| 54 | +``` |
| 55 | + |
| 56 | +**Trigger type:** Cloud Routine (scheduled) |
| 57 | +**Connectors:** GitHub |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +### Error Log Analysis |
| 62 | + |
| 63 | +**Schedule:** Daily at 7:00 AM |
| 64 | +**Purpose:** Surface overnight errors before the team starts work. |
| 65 | + |
| 66 | +``` |
| 67 | +Analyze application logs from the last 24 hours. |
| 68 | +- Count ERROR and FATAL entries; compare to 7-day average |
| 69 | +- Identify any new error types not seen before this week |
| 70 | +- Flag error spikes (>2x the daily average) |
| 71 | +
|
| 72 | +Post a summary to #engineering-alerts. Include top 5 errors by frequency. |
| 73 | +Do NOT open fix PRs automatically. |
| 74 | +``` |
| 75 | + |
| 76 | +**Trigger type:** Cloud Routine (scheduled) |
| 77 | +**Connectors:** Custom MCP integration for your logging service, Slack |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +### Documentation Sync Check |
| 82 | + |
| 83 | +**Schedule:** Daily at 10:00 AM |
| 84 | +**Purpose:** Catch docs that have drifted from the code they describe. |
| 85 | + |
| 86 | +``` |
| 87 | +Compare README.md and docs/ with the actual codebase. |
| 88 | +Flag any documentation that: |
| 89 | +- References functions, endpoints, or config keys that no longer exist |
| 90 | +- Shows installation steps that don't match the current package.json/requirements |
| 91 | +- Contains example code that would fail against the current API |
| 92 | +
|
| 93 | +Report findings as a checklist. Do NOT edit docs directly. |
| 94 | +``` |
| 95 | + |
| 96 | +**Trigger type:** Cloud Routine (scheduled) or Desktop Scheduled Task |
| 97 | +**Connectors:** GitHub |
| 98 | + |
| 99 | +--- |
| 100 | + |
| 101 | +## Event-Triggered Routines |
| 102 | + |
| 103 | +### PR Code Review |
| 104 | + |
| 105 | +**Trigger:** `pull_request.opened` |
| 106 | +**Purpose:** Immediate feedback on every new PR, applying your team's standards. |
| 107 | + |
| 108 | +``` |
| 109 | +Review the PR carefully and post a comment with: |
| 110 | +1. A one-line summary of what the PR changes |
| 111 | +2. Any potential bugs, edge cases, or security concerns |
| 112 | +3. Suggestions for improvement (if any) |
| 113 | +4. A clear verdict: ready to merge, needs changes, or blocking issue |
| 114 | +
|
| 115 | +Apply the project's coding standards from CLAUDE.md. |
| 116 | +Do NOT approve or merge the PR. |
| 117 | +``` |
| 118 | + |
| 119 | +**Trigger type:** Cloud Routine (GitHub event) |
| 120 | +**Connectors:** GitHub |
| 121 | + |
| 122 | +--- |
| 123 | + |
| 124 | +### Deploy Verification |
| 125 | + |
| 126 | +**Trigger:** API endpoint called by CD pipeline after production deploy |
| 127 | +**Purpose:** Automated smoke test to catch deploy regressions. |
| 128 | + |
| 129 | +``` |
| 130 | +Run smoke checks against the new build: |
| 131 | +- Hit health check endpoints and verify 200 responses |
| 132 | +- Scan error logs for new errors in the last 5 minutes |
| 133 | +- Compare response times to pre-deploy baseline |
| 134 | +
|
| 135 | +Post go/no-go status to #releases. If critical failures detected, |
| 136 | +include the error details and recent commit that likely caused it. |
| 137 | +``` |
| 138 | + |
| 139 | +**Trigger type:** Cloud Routine (API trigger) |
| 140 | +**Connectors:** Custom MCP integration for your monitoring service, Slack |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +### Alert Triage |
| 145 | + |
| 146 | +**Trigger:** API endpoint called by monitoring when error threshold is crossed |
| 147 | +**Purpose:** Correlate alerts with recent changes and accelerate response. |
| 148 | + |
| 149 | +``` |
| 150 | +Pull the stack trace from the alert payload. |
| 151 | +Correlate with commits from the last 24 hours. |
| 152 | +Identify the most likely causal commit. |
| 153 | +Post analysis to #oncall with: |
| 154 | +- Stack trace summary |
| 155 | +- Suspected commit and author |
| 156 | +- Suggested investigation steps |
| 157 | +
|
| 158 | +Do NOT open PRs or revert commits automatically. |
| 159 | +``` |
| 160 | + |
| 161 | +**Trigger type:** Cloud Routine (API trigger) |
| 162 | +**Connectors:** Custom MCP integration for your monitoring service, GitHub, Slack |
| 163 | + |
| 164 | +--- |
| 165 | + |
| 166 | +## Weekly Routines |
| 167 | + |
| 168 | +### Dependency Update Check |
| 169 | + |
| 170 | +**Schedule:** Every Monday at 7:00 AM |
| 171 | +**Purpose:** Stay current on dependencies without surprise breakage. |
| 172 | + |
| 173 | +``` |
| 174 | +Check for outdated packages in the project. |
| 175 | +For each outdated dependency: |
| 176 | +- Note the current vs latest version |
| 177 | +- Flag whether it's a major/minor/patch bump |
| 178 | +- Check for known security advisories |
| 179 | +- Note breaking changes from the changelog |
| 180 | +
|
| 181 | +Post a summary to #engineering. For security-critical updates, |
| 182 | +open a GitHub issue with the "security" label. |
| 183 | +Do NOT auto-upgrade or open PRs. |
| 184 | +``` |
| 185 | + |
| 186 | +**Trigger type:** Cloud Routine (scheduled) |
| 187 | +**Connectors:** GitHub, Slack |
| 188 | + |
| 189 | +--- |
| 190 | + |
| 191 | +### Stale Branch Cleanup |
| 192 | + |
| 193 | +**Schedule:** Every Friday at 5:00 PM |
| 194 | +**Purpose:** Keep the repository tidy by surfacing abandoned work. |
| 195 | + |
| 196 | +``` |
| 197 | +List all branches in the repository. |
| 198 | +Identify: |
| 199 | +- Branches already merged to main (safe to delete) |
| 200 | +- Unmerged branches with no commits in 30+ days |
| 201 | +
|
| 202 | +Post a summary listing branches safe to delete and stale unmerged branches. |
| 203 | +For stale unmerged branches: open a GitHub issue tagging the branch author, |
| 204 | +asking whether the work should be continued or the branch deleted. |
| 205 | +Do NOT delete any branches automatically. Do NOT touch release or protected branches. |
| 206 | +``` |
| 207 | + |
| 208 | +**Trigger type:** Cloud Routine (scheduled) or Desktop Scheduled Task |
| 209 | +**Connectors:** GitHub |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +### Code Complexity Trend |
| 214 | + |
| 215 | +**Schedule:** Every Monday at 8:00 AM |
| 216 | +**Purpose:** Catch architectural drift before it becomes tech debt. |
| 217 | + |
| 218 | +``` |
| 219 | +Analyze the codebase for complexity trends: |
| 220 | +- Identify files with the highest cyclomatic complexity |
| 221 | +- Compare this week's metrics to last week's |
| 222 | +- Flag any file where complexity increased by >20% |
| 223 | +- List the top 5 most complex functions |
| 224 | +
|
| 225 | +Post the report to #engineering. Do NOT refactor anything. |
| 226 | +``` |
| 227 | + |
| 228 | +**Trigger type:** Cloud Routine (scheduled) |
| 229 | +**Connectors:** GitHub, Slack |
| 230 | + |
| 231 | +--- |
| 232 | + |
| 233 | +### Weekly Changelog Generation |
| 234 | + |
| 235 | +**Schedule:** Every Friday at 4:00 PM |
| 236 | +**Purpose:** Automated release notes from the week's merged PRs. |
| 237 | + |
| 238 | +``` |
| 239 | +Read all PRs merged to main this week. |
| 240 | +Categorize each into: Feature, Fix, Chore, Docs. |
| 241 | +Generate a formatted changelog entry following Keep a Changelog format. |
| 242 | +
|
| 243 | +Post the draft to #releases for review. Do NOT commit to the repository. |
| 244 | +``` |
| 245 | + |
| 246 | +**Trigger type:** Cloud Routine (scheduled) |
| 247 | +**Connectors:** GitHub, Slack |
| 248 | + |
| 249 | +--- |
| 250 | + |
| 251 | +### Test Coverage Report |
| 252 | + |
| 253 | +**Schedule:** Every Monday at 9:00 AM |
| 254 | +**Purpose:** Track coverage trends and prevent regression. |
| 255 | + |
| 256 | +``` |
| 257 | +Run the test suite with coverage enabled. |
| 258 | +Compare coverage to last week's baseline. |
| 259 | +Flag: |
| 260 | +- Any module that dropped below 80% coverage |
| 261 | +- New files with zero test coverage |
| 262 | +- Coverage trend (improving/declining/stable) |
| 263 | +
|
| 264 | +Post results to #engineering with the coverage delta. |
| 265 | +``` |
| 266 | + |
| 267 | +**Trigger type:** Desktop Scheduled Task |
| 268 | +**Connectors:** GitHub, Slack |
| 269 | + |
| 270 | +--- |
| 271 | + |
| 272 | +## The `/loop` Pattern |
| 273 | + |
| 274 | +For in-session maintenance, the `/loop` command runs a repeating task while you work. Customize it with a `.claude/loop.md` file. |
| 275 | + |
| 276 | +### Default behavior (no loop.md) |
| 277 | + |
| 278 | +- Continues unfinished work from the conversation |
| 279 | +- Tends the current branch's PR: review comments, failed CI, merge conflicts |
| 280 | +- Runs cleanup passes when nothing else is pending |
| 281 | + |
| 282 | +### Custom loop.md example |
| 283 | + |
| 284 | +Place at `.claude/loop.md` (project) or `~/.claude/loop.md` (user): |
| 285 | + |
| 286 | +```markdown |
| 287 | +Check the `release/next` PR. If CI is red, pull the failing job log, |
| 288 | +diagnose, and push a minimal fix. If new review comments have arrived, |
| 289 | +address each one and resolve the thread. If everything is green and |
| 290 | +quiet, say so in one line. |
| 291 | +``` |
| 292 | + |
| 293 | +### Babysit PRs loop |
| 294 | + |
| 295 | +``` |
| 296 | +/loop 5m Review all open PRs on this repo. For each: |
| 297 | +- Check CI status |
| 298 | +- Respond to new review comments |
| 299 | +- Flag merge conflicts |
| 300 | +Report only changes since last check. |
| 301 | +``` |
| 302 | + |
| 303 | +--- |
| 304 | + |
| 305 | +## Writing Effective Routine Prompts |
| 306 | + |
| 307 | +### Do |
| 308 | + |
| 309 | +- **Be explicit about outputs.** "Post a Slack message to #channel" beats "notify the team." |
| 310 | +- **Include guardrails.** Every routine should state what it must NOT do: "Do NOT merge," "Do NOT edit files." |
| 311 | +- **Specify scope.** "Commits from the last 24 hours" is better than "recent commits." |
| 312 | +- **Define thresholds.** "Flag if >2x daily average" prevents noise on normal fluctuations. |
| 313 | +- **State the format.** "Bulleted list under 10 lines" keeps outputs consistent. |
| 314 | + |
| 315 | +### Don't |
| 316 | + |
| 317 | +- Don't omit "Do NOT" boundaries — routines run autonomously and will take any action the prompt allows. |
| 318 | +- Don't use vague time references — "yesterday" is ambiguous across timezones; prefer "last 24 hours." |
| 319 | +- Don't skip the connector list — routines need explicit access to each service they touch. |
| 320 | +- Don't assume context — the routine starts fresh each run with no memory of previous executions. |
| 321 | + |
| 322 | +--- |
| 323 | + |
| 324 | +## Resources |
| 325 | + |
| 326 | +- [Cloud Routines documentation](https://code.claude.com/docs/en/routines) |
| 327 | +- [Desktop Scheduled Tasks documentation](https://code.claude.com/docs/en/desktop-scheduled-tasks) |
| 328 | +- [Scheduled Tasks overview](https://code.claude.com/docs/en/scheduled-tasks) |
0 commit comments