AgentLoop is a Claude agent starter project for developers, designed to provide a readable and clearly structured implementation of an agent loop. It is based on Next.js (App Router) and TypeScript, uses the official Anthropic SDK, and concentrates its core logic in the app/api/chat/route.ts file, with about 150 lines of code. The project uses the MIT license and is provided for free.
Purpose: AgentLoop is used to help developers quickly understand and build Claude-based AI agents. It demonstrates the basic pattern of an agent loop: send a conversation to the model, execute the tools the model calls, append the results to the conversation, and repeat this process until the model returns an ordinary text response. The loop is limited to a maximum of 5 steps.
Main capabilities:
- Streaming chat: Uses native fetch and ReadableStream to render tokens in real time, with no UI dependency and no SDK lock-in.
- Real tool calling: Implements a working agent loop, rather than simple conditional checks.
- Two example tools: get_current_time and calculate, and provides a single-function extension point for easily adding custom tools.
- Typed and commented: The code includes type definitions and comments, and stays in sync with current Claude models.
- One-click deployment: Supports one-click deployment to Vercel.
How to use:
- Clone the repository.
- Get an API key at console.anthropic.com.
- Set the ANTHROPIC_API_KEY environment variable.
- Run the project, and you can ask the agent questions such as "what is (12 * 9) + 7?" to observe it calling the calculate tool.
- When deploying to Vercel, set ANTHROPIC_API_KEY in the project environment variables and it can go live.
Adding custom tools: You only need to make two edits in the lib/tools.ts file, and Claude will read the tool descriptions to decide when to call them.
Applicable scenarios:
- Developers learning how AI agents work.
- Teams that need to quickly build a Claude agent prototype.
- Developers who want to avoid black-box frameworks and bloated SaaS templates.
- Those who need to build their own agent products based on the Anthropic SDK.scenario.
Limitations and additional information:
- The project core is free and uses the MIT license, but AgentLoop Pro is a paid version that provides production environment fixes, uses a pay-as-you-go model, starts at $9 (originally $29), includes a commercial license, unlimited projects, and is available on Ko-fi.
- The author provides a free Agent Token Profiler tool that runs in the browser, requires no registration or key, and is used to analyze the token consumption of an agent per conversation turn and flag the approximately 20% waste caused by serialization redundancy (such as $schema, title added by Pydantic).
- The author also published a study that measured the actual cost per conversation turn of 13 real open-source AI agents (79 tools), pointing out that GitHub's MCP server resends 3,546 tokens per turn.
- AgentLoop Pro includes 29 tests, can be run via npm test, and supports running on Claude or any model (via OpenRouter) through the ModelCaller seam.
- The project is publicly built by an independent developer.