How AI coding agents work: the loop behind the edits
A plain-language tour of the plan, context, build and repair loop so you can steer an AI coding agent instead of fighting it.
What an AI coding agent actually is
An AI coding agent is a language model with tools, running in a loop. That single sentence is most of the answer to how AI coding agents work. The model itself predicts text. It does not hold your app in its head, and it does not know what your code does until something puts that code in front of it. What makes it an agent is that it can call tools (read a file, write a file, run a build) and then look at what came back before deciding the next step.
Anthropic's guide to building effective agents separates workflows, where models and tools are orchestrated through predefined code paths, from agents, where the model directs its own process and tool use. Most coding tools sit between those two. That matters because it explains both the flexibility and the unpredictability: nobody scripted the exact sequence of steps the agent takes.
The rest of this guide walks the loop in order, then covers where it breaks and how to phrase requests so it breaks less.
Planning: turning a request into steps
A request arrives as a sentence. The agent has to turn it into actions: which files to read, which to change, what to leave alone, in what order.
Some tools make this visible. In Draftship, Plan mode writes a short plan and changes nothing, so you can read the intended steps before any file is touched. The newest plan carries a Build this plan button that hands it to Build mode. Discuss mode answers questions without editing.
Skipping the plan is the cheapest mistake to make and the most expensive to fix. A wrong assumption in step one becomes a wrong edit in step four, and by then the agent has built on it.
Context: why the agent reads some files and not others
Two limits decide what the agent can see.
The first is the context window: a fixed budget of text the model can consider in one turn. Everything outside that budget is invisible, including files that matter. The second is retrieval, the mechanism that decides what gets loaded into the budget. A tool might send the whole project, a subset of files, or only what the agent explicitly asks for.
This is why an agent sometimes invents a field name that already exists, or rewrites a helper it never saw. It is not ignoring your code. It never read it.
In Draftship, each message sends the current files together with your request, and the AI returns only the files it needs to create or modify. That keeps a change small and stops unrelated files drifting. Standing context has its own place: AI instructions are read on every message for that app, while skills are read only when a request calls for them. Both are ways of spending context on what is relevant instead of repeating yourself every time.
Writing changes and running the build
Once the agent has decided what to change, it writes the edit. In a coding tool, the build is the moment of truth. Code that reads well can still fail: a missing import, a component that does not exist, a data shape that does not match.
In Draftship, one message is one job. The AI thinks, writes files, Draftship builds the app, and fixes the build if needed. One job runs per project at a time, and on Pro and above jobs can run in three projects at once.
That build step is what closes the loop. Without it, an agent is producing plausible text and hoping. With it, the tool has evidence.
Repair loops: reading an error and trying again
When a build fails, the error is the most valuable input the agent gets. A good loop passes the error back, the agent forms a hypothesis, makes another edit, and builds again.
This is where agents earn their keep and where they waste the most time. An agent that patches the symptom rather than the cause can move the error around: it changes shape, appears in a different file, or returns after two more edits. Errors that name a file and a line are far easier to repair than a generic failure message, so paste the full error rather than a summary of it.
It also helps to know when to stop the loop yourself. If two repairs have not changed the error, the problem is usually a missing piece of context, not a stubborn bug.
Why agents fail
Most failures come from three places.
Missing context. The file that defines your data shape was never read, so the agent guessed. Fix: name the file, or attach a sample.
Ambiguous requests. A vague request to make the dashboard better gives the agent no test it can pass, so it picks an interpretation and commits to it. Fix: describe the outcome and the constraint separately.
Long tasks. A message that touches sign-in, billing and layout at once multiplies the number of steps, and each step is a chance to drift. Fix: one change per message where you can.
There is a fourth, quieter cause: the agent does what you said rather than what you meant. A specific sentence late in a long message can override an instruction you gave earlier, even one stored in your app's settings.
Writing requests that work with the loop
Treat each message as a task with a definition of done.
- Say what should exist afterwards, and what should stay the same.
- Name the screens, files or tables involved if you know them.
- Give one example of the thing you want: a pasted JSON sample, a few rows of real data, a line of copy in the right voice.
- Put standing rules (audience, tone, things never to change) in AI instructions instead of repeating them.
- Paste errors in full.
- Use Plan mode for anything spanning more than a couple of areas.
Three example prompts, written for Draftship:
Plan:
Plan: add a waiting list to the landing page. Collect an email, store it, show a thank you state. Do not change the pricing section.
Build:
Add an email field to the existing waitlist table and show the count on the admin page. Use the existing table component and do not restyle anything else.
Repair:
The build failed with: [paste the full error]. Fix the cause, not the symptom. Do not change other files.
Notice what these have in common: each one narrows the search space and gives the agent a way to tell whether it succeeded.
Doing it with Draftship
Draftship runs this loop for you. You describe the app or the change in plain language, the AI writes files, the app is built and hosted, and build errors go back to the AI to fix. There is nothing to install and no local setup.
A few things make the loop easier to steer. Chat modes separate thinking from changing, so you can plan without touching a live app. Skills and AI instructions hold the context you would otherwise repeat. And the model picker lets Pro and above choose a model that suits the job, with Draftship AI as the default on every plan.
Start with one clear sentence about what you want to exist, then read what the first build tells you.
Primary sources
- Building effective AI agents \ Anthropic · anthropic.com
This article was drafted with AI assistance from the primary sources listed below and checked automatically against them. An editor hasn't reviewed it yet.