How to Set Up Scheduled Workflows in GitHub Actions in 5 Minutes¶
Target Audience
- Developers who want to automate recurring tasks with GitHub Actions
Key Points¶
- Configure a GitHub Actions schedule trigger
- Understand basic cron syntax
- Run Claude Code on a schedule
How Scheduled Execution Works¶
GitHub Actions schedule events automatically run workflows at specified times. Internally they use cron expressions, but everything runs on GitHub, so no server setup is required.
Implementation Steps¶
Step 1: Create a Workflow File¶
Create .github/workflows/scheduled-task.yml:
name: Scheduled Task
on:
schedule:
- cron: '0 9 * * *' # Daily at 9:00 AM (UTC)
workflow_dispatch: # Enable manual triggering
Step 2: Add Claude Code Execution Job¶
jobs:
run-claude:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Claude Code
env:
CLAUDE_API_KEY: ${{ secrets.CLAUDE_API_KEY }}
run: |
# Execute automation task with Claude Code
npx claude-code --task "Generate daily report"
Step 3: Push to GitHub to Activate¶
git add .github/workflows/scheduled-task.yml
git commit -m "Add scheduled workflow"
git push origin main
Common Cron Expression Patterns¶
| Schedule | Cron Expression | Japan Time (JST) |
|---|---|---|
| Daily 9 AM | 0 0 * * * | 9:00 |
| Weekdays 9 AM | 0 0 * * 1-5 | 9:00 (Mon-Fri) |
| Monday 9 AM | 0 0 * * 1 | Monday 9:00 |
| 1st of month 9 AM | 0 0 1 * * | 1st 9:00 |
| Every 6 hours | 0 */6 * * * | 0, 6, 12, 18 |
※GitHub Actions uses UTC. Japan time is UTC+9
Troubleshooting¶
| Symptom | Cause | Solution |
|---|---|---|
| Doesn't run | Incorrect cron syntax | Validate with crontab.guru |
| Time offset | Timezone | Calculate in UTC (JST-9 hours) |
| Stops after 60 days | Inactivity | Commit to repository regularly |
Advanced Configuration (Click to Expand)
### Multiple Scheduleson:
schedule:
- cron: '0 0 * * *' # Daily
- cron: '0 12 * * 5' # Friday noon
jobs:
scheduled-task:
strategy:
matrix:
environment: [dev, staging, prod]
runs-on: ubuntu-latest
steps:
- name: Run for ${{ matrix.environment }}
run: echo "Running for ${{ matrix.environment }}"
- name: Error Notification
if: failure()
uses: actions/github-script@v7
with:
script: |
github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'Scheduled task failed',
body: 'Check the workflow run for details'
})
Next Steps¶
This article extracts and organizes GitHub Actions-specific content from multiple legacy cron-related articles.