How to design AI agent loops: schedules, goals, and subagents in Claude Code and Codex
- Date
TLDR
AI coding agents have moved beyond human-in-the-loop chat toward autonomous "loops"—scheduled, triggered, or goal-driven automations that prompt themselves until a job is done. The episode breaks loops down into heartbeat, cron, hook, and goal variants, demonstrates how to build them in Claude Code and Codex using sub-agents and skills, and warns that imprecise prompts and weak validation criteria can burn tokens rapidly without useful output.
Key takeaways
A loop is an autonomous automation that prompts an agent on a schedule or trigger until the task is complete, fundamentally distinct from turn-based human chatting. The host defines loops as heartbeat (regular intervals), cron (set times), hook (internal/external events), and goal (run until validated outcome) automations that remove the need for human fingers to type every prompt. This represents a shift from messaging AI to designing jobs for agents, where the agent instructs itself.
Goal loops have shipped as native features in both Claude Code and Codex, enabling agents to run against an outcome until it is measured and validated or the agent is blocked. Unlike simple scheduled routines, a goal loop sets a success criterion and lets the agent iterate until that criterion is met. The host demonstrates this by having a Codex automation spin up sub-agents with explicit goals to validate newly suggested skills against the base branch, creating nested autonomous validation.
Clean loops depend on worktrees, skills, plugins, sub-agents, and state tracking to isolate work and maintain consistency. The host cites Addy Osmani's loop engineering framework and emphasizes that without sandboxed worktrees, reusable skills, connectors to tools like GitHub or Slack, sub-agents for federated tasks, and a tracking mechanism such as a markdown todo list or Linear, autonomous agents will collide, conflict, and produce messy results.
Designing a loop is equivalent to onboarding an employee, where you define the recurring task, success criteria, and tools rather than micromanaging each step. The host reframes loop creation as writing a job description, whether for an executive assistant reviewing calendars every Friday or a software engineer triaging GitHub issues hourly. This makes loop design accessible by translating automation into familiar workforce delegation rather than complex dynamic workflow diagrams.
Both Claude Code and Codex support sub-agents that let a parent loop spawn dedicated child threads to handle specific tasks or validation in parallel. In the Codex demo, the parent automation analyzes merged PRs and then spawns individually named sub-agents, each pursuing its own goal loop to validate a suggested skill on the base branch. This architecture means a single scheduled loop can instantiate an entire team of agents that monitor and validate work autonomously.
Poorly written goal loops will burn through tokens relentlessly because the agent will continue iterating until precise success criteria force it to stop. The host warns that goal-based prompting demands extreme precision in evaluation and exit conditions. Without tight validation logic, agents stay diligent but wasteful, consuming significant compute for marginal output. OpenAI's goal-writing guide for Codex is recommended, and the host admits their own live demos used suboptimal prompting that would benefit from stricter criteria.
Insights and implications
As AI coding loops gain sub-agent hierarchies, engineering management will need to adopt staffing-like governance models because a poorly managed loop functions exactly like a rogue contractor with a corporate credit card. The host demonstrates that a single loop can autonomously spawn validation sub-agents and decide its own scope, blurring the line between software execution and labor delegation. Organizations that fail to apply headcount-style oversight, such as approval limits and output quality reviews, will find autonomous agents racking up unpredictable token bills while producing unverified work.
The goal-loop primitive inverts the traditional developer workflow from "write code, then test" to "define success criteria, then let the agent iterate," which means the highest-leverage skill for engineers shifts from implementation to specification design. In the Codex demonstration, the parent automation does not write the skill directly; it writes a validation goal that the sub-agent pursues until satisfied. This implies that as loops mature, engineering productivity will depend less on syntax expertise and more on the ability to craft unambiguous, measurable exit conditions that prevent infinite autonomous iteration.
Loops expose a new category of technical debt: autonomous automation debt, where deprecated skills, stale connectors, or changed repository structures cause agent teams to silently fail or generate phantom work long after the originating prompt was forgotten. The host emphasizes that loops run on schedules independent of human attention, using skills, plugins, and worktrees that can drift out of sync with production reality. Unlike traditional scripts that break visibly, an agent loop with stale context may continue consuming tokens and posting to Slack indefinitely, creating invisible operational drag that only surfaces in a surprise cloud bill.