Build agent loops directly with Anthropic SDK
The agentic pattern is a ~40-line loop: call the model, run requested tools, feed results back, repeat until stop_reason !== "tool_use" — skip framework overhead entirely.
June 5, 2026
Summary
Eliminates confusion between Claude Code (Anthropic's CLI) and DIY agents built on the SDK. Gives developers a concrete, minimal implementation to own rather than inheriting black-box framework assumptions.
Why it matters
Eliminates confusion between Claude Code (Anthropic's CLI) and DIY agents built on the SDK. Gives developers a concrete, minimal implementation to own rather than inheriting black-box framework assumptions.
Implementation verdict
Replaces agent framework abstractions with explicit loop control. Requires understanding the four key patterns (append assistant turn verbatim, match tool_use_id, batch results in single user message, cap iterations). Ready now — author provides MIT-licensed Next.js starter (AgentLoop) deployable in one command.
Sources
- 1.the agentic CLI, CLAUDE.md files, slash commands, hooks
- 2.Most "agent frameworks" just hide that loop from you. It's small enough that you don't need them.
- 3.The four things people get wrong: Append the assistant turn verbatim — so the model sees its own tool request on the next call.
- 4.One tool_result per request, matched by tool_use_id.
- 5.Send all results back in a single user message.
- 6.Cap the turns so a confused model can't loop forever.
- 7.the whole agent in ~150 readable lines, no framework
Dev Signal
Get briefs like this in your inbox — free, 3x a week.
100+ sources compressed into one 4-minute read. Ranked, cited, implementation-ready.