How Coding Agents Actually Work
How do tools like Claude Code, Cursor, and Devin actually write code? The ReAct loop, tool calling, and context management — animated.
You type "fix the auth bug in login.py" and press Enter. Ten seconds later, the agent opens three files, finds the issue, writes a fix, and runs the tests. All green. Most developers assume the answer is some sophisticated multi-phase planner. But at the core of every major coding agent — Cursor, Claude Code, Copilot, Devin — there's the same fundamental pattern. A while loop.
The Core Loop
while not done:
think → act → observe
The agent reads your prompt. It decides what to do next. It takes an action. It looks at the result. And it loops — until the task is done or it gets stuck.
Trace a real example. You say "fix the auth bug." The model reasons: "I should read login.py first." It calls file_read and gets back the source code. It reasons again: "Line 42 is checking the token wrong." It calls file_edit and patches the line. Then: "Did that work?" It calls bash and runs the test suite. Tests pass. Done.
Three trips around the loop. Think, act, observe.
The Brain Needs Hands
An LLM by itself is a brain in a jar. It can reason, plan, and generate code — but it can't touch a file or run a command. It lives entirely inside text.
Tools are the bridge. When the model decides to act, it outputs a structured message: "call this tool, with these arguments." A program called the harness catches that message, executes the tool, and feeds the result back into the conversation.
The model never touches your filesystem directly. It writes instructions. The tools are its hands.
| Agent | Approximate Tool Count | Notable Capability |
|---|---|---|
| Cursor | ~10 | IDE-integrated editing |
| Claude Code | ~20 | Terminal + file system |
| Devin | Full VM | Browser, shell, everything |
Same core pattern, different hands. And the quality of the model matters enormously — a smarter model picks better tools, in a better order, with better arguments.
The Context Window Is the Real Constraint
Every tool result, every file read, every error message — it all flows into one container: the context window. This is the agent's entire working memory, and it's not infinite.
Every trip around the loop adds more. The window fills. And here's what most developers don't realize: the agent starts degrading before the window is full. Research shows that information in the middle of long contexts tends to get lost — the model pays strongest attention to the beginning and the end.
Close the session? Gone. The window empties completely. Next session starts from zero. Most agents work around this with a simple trick: a text file loaded at the start of every conversation with notes about your project and preferences.
How to Use Agents Better
Now that you see the architecture, use it:
- Be specific. Every vague word wastes precious context. "Fix the bug" forces search loops. "Fix the token check on line 42 of login.py" gets there in one shot.
- Break big tasks into small ones. A fresh context window is a sharp context window. Start new sessions often.
- Let it loop. The agent tries, fails, reads the error, and tries again. That's not a bug — that's the architecture working.
These tools aren't magic. They're a while loop, a set of tools, and a window of memory. And now you know exactly what happens every time you press Enter.
Watch the full animated breakdown: How Coding Agents Actually Work
