Claude · 03 · Part 2

What Exactly Is a Coding Agent?

"Agent" is used loosely. This page gives the term a precise meaning: a model alone is not an agent, a chat window is not an agent, and an agent is more than a model with a longer prompt. You will see the six parts every coding agent is built from, the loop they run in, and a small program that performs that loop with real file edits and a real compiler.

6
Vocabulary terms
6
Agent parts
1
Runnable loop
Information current as of: 2026-10-30
01
Chapter One · Vocabulary

Six Terms, One Ladder

Each term below adds one capability to the previous one. The line between them is what the system can do, not what it is called in a product page.

What each rung adds
LLMtext in, text out. No memory of you, no actions. AI assistant+ a conversation and instructions around the model. AI coding assistant+ sees your code; proposes edits. You run and verify. Coding agent+ tools and a loop: acts, observes, repeats until done. Agentic workflowagents chained into a repeatable multi-step process. Multi-agent systemseveral agents with separate contexts that coordinate.
TermDefinition used in this guideExample
LLMThe model itself: predicts text from input text.A Claude model called through an API.
AI assistantA product that wraps an LLM with a conversation and instructions.A chat window.
AI coding assistantAn assistant that can see code and propose changes; the human executes.Inline suggestions and in-editor chat.
Coding agentAn LLM plus tools in a loop that takes actions on a codebase and reads the results.Claude Code, Codex, Cline.
Agentic workflowA multi-step process built from agent steps, often with a fixed structure."Review PR, run tests, post comments".
Multi-agent systemSeveral agents, each with its own context, coordinating on one job.A lead agent delegating to subagents.

Anthropic draws a related line between workflows, where an LLM and tools are orchestrated through predefined code paths, and agents, where the LLM itself decides its steps and tool use and stays in control of how the task is done (Source 1). A coding agent in the sense of this chapter is the second kind.

02
Chapter Two · Architecture

The Six Parts of a Coding Agent

Every coding agent is the same six ideas assembled differently. The model is only one of them. Claude Code's documentation makes the split explicit: models reason, tools act, and Claude Code is the layer around the model that provides the tools and manages the context the model sees — the agentic harness (Source 2).

LLM + Instructions + Context + Tools + Environment + Feedback loop
LLM reasons, decides Instructionsgoal · rules Contextfiles · history Toolsread · edit · run Environmentshell · repo · tests Feedback loopresults return to context the model never touches the machine directly
PartRoleIn Claude Code (from its docs)
LLMReads the context and chooses the next action.Claude models; you can switch with the model command or a start-up flag.
InstructionsStanding rules and the task.Your prompt plus CLAUDE.md files loaded each session; an AGENTS.md can be read instead.
ContextEverything the model can see now.Conversation, file contents, command output, memory and instructions, with automatic compaction near the limit.
ToolsThe actions the model may request.Five categories: file operations, search, execution, web, and code intelligence (the last needs plugins).
Execution environmentWhere the actions really run.Local machine by default; also cloud VMs, or your machine driven from a browser.
Feedback loopReturns each result to the model so it can adjust.Each tool result informs the next step; you can interrupt at any point.

The instructions part connects to Chapter 1: the model does not retain project knowledge between sessions, so standing rules must be re-supplied as text every time. Claude Code documents that each new session starts with a fresh context window and that CLAUDE.md and auto memory carry knowledge across sessions (Source 2).

03
Chapter Three · The Loop

The Agentic Loop

Claude Code's documentation describes three phases that blend together: gather context, take action, and verify results, repeated until the task is complete. A question about a codebase may need only the first phase; a bug fix cycles through all three several times (Source 2).

The agentic loop, with you as an interrupt
Your prompt Gather contextsearch, read files Take actionedit, run commands Verifyruns the tests not done? go round again with what was learned Done → you review Esc = interrupt

A concrete case from the same documentation: when told to "fix the failing tests", an agent might run the test suite, read the error output, search for the relevant source, read those files, edit them, and run the tests again. Each tool use returns new information that informs the next decision.

04
Chapter Four · Worked Contrast

Asking for a REST API: Model vs. Agent

Suppose you want a GET /books/{id} endpoint in an existing Spring Boot project. The same request produces very different work depending on whether the model can act. The right-hand column describes what an agent is built to do; it is a description of the pattern, not output from a particular run.

