The Agent Loop Workflow
Build effective long-running coding agents in 7 minutes. From spec to PRD to autonomous execution.
The Core Insight
The Agent Loop is an iterative process where an AI repeatedly: decides what to do next → executes that action → observes the result → repeats until the task is complete. The key is that state persists in the file system, not in the AI's memory.
The 3-Phase Workflow
Nader Dabit's workflow breaks down into three clear phases that transform vague ideas into shipped code.
1Create the Spec
Start with a high-level description of what you want to build and why. Focus on goals, constraints, and user needs—not implementation details.
A good spec answers:
- • What problem are we solving?
- • Who is the target user?
- • What are the core features (v1)?
- • What's explicitly out of scope?
- • What are the constraints (tech stack, budget, timeline)?
2Build & Polish the PRD
Transform the spec into a detailed Product Requirements Document. The PRD becomes the source of truth that the agent references on every iteration.
PRD Structure
- • Overview & objectives
- • User stories with acceptance criteria
- • Technical requirements
- • API contracts & data models
- • Non-goals (explicit boundaries)
Polish Tips
- • Use AI to expand initial draft
- • Add "DO NOT CHANGE" sections
- • Include verification steps
- • Define success metrics
- • Create testable checkpoints
3Run the Agent Loop
Execute the agent using Claude Code, Codex, or OpenCode. The agent reads the PRD, implements tasks, commits progress, and continues until complete.
# The Agent Loop
while task_not_complete:
1. Read PRD & check git history
2. Decide next action
3. Execute (read/write/edit/bash)
4. Commit changes with message
5. Verify against acceptance criteria
Claude Agent SDK Tools
The Claude Agent SDK (the infrastructure behind Claude Code) provides these built-in tools for agents:
Read any file
Create new files
Modify existing files
Run terminal commands
Find files by pattern
Search file contents
Search the web
Fetch web pages
Advanced Capabilities
Subagents
Create specialized agents for specific tasks: a "security-reviewer" to audit code, a "test-analyzer" to verify coverage, or a "performance-optimizer" to profile bottlenecks.
Permission Controls
Control what the agent can do: default (prompts for approval), acceptEdits (auto-approve file edits), or bypassPermissions (fully autonomous).
Session Management
Capture and resume sessions for multi-turn conversations. The agent remembers previous context and can answer follow-up questions or continue interrupted work.
Structured Output
Configure agents to return JSON Schema-validated output. Perfect for code review reports, audit logs, or any structured data that downstream systems consume.
The Secret: Backpressure
Unit, integration, E2E tests verify functionality
ESLint, Prettier catch style issues
TypeScript ensures type safety
Quick Start
1. Install Claude Agent SDK
npm install @anthropic-ai/claude-agent-sdk2. Create your spec file
# SPEC.md
## Goal
Build a REST API for task management
## Features (v1)
- CRUD operations for tasks
- User authentication
- Due date reminders
## Out of Scope
- Mobile app
- Team collaboration3. Run the agent
claude --dangerously-skip-permissions "Read SPEC.md and implement the API"How It Compares
| Aspect | Agent Loop | Ralph | GSD |
|---|---|---|---|
| Focus | SDK-first development | Shell script simplicity | Context engineering |
| State | Git + file system | progress.txt + git | .planning/ directory |
| Complexity | Medium (SDK setup) | Low (shell script) | High (multi-agent) |
| Best For | Custom agents, integrations | Quick automation | Large projects |