Claude Code loops let an agent repeat a task until it hits a stop condition. They are the most powerful execution primitive in agentic AI right now. And most of them fail for the same reason: they loop over empty context. The agent starts cold every cycle, re-derives everything, burns tokens, and compounds generic output. The fix is not a better loop. It is loading the brain before the loop runs.
What Are Claude Code Loops, and Why Is Everyone Talking About Them?
On July 7, 2026, Anthropic's Claude Code team published their official "Getting started with loops" guide. It defines three primitives that turn Claude Code from a one-shot assistant into a persistent execution engine.
/goal sets verifiable stop conditions. Instead of "keep going until it looks good," you define a concrete, checkable state the agent must reach before it stops. This is what separates a useful loop from an infinite billing cycle.
/loop runs on an interval. The agent executes, pauses, then executes again. Periodic, like a cron job with reasoning built in.
/schedule triggers execution based on events. Something happens, the agent responds. Reactive instead of periodic.
Then there are turn-based agentic loops, where the agent runs a full reasoning cycle, produces output, evaluates it against the goal, and decides whether to continue or stop.
Under the hood, the Agent SDK exposes the same execution cycle that powers all of this: Claude evaluates a prompt, calls tools to take action, receives the results, and repeats. Each round trip is a "turn." A quick question might take one or two turns. A complex task can chain dozens of tool calls across many turns, with the agent adjusting its approach based on each result.
"Loop engineering" is trending across X right now, with over 2,200 posts on the topic. Anthropic's Boris Cherny and OpenAI's Peter Steinberger are championing the pattern. Matt Pocock is offering sharp critique. The conversation is moving fast because loops solve a real problem: they let agents do sustained, autonomous work instead of answering one question and forgetting everything.
But the conversation is missing something critical. Everyone is talking about the engine. Almost nobody is talking about the fuel.
How the Agent Loop Actually Works Under the Hood
Most loop engineering content stops at the surface. Here is what actually happens inside the loop, according to Anthropic's own agent loop documentation.
The cycle is five steps. The agent receives your prompt along with the system prompt, tool definitions, and conversation history. Claude evaluates the current state. It responds with text, tool calls, or both. The SDK executes those tool calls and feeds the results back. Steps two and three repeat until Claude produces a response with no tool calls. Then it returns the final result.
Context accumulates. It never resets. Everything piles up across turns within a session: the system prompt, tool definitions, conversation history, tool inputs, tool outputs. Content that stays the same across turns gets prompt-cached, which reduces cost for repeated prefixes. But everything else grows.
Large tool outputs are the silent killer. Reading a big file or running a command with verbose output can consume thousands of tokens in a single turn. Multiply that by a loop running dozens of cycles and you see the problem. This is where unscoped loops become billing incidents.
Automatic compaction is a band-aid, not a cure. When the context window approaches its limit, the SDK compacts the conversation by summarizing older history. That summary loses specific instructions from early in the session. If your standards were only in the initial prompt, they get compressed away. This is exactly why persistent, reloadable context matters: it survives compaction because it gets re-injected on every request.
Turns can be capped, but most people do not cap them. The SDK offers max_turns and max_budget_usd as safety limits. Without them, the loop runs until Claude finishes on its own. For a well-scoped task, that is fine. For an open-ended prompt like "improve this codebase," that is a blank check.
Understanding this architecture changes how you think about loops entirely. A loop is not a magic instruction that makes the agent autonomous. It is a cycle that compounds whatever you feed into it. Feed in scoped context and clear standards, you get compounding quality. Feed in nothing, you get compounding cost.
The Failure Mode: Loops Without Context Are the Cold-Start Problem at Scale
Here is what actually happens when most people set up a loop.
The agent starts a cycle. It has no memory of your voice. No knowledge of your standards. No record of what it decided last cycle. This is why agents forget between runs, and loops make it worse. So it re-derives everything from scratch. It reads files it already read. It makes decisions it already made. It produces output that is technically correct but generically wrong, because it has no idea what "right" looks like for your specific system.
Then it loops again. Same cold start. Same re-derivation. Same generic output. Every tick.
This is the cold-start problem that makes AI content sound like AI, and loops turn it from an annoyance into an operational hazard.
Anthropic's own guide flags the cost trap directly. A /loop that re-reads an entire monorepo every tick has a far worse cost profile than one that calls a focused, scoped context. That is not a theoretical risk. That is the default behavior when you set up a loop without boundaries.
The agent loop documentation confirms why: context accumulates across turns, large tool outputs consume thousands of tokens, and without max_turns or max_budget_usd limits, the loop runs indefinitely. You are paying for every re-derivation, every redundant file read, every decision the agent already made but forgot.
And the output is not just expensive. It is mediocre. An agent that writes a blog post with no voice rules loaded will produce something generically competent. An agent that builds a landing page with no brand context will produce something that looks like every other template. An agent that writes code with no architectural standards will produce something that works but creates tech debt. Multiply that by a loop running 30, 40, 50 cycles, and you have an expensive machine producing consistent mediocrity at scale.
Most people building with loops right now are building engines with empty fuel tanks. The engine runs. It just produces nothing useful, expensively.
The Fix: Load the Brain Before the Loop Runs
The solution is not to avoid loops. Loops are the right execution primitive. The solution is to make sure the agent starts every cycle warm instead of cold.
That means three things happen before the first tick.
Scoped context, not the whole repo. The agent gets exactly the files, standards, and prior decisions it needs for this specific task. Not everything. Not a summary of everything. The precise, relevant context that lets it reason correctly without re-discovering your entire codebase. The Agent SDK supports this through setting sources that load CLAUDE.md files, skills, and hooks from your project directory. Those get re-injected on every request, surviving compaction. That is the mechanism.
Standards loaded on startup. Your voice rules, compliance guardrails, quality checks, and formatting requirements are present from the first token of the first cycle. The agent does not guess at your preferences. It reads them. This is the difference between an agent that writes in your voice and one that writes in default ChatGPT voice. The standards are not suggestions. They are constraints the agent must follow on every tick.
Memory of prior decisions. If the agent decided something last cycle, it knows that this cycle. It does not re-derive the same conclusion. It builds on it. The SDK supports session continuity through session IDs: capture the session_id from the result, pass it back to resume, and the full context from previous turns is restored. But session continuity alone is not enough. You need the standards to persist across sessions, not just within them.
When you load the brain before the loop runs, every tick starts where the last one left off. The agent reasons with your context, not against the void. Output gets better each cycle instead of staying generically flat.
Loops are the execution engine. Context is the fuel. You need both.
The Real System: Agents Talking to Agents, With a Second Brain for Standards
I have been running this pattern manually for a while now. Not as a concept. As an operating system for real production work across every channel I operate.
The architecture looks like this. Multiple specialized agents, each with a clear job, handing work to each other. And a second brain (think Obsidian-style, with routing rules) that every agent reads before it starts working. The second brain holds the standards: voice, compliance, quality, formatting. Every agent follows the same rules because every agent loads the same brain.
This maps directly to how the Agent SDK handles subagents. Each subagent starts with a fresh context window. It does not see the parent agent's full transcript. It loads its own system prompt and project-level context. It does its work. And only its final summary returns to the parent. The parent's context grows by that summary, not by the full subtask transcript. That keeps the main loop lean.
But the SDK gives you the mechanism. What matters is what you load into it.
How This Runs the Blog
This blog is a live example of that system in production.
A writer agent produces the post you are reading right now. It loads the second brain on startup: voice rules (short paragraphs, answer-first, no banned tokens), compliance guardrails (no income claims, capability framing only), structural requirements (pillar or cluster, FAQ in frontmatter, internal linking density), and the positioning framework (who the audience is, what the blog is for, how it fits the funnel).
A separate publishing agent formats and ships the post. It loads the same brain. It knows the MDX contract, the frontmatter schema, the image conventions, the canonical URL structure.
Neither agent guesses. Neither re-derives standards. Both read from the same brain before they start. The output is consistent because the constraints are consistent.
How This Runs Social Content
The same architecture runs short-form content for social media. A content agent takes a topic or a blog post and produces hooks, scripts, and captions. It loads the brain on startup: the hook patterns that convert (build reveals, contrarian operator takes, reclaimed-time proof, case study opens, cost-cut hooks), the compliance guardrails (no income claims, no get-rich framing, no financial opportunity openers for TikTok's classifier), and the voice rules.
For Instagram carousels, a carousel agent handles the structure: slide count, text density per slide, visual hierarchy, the swipe-stopping opener, the CTA slide. It loads the same brain for voice and compliance, plus carousel-specific structural rules. A design agent handles the visual layer. Both agents share standards. Neither one invents the brand from scratch.
Every piece of short-form content follows the same rules the blog follows, because every agent reads from the same second brain. The voice stays consistent across a blog post, a TikTok script, and a 10-slide carousel, not because I manually enforce it, but because the brain enforces it.
How This Runs Coding Agents
The pattern extends to code. A build agent writes features. A review agent checks code quality against architectural standards. Both load from the same brain: the tech stack conventions, the file structure rules, the testing requirements, the deployment constraints.
When the build agent hands work to the review agent, the review agent does not re-derive what "good code" looks like for this project. It reads the standards and evaluates against them. The feedback loop is tight because the standards are shared, not re-invented.
How This Runs Landing Pages
Landing page agents follow the same architecture. A copy agent writes the page: headline, subhead, body sections, social proof, CTA. It loads the brain for voice, compliance, and funnel logic (cold traffic goes to the masterclass, warm traffic goes to the community offer). A layout agent structures the visual hierarchy. Both share the same brand context.
The result is a landing page that sounds like me, follows the funnel rules, and stays compliant, without me writing every word or reviewing every layout decision. The agents do the work. The brain ensures the work meets the standard.
The Feedback Loop: oAuth, Results, and a Brain That Gets Smarter
Here is where most people stop. They build agents, load context, run loops, and ship output. Then they start over next time with the same static brain.
That is a one-way system. Context goes in. Output goes out. Nothing comes back.
The next layer is closing the loop. Not just pushing context to agents, but pulling results back from the services where the work actually lands, and using those results to retrain the brain.
This is what oAuth integrations make possible. When your agents are authenticated to the platforms where your content, code, and pages live, they can read the results of their own work. Not just "did it publish?" but "how did it perform?"
The blog agent publishes a post. An oAuth connection to analytics pulls back the data: which posts got cited by AI answer engines, which ones ranked, which sections got pulled into featured snippets, which ones fell flat. That data feeds back into the brain. The voice rules, structural patterns, and content angles get refined based on what actually worked, not what we assumed would work.
The social content agent publishes a carousel or a short-form video. An oAuth connection to the platform pulls back completion rates, saves, shares. The brain learns which hook patterns actually drive engagement versus which ones we thought would. The question-opener pattern that gets three times the completion rate on TikTok? That was a learning that came from closing this loop. It is now loaded into the brain as a constraint, not a guess.
The coding agents ship a feature. oAuth connections to monitoring and error tracking pull back the results: crash rates, performance metrics, user-reported issues. The architectural standards in the brain get tightened based on what caused real production problems, not theoretical best practices.
The landing page agent ships a page. oAuth connections pull back conversion data. The funnel logic in the brain gets refined: which headline patterns convert cold traffic, which CTA placements work, which page structures hold attention.
Each cycle makes the brain smarter. The agents do not just execute. They learn. Not in the vague "AI learns from data" sense. In the concrete, operational sense: results come back, the brain updates, the next cycle starts with better standards than the last one.
This is the difference between a static prompt library and a living operational system. A prompt library gives you the same output forever. A brain that closes the feedback loop compounds. Every cycle of work makes the next cycle better.
Why This Pattern Is Becoming the Backbone of Focus Pilot
I am building Focus Pilot in public. This post is part of that.
The manual system I described above works. I run it every day across blogging, social content, coding, and landing pages. But it is manual. I wire up the agents. I maintain the second brain. I route the context. I set up the oAuth connections and build the feedback pipelines. That is fine when I am the only operator, but it does not scale to a team or a product.
Focus Pilot productizes this entire pattern. Persistent memory and context routing so your agents (and your loops) start warm, with your standards already loaded, instead of cold every cycle. Agent-to-agent orchestration so specialized agents hand work to each other with shared context. And the oAuth feedback loop so the brain learns from real results, not static assumptions.
The core capabilities, framed as what Focus Pilot does:
Persistent memory with context routing. You build a second brain of standards, voice, compliance rules, and operational context. Focus Pilot routes the right context to the right agent at the right time. When a loop runs, it reads from your brain on the first tick. When an agent hands work to another agent, both agents share the same loaded context.
Agent-to-agent orchestration. Specialized agents with clear roles, handing work to each other, with the brain enforcing standards across all of them. Not a single monolithic agent trying to do everything. A system of focused agents that coordinate.
oAuth-powered feedback loops. Authenticated connections to the services where your work lands. Results flow back into the brain. The standards that govern your agents are refined by the outcomes those agents actually produce. The system gets smarter with every cycle.
This is what "agents talking to agents" looks like when it is a product instead of a manual wiring job. The agent knows your voice. It knows your rules. It knows what happened last cycle. It knows what worked and what did not. It starts warm.
I am building this live, documenting the process in the community, and shipping updates as they land. If you want to watch an agentic product get built using the exact pattern it is productizing, that is what is happening right now.
Frequently Asked Questions
- What is a Claude Code loop?
- A loop is a repeating agentic cycle where Claude Code executes a task, checks a stop condition, and runs again until the goal is met. Anthropic's official guide defines three primitives: /goal for verifiable stop conditions, /loop for interval execution, and /schedule for triggered runs. The Agent SDK exposes the same cycle programmatically: Claude evaluates, calls tools, receives results, and repeats until the task is complete or a budget limit is hit.
- Why do Claude Code loops burn so many tokens?
- Loops without scoped context re-read and re-derive everything on every tick. A /loop that ingests an entire monorepo each cycle has a far worse cost profile than one that calls a focused, pre-loaded context. The Anthropic agent loop doc confirms that large tool outputs consume thousands of tokens per turn, and context accumulates across turns. Boundaries and loaded context are the fix.
- What is the cold-start problem in agentic loops?
- Cold start means the agent begins every cycle with zero memory of your standards, voice, or prior decisions. It re-derives context from scratch each tick, which burns tokens and produces generic, inconsistent output. Loading a second brain of standards before the loop runs eliminates cold start and turns each tick into a compounding step instead of a reset.
- How do I make Claude Code loops more reliable?
- Load scoped context before the loop executes. Define your standards, voice rules, and quality checks in a persistent second brain that every loop tick reads on startup. Use /goal with verifiable stop conditions so the loop knows when to stop. Set max_turns and max_budget_usd as safety limits. Use subagents for subtasks so the main context stays lean.
- What is agents talking to agents?
- It is an orchestration pattern where multiple specialized agents hand work to each other, with a shared second brain enforcing standards across all of them. Each subagent starts with a fresh context window but loads the same persistent standards. The parent agent's context grows only by the subagent's final summary, not its full transcript. This keeps loops lean and output consistent.
Related Articles
I'm building this in public. Come build with me.
The Sprint: Focus Pilot, live weekly mentorship, and a community of operators who ship with AI.

Matt Ganzak
Founder, The Sprint & ScaleUp Media
25+ years building software companies. Multiple SaaS exits. Bestselling author of The Million Dollar Plan. Writes about running AI agents for real operational work.