I rebuilt a Claude Code–style coding agent from scratch — the whole agent loop is 6 lines. 20 chapters, ~5k lines, no frameworks, runs on local models too

Reddit r/AI_Agents Tools

Summary

A developer shares a 20-chapter tutorial rebuilding a Claude Code–style coding agent from scratch, showing the entire agent loop in ~6 lines, with support for local models and multiple LLM APIs.

I kept using coding agents without really knowing what happened inside the box, so I rebuilt one from scratch. The agent loop turns out to be \~6 lines — tools, sessions, compaction, subagents, skills, MCP, and streaming are all just the harness around it. 20 short chapters (one Python file + one explainer each) build up to an \~850-line Claude-Code-shaped CLI. No frameworks. 42 tests pass with no API key (mocked LLMs + a real MCP subprocess). Chapter 17 ports the same loop to OpenAI + Gemini, so it runs against any OpenAI-compatible endpoint — llama.cpp / Ollama / vLLM included. Would love feedback on what's missing or wrong, especially from people running agents on local models.
Original Article

Similar Articles

AI agents still suck, so I built my own

Reddit r/AI_Agents

The author built a custom AI agent application wrapping Claude Code and upcoming Codex support, focusing on composable workflows and seeking community feedback.