Claude Code in 9 lines Python
A Reddit thread on the LocalLLaMA community surfaced a demonstration showing that the core loop of Claude Code — Anthropic's agentic coding assistant — can…
By Dillip Chowdary • Aug 10, 2026 • Source: HN Claude/Codex/Fable
What happened
A Reddit thread on the LocalLLaMA community surfaced a demonstration showing that the core loop of Claude Code — Anthropic's agentic coding assistant — can be reproduced in roughly nine lines of Python. The post drew enough attention to reach Hacker News, where it was tagged alongside discussions of Codex and Fable, another AI coding tool. The premise is straightforward: strip away the terminal interface, the streaming polish, and the CLI scaffolding, and what remains of Claude Code's fundamental logic is surprisingly thin.
The technical claim being made is that the agentic loop itself is not the hard part. Claude Code, like most LLM-driven coding agents, operates on a pattern that is structurally simple: send a prompt to the model, receive a response that may contain tool calls, execute those tool calls against a local environment, feed the results back into the context, and repeat until the model stops requesting actions. In Python, with the Anthropic SDK, that loop can be expressed in very few lines because the SDK handles the HTTP layer, the tool-call schema, and the message structure. What the nine-line version omits is everything around that loop: safety checks, diff previews, permission prompts, working directory management, shell sandboxing, and the accumulated prompt engineering that makes the agent behave reliably across diverse codebases.
The technical detail

For engineers and builders, this demonstration has practical value as a teaching artifact. Understanding that the agentic loop is a while-loop over an API call removes the mystique and lowers the barrier to building custom coding agents. A developer who needs a coding assistant tailored to a specific stack, with custom tools, restricted scope, or integration into an internal CI system, does not need to fork Claude Code or replicate its full surface area. They can write the minimal loop, add only the tool definitions their use case requires, and wire it to whatever model API is available. The nine-line framing is a useful mental model even if the production version of any real tool will be far longer.
Advertisement
Tech Pulse Daily
Get tomorrow's pulse first
Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.
Why it matters for builders
In the competitive context, this sits alongside a growing set of demonstrations that aim to demystify the leading AI coding tools. OpenAI's Codex has gone through multiple public iterations, and its agentic capabilities have similarly been reproduced in stripped-down open-source projects. Fable's inclusion in the HN tag cluster suggests the thread was being read alongside discussions of narrative or game-scripting agents, which share the same loop structure but apply it to different tool sets. The broader point the community is working out is whether the value in products like Claude Code lives in the model weights, the prompt engineering, the UX, or some combination — and demonstrations like this one push toward the answer that the loop architecture itself is a commodity.
Market and competitive context
The practical takeaway for someone watching this space is to focus on what is not in those nine lines. Anthropic has invested heavily in the scaffolding that makes Claude Code usable in real development environments: the handling of large file contexts, the git-aware diffing, the interactive approval flow, and the testing integrations. A nine-line loop will hallucinate file paths, overwrite things it should not, and stall on ambiguous instructions without that scaffolding. The interesting engineering work is in making the loop robust, not in writing the loop itself. Builders evaluating whether to use Claude Code versus a custom agent should be asking about those surrounding systems, not the loop.
What to watch next
There are open questions the thread raises without answering. The first is how much of Claude Code's quality advantage comes from model-level fine-tuning specific to the agentic loop versus the surrounding infrastructure. If Anthropic has fine-tuned Claude to be a better tool-calling agent than the base API model, then the nine-line reproduction using the same API is implicitly benefiting from that work even in its minimal form. The second question is about context management: a nine-line loop will run into token limits quickly on any real codebase, and none of the summarization or retrieval strategies that make long-horizon coding tasks tractable are present. The prior art here includes Microsoft's original AutoGen architecture and the many open-source agent frameworks that have been exploring these problems since 2023. The nine-line version is a clean entry point, but the lineage of what it is compressing is much longer.
Advertisement