AI Agent Scheduled Task Cron Job — Run Claude or GPT Daily at 6am
Kick off an AI agent every morning at 6am to process overnight data, generate content, or summarize what happened while you slept.
What this schedule does
The expression 0 6 * * * fires at exactly 6:00 AM every day, seven days a week. The five fields mean: minute=0, hour=6, any day of month, any month, any day of week. It runs daily without exception — including weekends — making it ideal for continuous overnight processing pipelines.
This is the standard "morning agent" schedule. Your cron job starts a Python (or Node) script that calls the Anthropic or OpenAI API, processes whatever accumulated overnight — logs, user submissions, market data, RSS feeds — and writes a structured output: a Slack message, a markdown summary file, a database row, or an email digest.
What to run with an AI agent
A 6am agent job works best when there is a clear input corpus that accumulates overnight and a clear output artifact. Common patterns:
- Summarize overnight support tickets or GitHub issues using Claude and post to Slack
- Generate a daily content brief or social post drafts from RSS feeds or trending topics
- Classify and triage overnight log anomalies — send only the critical ones to on-call
- Pull yesterday's analytics, ask GPT to write a one-paragraph narrative, email it to the team
- Extract action items from overnight customer emails and append them to a Notion or Google Sheet
Keep the script idempotent — if it runs twice, it should not produce duplicate Slack messages or double-send emails. Write a sentinel file or check a database flag at startup.
Platform snippets
# crontab -e
0 6 * * * /usr/bin/python3 /opt/agents/morning_agent.py >> /var/log/morning_agent.log 2>&1
# morning_agent.py
import anthropic, datetime, json, pathlib, os, requests
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
# Load overnight data (replace with your actual source)
data_path = pathlib.Path("/var/data/overnight_events.jsonl")
events = [json.loads(l) for l in data_path.read_text().splitlines() if l.strip()]
corpus = "\n".join(e.get("summary", "") for e in events[-50:]) # last 50 events
message = client.messages.create(
model="claude-opus-4-5",
max_tokens=1024,
messages=[{
"role": "user",
"content": f"Summarize these overnight events in 3 bullet points:\n\n{corpus}"
}]
)
summary = message.content[0].text
# Post to Slack
requests.post(os.environ["SLACK_WEBHOOK"], json={
"text": f":robot_face: *Morning Agent — {datetime.date.today()}*\n{summary}"
})
# Archive processed file
data_path.rename(data_path.with_suffix(f".{datetime.date.today()}.done"))
on:
schedule:
- cron: '0 6 * * *' # UTC — adjust for your timezone
jobs:
morning-agent:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install anthropic openai requests
- name: Run morning AI agent
run: python scripts/morning_agent.py
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# EventBridge cron (6 fields — adds year, UTC)
cron(0 6 * * ? *)
# Lambda handler (Python) — triggered by EventBridge
import anthropic, boto3, json, os
def handler(event, context):
client = anthropic.Anthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
# Fetch overnight data from S3
s3 = boto3.client("s3")
obj = s3.get_object(Bucket=os.environ["DATA_BUCKET"], Key="overnight/events.json")
events = json.loads(obj["Body"].read())
corpus = "\n".join(e["text"] for e in events[:40])
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=512,
messages=[{"role": "user", "content": f"Summarize:\n{corpus}"}]
)
# Write result back to S3
s3.put_object(
Bucket=os.environ["DATA_BUCKET"],
Key=f"summaries/{context.aws_request_id}.txt",
Body=response.content[0].text
)
return {"status": "ok"}
apiVersion: batch/v1
kind: CronJob
metadata:
name: morning-ai-agent
spec:
schedule: "0 6 * * *"
timeZone: "America/New_York" # Kubernetes 1.27+
concurrencyPolicy: Forbid # prevent overlapping runs
jobTemplate:
spec:
template:
spec:
containers:
- name: agent
image: your-registry/morning-agent:latest
command: ["python", "morning_agent.py"]
env:
- name: ANTHROPIC_API_KEY
valueFrom:
secretKeyRef:
name: ai-secrets
key: anthropic-api-key
- name: SLACK_WEBHOOK
valueFrom:
secretKeyRef:
name: ai-secrets
key: slack-webhook
restartPolicy: OnFailure
Timezone note
Standard crontab uses the system timezone. GitHub Actions and AWS EventBridge run in UTC — if you're on US Eastern time (UTC-5), use 0 11 * * * to fire at 6am ET. Kubernetes 1.27+ supports spec.timeZone: "America/New_York" so you can write the local time directly. Always log the agent's start timestamp so you can verify the schedule is firing when you expect it to.