Catalog My learning Blog
AI-Assisted Coding Course: Agentic Development in 30 Days · Phase 1 · Lesson 2 · 5 min read

How AI Coding Agents Work: Tools, Loop and Permissions

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: Reading an Agent's Trajectory
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Understand what happens inside a coding agent such as Claude Code, Cursor's agent or Codex: the loop of reading, searching, editing and running commands, the tools it uses, how permissions gate those tools, and why agents are strongest on tasks with fast, objective feedback.

Concept Explanation

A coding agent is a language model running in a loop with tools. You give it a task. The model decides on an action, such as reading a file, searching the codebase, editing a file or running a shell command. The harness, the program around the model, executes that action and returns the result. The model reads the result and decides the next action. It repeats until it believes the task is done or it needs your input. Everything an agent knows about your project comes from what it reads during that loop and from the instructions you provide.

The tools are ordinary developer actions. Read opens a file. Grep and Glob search by content and file name, which is how agents find their way around large codebases without reading everything. Edit replaces a specific piece of text in a file, and Write creates or overwrites a file. Bash runs a command: the test suite, a build, git, a linter. Many agents also fetch web pages, spawn subagents for side tasks and call tools from MCP servers. The quality of an agent depends heavily on how well its harness implements these tools, which is why the same model can behave differently in different products.

Permissions sit between the model and the tools. A careful setup lets the agent read freely but asks you before it edits files or runs commands, at least until you have expressed trust. Most tools offer modes ranging from asking about everything, to auto-accepting edits, to classifier-assisted modes that approve routine actions and stop on risky ones, to fully unattended modes meant only for isolated sandboxes. You will configure these properly on Day 20.

The most important property of agent work is feedback. An agent that can run the tests after each change knows whether it succeeded; one that cannot is guessing. Type checkers, linters, test suites, build commands and even screenshots of a running app give the model objective signals it can act on. That is why agents excel at fixing a failing test, migrating code under a compiler's guidance or implementing a function to a clear specification, and struggle with vague goals such as "make the UI nicer", where nothing tells them whether they are getting closer.

Finally, agents have no memory between sessions except what is written down. A new session starts from scratch, reads your project instruction file, and explores again. Day 3 explains how context limits shape agent behavior, and Days 6 and 7 cover how to give agents the context they need without filling their window with noise.

ToolWhat it doesTypical use in a task
Glob and GrepFind files by name and contentLocate where a function is defined and used
ReadRead a file or part of oneUnderstand the code before changing it
Edit and WriteChange or create filesImplement the fix or feature
BashRun commandsTests, type checks, builds, git
Web fetch and searchRead documentationCheck an API the model is unsure about
Subagents and MCP toolsDelegate or reach external systemsParallel research, issue trackers, databases

Worked Example: Reading an Agent's Trajectory

This is a condensed, typical trajectory of a coding agent fixing a failing test. Learning to read trajectories like this, in your tool's transcript view, is how you understand and debug agent behavior.

Code
User: The test test_invoice_total_rounding is failing. Fix it.

1. Bash    pytest tests/test_invoice.py::test_invoice_total_rounding -q
           -> FAILED  assert 10.0 == 9.99  (expected 9.99, got 10.0)
2. Grep    "def invoice_total"            -> src/billing/invoice.py:41
3. Read    src/billing/invoice.py (lines 30-70)
           -> total = round(sum(line.amount for line in lines), 2) after converting to float
4. Grep    "Decimal"                       -> src/billing/money.py uses Decimal and quantize
5. Read    src/billing/money.py
6. Edit    src/billing/invoice.py: sum Decimals, quantize with ROUND_HALF_EVEN via money.to_cents
7. Bash    pytest tests/test_invoice.py -q          -> 14 passed
8. Bash    pytest -q                                -> 412 passed
9. Answer  "invoice_total converted amounts to float before rounding, which produced 10.0.
           It now uses the existing money.to_cents helper with Decimal. All 412 tests pass."

Notice the shape: reproduce the failure, locate the code, read before editing, look for existing conventions, make a focused change, verify locally, then verify globally. When an agent skips the reproduction or the final full test run, its confident summary deserves less trust.

The model picks an action, the harness checks permissions and runs the tool, and the result goes back into the context. The loop repeats until the task is done, and tests and type checks tell the agent whether it succeeded.
The model picks an action, the harness checks permissions and runs the tool, and the result goes back into the context. The loop repeats until the task is done, and tests and type checks tell the agent whether it succeeded.

Real-World Examples

  • Anthropic's documentation describes Claude Code's built-in tools, including Read, Edit, Write, Bash, Grep and Glob, and notes that the agent works best when it can verify its own work, for example by running tests or comparing screenshots.
  • Research such as SWE-agent (Princeton, 2024) showed that the design of the interface between the model and the repository, including how files are viewed and how search results are summarized, has a large effect on how often a model fixes real GitHub issues.
Key TakeawaysA coding agent is a model in a loop with developer tools: search, read, edit and run commands, gated by permissions you control. It knows only what it reads and what you tell it, and it does its best work when fast, objective feedback such as tests and type checks tells it whether it succeeded. Read trajectories to understand and trust its work.

Review Questions & Answers

The program around the model that executes its chosen actions, such as reading files or running commands, returns results to the model, enforces permissions and manages the context. Different harnesses with the same model can behave differently.

A failing test gives fast, objective feedback: the agent can run it after each change and know whether it succeeded. A vague goal provides no signal about whether the agent is getting closer.

Reading everything would fill the context window and waste time. Searching by name and content lets the agent find the relevant code quickly and read only what it needs.

Reproducing the failure first, reading existing conventions and reusing the money helper, rerunning the specific test, and finally running the full suite with all tests passing.