LLM only (chat)
You: "Write a GET /books/{id} endpoint in Spring Boot." Model: returns a generic controller - guesses package names - guesses the service and DTO - cannot compile it - cannot run your tests You: paste it in, fix imports, run the build, paste errors back
Coding agent
You: "Add GET /books/{id}. Follow the existing controllers. Tests must pass." Agent: 1. lists the project, reads pom.xml 2. reads an existing controller 3. creates controller + test 4. runs the build and tests 5. reads failures, edits, re-runs 6. reports what changed
The difference is not smarter text. It is that the agent can look at your project (so its guesses become observations) and can run the build (so errors become input rather than your homework). Whether the final code is right is still yours to decide.
05
Chapter Five · Run It Yourself

A Toy Agent Loop, Executed

What this demo is — and is not. The decision step below is a few hand-written if rules standing in for the model. It is not an LLM and it does not reason. What is real is everything else: the file reads and edits happen on disk, and the tests are compiled and run by the JDK. Its purpose is to make the loop's shape visible: observe, choose a tool, act, feed the result back, repeat.
Setup: a project with a deliberate bug
work/Calculator.java
public class Calculator { public static int add(int a, int b) { return a - b; // bug: should be a + b } }
work/CalculatorTest.java
public class CalculatorTest { public static void main(String[] args) { int actual = Calculator.add(2, 3); if (actual != 5) { System.out.println("FAIL add(2,3): expected 5 but was " + actual); System.exit(1); } System.out.println("PASS add(2,3) = 5"); } }
MiniAgent.java — the loop (expand to read the source)
Java 21 · single-file program · run from the folder that contains work/
import java.nio.file.*; import java.util.*; /** A toy agent loop. The "model" is a hand-written rule, NOT an LLM; the tools are real. */ public class MiniAgent { static final Path DIR = Path.of("work"); // ---- tools (real file system and real JDK) ---- static String readFile(String name) throws Exception { return Files.readString(DIR.resolve(name)); } static void editFile(String name, String from, String to) throws Exception { Path p = DIR.resolve(name); Files.writeString(p, Files.readString(p).replace(from, to)); } static String runTests() throws Exception { Process p = new ProcessBuilder("sh", "-c", "javac -d out Calculator.java CalculatorTest.java && java -cp out CalculatorTest") .directory(DIR.toFile()).redirectErrorStream(true).start(); String out = new String(p.getInputStream().readAllBytes()).trim(); return (p.waitFor() == 0 ? "[exit 0] " : "[exit 1] ") + out; } // ---- the stand-in for the model: looks at the history and picks the next action ---- static String[] decide(List<String> history) { String last = history.isEmpty() ? "" : history.get(history.size() - 1); if (history.isEmpty()) return new String[]{"run_tests"}; if (last.startsWith("[exit 0]")) return new String[]{"done"}; if (last.startsWith("[exit 1]") && history.stream().noneMatch(h -> h.contains("return a - b"))) return new String[]{"read_file", "Calculator.java"}; if (last.contains("return a - b")) return new String[]{"edit_file", "Calculator.java", "a - b", "a + b"}; return new String[]{"run_tests"}; } public static void main(String[] args) throws Exception { List<String> history = new ArrayList<>(); for (int step = 1; step <= 6; step++) { String[] action = decide(history); System.out.println("step " + step + " -> " + String.join(" ", action)); if (action[0].equals("done")) { System.out.println("goal reached: tests pass"); return; } String result = switch (action[0]) { case "run_tests" -> runTests(); case "read_file" -> readFile(action[1]); case "edit_file" -> { editFile(action[1], action[2], action[3]); yield "edited " + action[1]; } default -> "unknown tool"; }; System.out.println(" observation: " + result.replace("\n", "\n ")); history.add(result); } System.out.println("stopped: step limit reached"); } }
Prerequisites: JDK 21 on the PATH. Save the three files, then run from the folder that contains work/.
$ java MiniAgent.java
Actual output · executed 2026-10-30 · OpenJDK 21.0.2 (Temurin), Linux
step 1 -> run_tests observation: [exit 1] FAIL add(2,3): expected 5 but was -1 step 2 -> read_file Calculator.java observation: public class Calculator { public static int add(int a, int b) { return a - b; } } step 3 -> edit_file Calculator.java a - b a + b observation: edited Calculator.java step 4 -> run_tests observation: [exit 0] PASS add(2,3) = 5 step 5 -> done goal reached: tests pass
Reading the trace
StepLoop phaseWhat happened
1Verify (first look)Ran the tests; the failure is a real compiler-plus-runtime result, not a guess.
2Gather contextRead the source file named by the failure.
3Take actionEdited the file on disk.
4VerifyRe-ran the tests; the evidence changed from FAIL to PASS.
5StopThe stopping rule is "tests pass".

The lesson for real agents: they replace the hand-written rules with a language model and the three tools with many more, but the skeleton is identical. Notice also that the agent was only as good as its check. A passing test proved add(2,3) — not that addition is correct for all inputs. Agents declare success on the evidence you give them.

Environment record: Claude Code 2.1.314 (output of claude --version on this machine), OpenJDK 21.0.2 (Temurin). No Claude session was run for this page: nothing here depends on an authenticated Claude account.
06
Chapter Six · Several Agents

Agentic Workflows and Multi-Agent Systems

One agent has one context window. When a task would flood that window — reading dozens of files, running a long search — the answer is to hand part of it to another agent with its own window. Claude Code's subagents work this way: each runs in its own context with its own system prompt and tool access, and only a summary returns to the main conversation (Source 3).

Why delegate: separate windows, summaries come back
Main agentyour conversation Subagent Aown context · many files Subagent Bown context · runs tests task task summary only

Subagents and dynamic workflows are documented features; agent teams are disabled by default and gated behind an experimental flag (Source 4). Token use grows with the number of agents, because each keeps its own context — the cost page notes agent teams use many times more tokens than a standard session. Chapters 10–11 cover when this pays off.

07
Chapter Seven · Trade-offs

Costs, Risks and When Not to Use an Agent

Anthropic's guidance on building agents is direct: agents suit open-ended problems where the number of steps cannot be predicted in advance; they work best in trusted environments; they cost more; and their errors can compound. It advises starting with the simplest solution possible and adding complexity only when it measurably improves results (Source 1).

SituationBetter fitWhy
Explain one error message you pastedPlain chatNo project access or tools are needed.
Rename a method across twenty filesIDE refactoring or an agentMechanical, checkable by the compiler.
Fix a failing integration test in an unfamiliar moduleAgentNeeds searching, reading, running and iterating.
Change production database dataHuman, with reviewIrreversible; an agent's wrong assumption costs more than the saved time.
Autonomy needs boundaries. An agent that can run shell commands can also run the wrong ones. Claude Code ships permission modes, checkpoints for file edits (which do not cover remote systems such as databases or deployments), and sandboxing options precisely because of this (Source 5). Chapter 13 covers them in depth.
08
Chapter Eight · Summary

Key Takeaways, Exercises and Sources

∑ Coding agents — what to remember
  • An agent is an LLM plus tools in a loop. The model decides; the harness executes and feeds results back.
  • Six parts: LLM, instructions, context, tools, execution environment, feedback loop.
  • The loop is gather, act, verify. Verification is what separates guessing from engineering.
  • An agent trusts its checks. A weak test gives a confident wrong "done".
  • More agents mean separate contexts and higher cost; use them when isolation pays for itself.
  • Start simple. Reach for autonomy when the task needs open-ended exploration.
Exercises

Exercise 1 Beginner

Run MiniAgent.java as shown. Then reset Calculator.java to the buggy version and run it again. Which log line tells you the agent knew the fix worked?

Learning outcome: identify the verify step in a loop.

Exercise 2 Intermediate

Add a second failing case (for example add(-1, 1) should be 0) and a rule so the loop handles a second failure. Then change the test so it checks only add(0, 0) and observe the agent declaring success on the buggy code.

Learning outcome: see that an agent's confidence is only as good as its checks.

Exercise 3 Advanced

Pick a real task from your work and decompose it into the six parts: what instructions, which context, which tools, which environment, what feedback signal would an agent need? Identify the one part most likely to fail and how you would detect that.

Learning outcome: design an agent task around its failure modes instead of its happy path.

Sources (read on 2026-10-30; paraphrased)
  1. Anthropic, Building effective agents — workflows vs agents; when to use agents; costs and compounding errors.
  2. Anthropic, How Claude Code works — agentic loop, harness, tool categories, environments, sessions and context.
  3. Anthropic, Subagents — separate context windows, summaries returned.
  4. Anthropic, Manage costs and Extend Claude Code — agent teams default and token cost; dynamic workflows.
  5. Anthropic, Security and Permission modes — permissions, sandboxing, checkpoint scope.

Demo run: OpenJDK 21.0.2 (Temurin), Linux, 2026-10-30; claude --version reported 2.1.314. The six-term vocabulary ladder and the REST-API contrast are explanatory framing written for this guide, not taken from a single source.