A complete hands-on course for building self-improving AI agents. Interactive modules, a live loop simulator, working code you can execute, charts, and 4 real projects.
Claude Code is Anthropic's command-line assistant that reads your codebase, plans changes, runs tools, runs tests, and iterates autonomously. To engineer good loops on top of it, first look inside.
CLAUDE.md, file @mentions, memory files. What Claude sees on turn N.
File ops, shell, git, MCP, web skills. Every tool is one verb.
Observe → Plan → Act → Verify → Iterate. The atomic loop.
Observe: Reads files, tests, prior context, tool outputs.
# Global Policies for This Project
- Always create a git worktree for experiments: git worktree add ../temp-$(date +%s)
- Run relevant tests after every code change
- Use low effort for routine tasks, high effort for planning
- Document all changes clearly
- Never execute destructive commands without confirmation
- Prefer secure, minimal changes/init
Read the entire src/ directory and provide a high-level architecture summary.Edit utils.py to implement caching for the get_data function.
Then execute: python -c "from utils import get_data; print(get_data())"Loops replace one-shot prompts with a system: trigger, goal, executor, verifier, memory, stop condition. Below is a live simulator — tune the rubric and watch convergence.
manual · cron · webhook · event
measurable success criteria
Fable 5 for complex, Sonnet for routine
separate agent · scores 1–10
progress.md · CLAUDE.md
max iters · pass · budget cap
/goal: Refactor the authentication module for security and performance.
Success criteria (verify each iteration):
1. All unit tests pass (pytest auth/)
2. No security issues detected
3. Performance benchmark improved >=15%
4. Code style compliant and documented
Use a dedicated worktree. Maximum 5 iterations. Summarize final changes.model: sonnet
effort: low
You are a strict code verifier. Score the output 1-10 against the provided rubric.
Only approve if score >=9. Provide specific fix suggestions otherwise.Use the verifier subagent after every major change.
/loop every 30 seconds until goal is met or max 10 iterations reached.
Log progress to progress.mdSpawn parallel subagents:
- Researcher (haiku, low effort): Collect latest best practices
- Implementer (Fable 5): Apply changes to code
- Tester: Run full test suite
Only merge after all subagents reach consensus.# Automatic Code Review Skill
Triggers: File edits in src/ or PR creation
Instructions:
- Review for tests, edge cases, security, performance, readability
- Suggest improvements in JSON format: {"issues": [...], "suggestions": [...]}
- Auto-apply safe fixes when confidence >80%Invoke with @auto-review in prompts.
const { execSync } = require('child_process');
try {
execSync(`eslint --fix ${process.env.FILE}`);
console.log(`Linting applied to ${process.env.FILE}`);
} catch (e) {
console.log('Linting warnings present');
}Connect via MCP to GitHub.
Create a draft PR for the current branch.
Include:
- Clear title and description
- Test results summary
- Security checklistVoice lets you specify complex, nuanced goals faster than typing. Best used in a hybrid workflow: dictate the intent, refine into a structured /goal loop.
Claude mobile/web voice captures nuance and constraints.
Paste transcript, ask Claude to produce a full rubric + verifier spec.
Executor runs; verifier scores; you review the diff.
Refine this voice transcript into a complete executable /goal loop with detailed rubric and verifier instructions.
[PASTE TRANSCRIPT HERE]/goal: Review, fix, and create draft PR for branch 'feature/new-feature'.
Loop steps:
1. Checkout in isolated worktree
2. Run full tests + linter + security scan
3. Analyze changes and generate improvements
4. Create/update draft PR with detailed summary, test report, and checklist
5. Iterate fixes up to 4 times
Use Fable 5 for orchestration.Fable 5 excels at long-horizon autonomous tasks: research reports, content pipelines, business ops.
/goal: Create a comprehensive Q3 market analysis report on AI coding assistants.
Requirements:
- Cover major players with citations
- Include SWOT analysis and recommendations
- Professional Markdown format with tables
- Verify all facts across multiple sources
Run as a daily Routine.Create a detailed blog post on "Loop Engineering Best Practices".
Process: Outline → Draft sections with voice input → Self-critique → Revise → Format for publication.Process leads from leads.csv:
- Personalize outreach emails using template
- Send via approved MCP integration
- Track responses in loop
- Generate daily summary reportmain: fable-5
workers:
- name: scout
model: haiku
effort: low
- name: executor
model: sonnet# Loop Progress
Current Goal: ...
Attempts: ...
Learnings: ...
Next Actions: ...Monitor lint/test issues in your repo and auto-fix in a worktree loop.
Start with a ready-made loopScheduled routine that gathers, summarizes, and emails key insights.
Start with a ready-made loopCombine loops + subagents into an autonomous content generator + publisher.
Start with a ready-made loopAutomate a real ops process end-to-end (leads, reports, follow-ups).
Start with a ready-made loopStart with a simple loop, measure impact, then expand. The best way to master loop engineering is by shipping them.