Lenny Rachitsky · 2 min read · Gen AI Tools
How to design AI agent loops: schedules, goals, and subagents in Claude Code and Codex
Read the original on lennysnewsletter.com →
Explore designing AI agent loops—defining heartbeat, cron, hook, and goal loops, when to use each, and the five essentials for production. The guide includes a practical onboarding framework and two live builds: a daily aging-PR loop in Claude Code with subagents, and a weekly skills-identification loop in Codex that validates output in real time.
Key Takeaways
- Loops are automated prompts, not a new paradigm, with four concrete types: heartbeat, cron, hook, and goal.
- Every effective loop needs five ingredients: work trees, skills, plugins/connectors, subagents, and state tracking.
- Use the onboarding-an-employee framework to guide loop design and learn from live builds like the daily PR aging loop and the weekly skills loop.
- Goal-based loops are the hardest to implement and can waste tokens; watch for signs of runaway costs.
Excerpt
I break down every loop type from scratch—what a heartbeat, cron, hook, and goal loop actually are, when each one fits, and the five things any effective loop needs before it touches production. Then I build two live loops: a daily aging-PR reviewer in Claude Code that schedules itself at 10:15 a.m. and spins off its own subagents, and a weekly skills-identification loop in Codex that spawns goal-based subagents to validate its own output in real time. Listen or watch on YouTube , Spotify , or Apple Podcasts What you’ll learn: The plain-English definition of a loop—and why it’s just…