How Claude Code Works (Let’s Build a Tiny One) A new technical explainer walks through building a working coding agent in a single Python file with no libraries, using the OpenAI chat completions format to connect to Groq, OpenRouter, NVIDIA or a local Ollama model. The post's central claim is that "an agent is a while-loop around one API call" and that everything else is guardrails and memory, built on the fact that an LLM remembers nothing between calls and must be resent the full conversation each time. It details token accounting (roughly 4 characters per token, about 1,300 tokens per 1,000 English words), context windows, system prompts, and tool calling as the mechanism by which a text-only model reads files and runs commands. When you first watch a coding agent like Claude Code work, it feels like magic. You type “add a test for this function”, and it reads your files, writes code, runs the tests, notices a failure, fixes it and tells you it’s done. It isn’t magic. Underneath, it’s a surprisingly small idea, wrapped in a lot of careful engineering. In this post I’ll start from absolute zero what a language model even is and end with a working coding agent you can run on your own machine: one Python file, no libraries to install, working with Groq, OpenRouter, NVIDIA, or a model running locally with Ollama. If you remember one sentence from this post, make it this one: An agent is a while-loop around one API call. Everything else is guardrails and memory. Let’s earn that sentence. A large language model LLM , like Claude, Gemini or GPT, does exactly one thing: given some text, it predicts what comes next. It does this one small piece at a time, very fast, after learning from an enormous amount of writing. Chat, code, reasoning, agents: all of it is built on that one ability. Models don’t read letters or words. They read tokens : chunks of text, about ¾ of an English word on average. hello is one token; a long word might be two or three; 1,000 words of English come to roughly 1,300 tokens. A handy rule of thumb is about 4 characters per token , which is exactly what our agent will use later to measure its conversation. Tokens matter because everything is measured in them: how much the model can read at once, how fast it answers, and what you pay. The context window is how much text the model can look at in one go. Think of it as a desk. Everything the model needs for its next answer has to fit on that desk: its instructions, the conversation, the files it read, the output of the commands it ran. If something isn’t on the desk, the model can’t see it. Hold on to that; it becomes important when conversations get long. Here’s the thing that surprises most people. An LLM remembers nothing between calls . Every request starts from a blank slate. When a chat app seems to remember what you said five messages ago, that’s because the app sends the entire conversation again, every single time . Three consequences follow, and we’ll meet all of them: A conversation is sent as a list of messages , each with a role : The system prompt is the first message: the model’s job description. It’s the main way to shape behavior without retraining anything. You talk to a hosted model by POSTing your messages as JSON and getting JSON back: POST https://api.groq.com/openai/v1/chat/completionsAuthorization: Bearer