# How to design AI agent loops: schedules, goals, and subagents in Claude Code and Codex

Podcast: How I AI
Published: Jun 17, 2026
Reading time: 12 min
Canonical: https://podbrew.app/briefs/how-i-ai-how-to-design-ai-agent-loops-schedules-goals-and-subagents-in-claude-co

This Podbrew episode dives deep into the architecture and application of AI agent loops. It provides a comprehensive guide on how to move beyond simple, one-off prompts to design self-sustaining, intelligent automation systems.

The discussion covers the four fundamental loop types—heartbeat, cron, hook, and goal—and outlines when each is most effective. Listeners will learn the five essential elements for any robust loop, demonstrated through practical, live builds like a daily aging-PR reviewer in Claude Code and a weekly skills-identification routine in Codex that uses goal-based subagents.

Understanding AI agent loops is vital for creating efficient and scalable AI solutions. The episode offers a clear framework for design and highlights how to build systems that automate complex workflows, manage tasks autonomously, and avoid common pitfalls, ultimately leading to more effective and less expensive AI deployments.

## Key takeaways

- AI agent loops are a form of automated prompting where agents generate their own prompts, differing from human-triggered message-based interactions.

- Heartbeat loops trigger tasks at consistent, regular intervals for continuous operations.

- Cron loops enable scheduled execution of tasks at specific times or dates.

- Hooks facilitate event-driven automation by responding to internal or external triggers.

- Effective AI loops require five foundational components for clean and efficient operation.

- Work trees isolate agent coding work, skills standardize common tasks, and plugins provide external tool access.

- Sub-agents handle specific delegated tasks, and state tracking manages ongoing progress and goals.

- Design AI agent loops by conceptualizing them as recurring "jobs to be done" for an intelligent agent, similar to onboarding an employee.

- Practical applications include an executive assistant agent reviewing calendars weekly or a software engineer agent triaging GitHub issues hourly and ensuring PRs meet code standards.

- Agent loops can be designed to initiate other loops, enabling the creation of hierarchical and creative automation systems.

- A practical routine can be established in Claude Code to track and flag pull requests that have remained open for over 12 hours, aiding in PR management.

- Automated loops can be scheduled to run daily, identifying and acting on pull requests open past a specified age threshold.

- Agents can be configured to 'babysit' PRs, monitoring merge checks and even initiating sub-agents or threads for continuous oversight.

- The system integrates with communication tools like Slack to alert teams about merge-ready PRs, reducing manual oversight and preventing delays.

- Codex offers customizable automation templates for creating complex, scheduled routines, such as a weekly process for identifying coding skill gaps.

- Advanced automations can incorporate goal-based sub-agents to automatically validate identified skills against a codebase, ensuring their functionality and quality.

- Nesting scheduled loops with goal-based sub-agent loops enables a powerful, continuous system for identifying, developing, and validating critical technical skills within an organization.

- Codex autonomously identifies new skills within a repository and then initiates a validation workflow.

- AI loops can incur high costs due to extensive token consumption, particularly if loop validation is inefficient or criteria are too broad.

- Precise prompt writing is essential for goal-based AI loops to ensure accurate evaluation, define success criteria, and avoid wasting tokens.

## 01:25 - 03:56 Understanding AI Agent Loops as Automated Prompting

The concept of AI agent loops is presented as an evolution beyond traditional human-triggered prompting. Influenced by figures like Pete at OpenClaw, the idea suggests that instead of humans prompting agents, agents should be designed to prompt themselves, forming an automated "loop."

A core distinction is made between "messages" and "loops." Messages represent human-triggered, turn-based inputs into a chatbot, which is how most people interact with AI. In contrast, loops refer to the automated prompting of an AI agent without direct human intervention for each prompt.

While agent loops offer significant benefits and use cases, particularly in software engineering, traditional human prompting remains a valid and effective method for many tasks. Both approaches have their utility, and not all AI interactions need to be "loop-maxed."

> Instead, when we're talking about loops, we're talking about automated prompting. of an agent.

## 03:56 - 06:01 Explore Four Distinct Automation Loop Types for AI Agents

Automation loops provide structured ways for AI agents to perform tasks without constant human prompting. These loops ensure that agents can operate semi-autonomously based on different triggers and schedules, mimicking traditional automation patterns now applied to AI workflows.

The heartbeat loop runs on a regular, recurring basis, such as checking for new Jira tickets every five minutes to initiate a coding agent. Cron loops, on the other hand, operate on a fixed schedule, like executing a task at 9 AM daily or every Sunday night.

Hooks are event-driven, prompting an agent based on internal lifecycle events (e.g., a tool call or session start) or external webhooks (e.g., receiving an email). These three loop types were common in automation before AI and are now used to trigger AI agents.

A newer type, the goal loop, has emerged as a first-class citizen in platforms like Claude Code and Codex. This loop defines an outcome and continually runs an agent until that outcome is measured, validated, or the agent becomes blocked. This is particularly useful in AI coding and other outcome-oriented automation scenarios.

> A goal is a type of loop that sets an outcome and runs an agent against that outcome until the outcome can be measured and validated or the agent is blocked.

## 06:01 - 09:49 Five Essential Components for Effective AI Loop Design

To build effective AI loops, five critical components are necessary for clean and consistent execution. These elements ensure that autonomous agents can perform tasks reliably, avoid conflicts, and operate efficiently without human intervention.

The first three components include work trees, skills, and plugins/connectors. Work trees isolate an agent's coding work in a sandbox, similar to Git worktrees, preventing interference with other agents. Skills represent repeatable methods for common tasks, while plugins and connectors provide the agent with access to external tools like GitHub, Google Docs, or Google Calendar, along with instructions for their use.

The final two components are sub-agents and state tracking. Sub-agents allow for the delegation of specific tasks, such as validation, from the main agent's thread. State tracking provides a mechanism to monitor progress, akin to a to-do list, which can be implemented using markdown or task trackers like Linear.

Collectively, these components empower an autonomously launched agent to perform its assigned task, maintain progress towards a goal, and manage its operations with the necessary isolation and tools. This structured approach ensures that AI loops function effectively, whether on a schedule or until a specific goal is achieved.

> If you are gonna be yoloing loops all over the place, you're going to want some consistency in execution, you're gonna want clean workspaces, you're gonna want conflicts resolved and avoided, and so all these things are really to make those loops effective.

## 09:50 - 12:01 Designing AI Agent Loops Using the Employee Onboarding Metaphor

AI agent loops can be effectively designed by adopting the mental model of onboarding a new employee and assigning them recurring tasks. Instead of complex technical diagrams, consider what "jobs to be done" you would delegate to a human. This approach makes the concept of automated workflows more accessible for building intelligent agents.

For instance, an executive assistant agent could be tasked to review a calendar every Friday, identify cancellations, and suggest follow-ups via Slack. Similarly, a software engineer agent might be instructed to check for new GitHub issues hourly, triage them, and submit code for review. Another example involves a PR reviewer agent that continuously works on a pull request until it meets predefined code standards and all checks are clean.

The power of these loops lies in their ability to automate specific, repeatable jobs. When you identify a task that needs to be done every day or hour, that's an ideal candidate for an agent loop. Rather than manually prompting, the loop is designed to kick itself off. Agents can also be configured to prompt other loops, allowing for sophisticated, layered automation where a primary agent oversees a team of subordinate agents, each running their own loops.

> I really like to think about loops as designing workflows and designing jobs. To be done for people, it just happens to be that you can put this intelligent agent against the loop, and then it's ready to go.

## 12:01 - 14:11 Setting Up a Daily Aging Pull Request Review Routine

This segment introduces the initial setup for a practical, non-technical loop designed for product managers and engineering teams. The host demonstrates how a simple scheduled task, like a morning briefing in Claude CoWork, already functions as a basic loop, making it an accessible starting point for understanding more complex routines.

The focus then shifts to building a more intelligent routine within Claude Code, specifically named 'Daily Aging PR Review'. This routine is intended to help teams monitor and manage pull requests that have been open for an extended period.

The core function of this routine is to identify open pull requests that have been active for more than 12 hours. The host notes that for this initial setup, the routine will run locally on their computer, requiring the laptop screen to remain open during execution.

> I'm gonna create a routine… it's gonna be a loop or a routine that looks for open PRs that have been open more than twelve hours.

## 15:41 - 18:59 Automating PR Review and Alerting with Scheduled Agent Loops

An automation loop is set up to address pull requests (PRs) that have been open for more than 12 hours. This daily scheduled routine, running at 10:15 AM, eliminates the need for manual monitoring of aging PRs.

The agent is given specific instructions: first, it reviews PRs open on the Chappier app. If a PR has been open for over twelve hours, it assesses its merge readiness. If possible, the agent initiates a sub-thread to 'babysit' the PR, monitoring it until all merge checks are green.

Alternatively, if PRs are ready for approval and merge but require team action, the agent uses a Slack connector to send a notification to the product channel. This ensures the team is promptly alerted to PRs that are complete but ignored.

This automated process makes the PR review workflow autonomous, leveraging connectors like GitHub and Slack. It significantly reduces manual oversight, providing a streamlined way to manage and push PRs to merge readiness or alert the team when intervention is needed.

> I am not gonna have to monitor it, and all I'm gonna get at the end of the day is a good set of PRs that are ready to merge and some mean messages about how we're ignoring good PRs.

## 19:00 - 22:56 Building a Scheduled Automation for Skill Identification and Goal-Based Validation in Codex

An advanced automation in Codex is described, focusing on a weekly routine to identify missing coding skills. This leverages Codex's automation templates, specifically one designed to analyze recent pull requests (PRs) and reviews to suggest skills for developers to deepen. This process is scheduled to run every Friday morning.

The default prompt for this automation is customized to ensure that skill suggestions are anchored to concrete evidence and are actionable. A critical modification specifies that if internal tools for automatic validation (like command-line tools or MCPs for running test suites) exist, the automation should prioritize identifying skills related to using these tools.

The automation introduces a powerful multi-layered loop structure. When a new skill is identified, the primary scheduled loop initiates a sub-thread or sub-agent. This sub-agent's role is to validate the identified skill in real-time by running against the base branch of the code repository. This validation uses its own goal-based loop to confirm the skill functions correctly and produces high-quality output.

This meta-task demonstrates the power of loop-based prompting, where a main scheduled loop triggers sub-agents that perform their own goal-oriented loops for validation. This creates a continuous and dynamic system for not only identifying potential skill gaps but also actively testing and confirming the efficacy of new or improved coding skills.

> Not only are we setting a loop at the schedule basis, we are setting up sub-agents to work on specific things, and then we're using a goal in those sub-agents, which is a different type of loop, to validate the work.

## 22:57 - 25:40 Observing Codex Subagents Validate Skills in Real-Time

Codex automation demonstrates its ability to identify potential skills within a codebase and then initiate a validation process. It sets up its own memory, searches code, and runs commands to create these new skills.

A key feature is the spawning of dedicated sub-agents, each assigned a specific goal to test an identified skill. For instance, the system found a 'chat smoke CLI' skill and created a sub-agent to test its instructions against the base branch, ensuring practical functionality.

These sub-agents, like 'Gauss' validating the smoke CLI skill and 'Galileo' working on a 'GitHub address comment' skill, operate in a loop until their respective validation tasks are complete. This allows for concurrent testing of multiple skills.

This automation can be configured to run periodically, such as weekly, to review the repository, generate new skills, and then leverage these goal-oriented sub-agents to continuously validate their functionality.

> it spun up this agent, you can see agent, it's got a little key name, and it's given it a goal, so you can see here it's pursuing this goal. Which is validate the local repo chatgsm cli skill on the base branch, and it's basically gonna loop until that validation is done.

## 25:40 - 28:14 Common Pitfalls with AI Loops: Managing Costs and Prompt Precision

AI automation loops, while powerful for tasks like spinning off sub-agents or performing regular work, come with significant challenges. Two primary issues are the potential for high token consumption and the absolute necessity of precise prompt engineering.

The cost associated with AI loops can escalate rapidly. Agents performing loop-based validation will continue to consume tokens until they meet a defined success threshold. If the loop is poorly written or the validation criteria are too lenient, the agent can burn through a substantial number of tokens without achieving efficient results, as seen with some Open-AI agent harnesses.

Prompt precision is critically important, especially for goal-based loops. If the evaluation and success criteria are not meticulously defined, the agent's output can be disappointing, leading to wasted tokens and resources. Tools like OpenAI's guide for Codex on writing goals offer valuable insights for crafting effective prompts.

While AI loops can be beneficial for various applications, such as scheduled morning briefs or inbox clean-up, users must exercise caution. Being mindful of token usage and investing time in crafting highly specific prompts can prevent inefficiencies and unexpected expenses.

> loops, especially goal-based loops, are ones where writing the prompt really precisely is super, super important.

---

Get podcast briefs for shows you follow: https://podbrew.app/
