What is an AI coding agent? How it works, with an example
Updated
An AI coding agent is a program that uses a language model to do a software task for you, not just suggest code. You give it a task such as “fix the failing login test”. It reads your files, runs commands, edits code, runs the tests again, and keeps going until the task is done or it needs you. Claude Code, Codex, OpenCode, Cursor’s agent and GitHub Copilot’s agents are all coding agents.
The difference from a chatbot is the loop. A chatbot answers once and you copy the code. An agent acts in your project and checks its own work.
The difference from a workflow tool is who draws the path. A procedural engine such as n8n follows steps a person laid out in advance; an agent picks its next step at runtime from what the last one returned. When to Use OpenAI + Tools vs a Workflow Runtime draws the practical line as assisting versus acting: “If it’s assisting, use tools. If it’s acting, use orchestration.” A model that answers a question with one or two tool calls is assisting. One that edits, runs and retries across many steps is acting, and needs what orchestration adds: state across steps, retries, approvals and a record of what ran.
What it looks like in practice#
You type: “The session test fails since yesterday. Find out why and fix it.”
The agent then works through steps like these, showing each one as it goes:
read_file src/auth/session.ts
search "refreshToken" in src/
run npm test -- session 1 failing
edit_file src/auth/session.ts 2 lines changed
run npm test -- session all passing
answer "Expiry compared seconds to milliseconds. Fixed in session.ts."
You didn’t open a file. You read a two-line diff and decide whether to keep it.
How does an AI coding agent work?#
Every agent, whatever the product, runs the same loop:
- You describe the task.
- The model gets your task, its instructions and a list of tools it may use.
- The model answers with either text or a tool call, such as “read
src/auth.ts”. - The agent program runs the tool and sends the result back to the model.
- Steps 3 and 4 repeat until the model answers with text instead of a tool call.
The model never touches your disk. It only asks for actions. The agent program on your computer decides whether to carry them out, which is where permission prompts and rules live.
What does the agent actually send to the model?#
Tools are just descriptions. The agent program tells the model which tools exist, in a format like this one from Anthropic’s API:
{
"name": "read_file",
"description": "Read a file from the project.",
"input_schema": {
"type": "object",
"properties": { "path": { "type": "string" } },
"required": ["path"]
}
}
When the model wants to use one, it doesn’t run anything. It answers with a request, and stops:
{
"type": "tool_use",
"id": "toolu_01A09q90qw90lq917835lq9",
"name": "read_file",
"input": { "path": "src/auth/session.ts" }
}
The agent program reads the file, sends the contents back as a tool_result with the same id, and asks the model again. That’s one turn of the loop. Two things follow from it:
- Tool descriptions cost tokens on every turn. In the basic loop, every description is sent with every request, so twenty tools with long descriptions are paid for before your task even starts. Some agents, Claude Code among them, now send only the names of MCP tools and load a tool’s full definition when it is needed.
- The model only ever sees text. Anything a tool returns, a file, a web page, an error, becomes part of what the model reads next. That’s why a malicious line in a README can steer an agent.
OpenAI, Google and others use their own field names, but the shape is the same.
A variation, seen in a real run: instead of one tool call per turn, the model can write a program that calls the tools, and the agent runs the program. An experiment in Contenox Runtime gave a model a JavaScript sandbox with two functions, one to fetch a URL and one to hand a prompt to another model, and asked it to fetch a sample to-do item and summarize it. The generated script carried its own error handling: on the first try the test API sat behind a Cloudflare outage, returned a 500, and the script’s own failure branch turned that into an apology. Retried later in the same chat, it fetched the item, passed it to a second model for the summary, and answered “Task titled ‘delectus aut autem’ is incomplete.” One model turn did the work of several, and the code it wrote is untrusted input, so it only runs inside a sandbox. The trace is in I Let an LLM Write JavaScript Inside My AI Runtime.
What can a coding agent do?#
What its tools allow. Most come with:
- Read and search files.
- Edit and create files, usually by replacing specific lines.
- Run commands: tests, builds, linters, package managers, git.
- Fetch web pages and documentation.
Many can load more tools through MCP, for example to read GitHub issues, query a database or drive a browser.
Agents do best on bug fixes with a way to reproduce them, adding tests, small features, refactors across many files, and explaining unfamiliar code. They do worst on vague goals with no way to check the result.
Is it the same as Copilot autocomplete or ChatGPT?#
Autocomplete, question-and-answer chat and coding agents do different jobs. The product name alone does not tell you which one is active. GitHub Copilot includes completions and agents. In the ChatGPT desktop app, you can choose Codex for an agent session in a local folder. Copilot features · ChatGPT desktop quickstart
| Autocomplete | Chat | Coding agent | |
|---|---|---|---|
| Works on | The next few lines | One question | A whole task |
| Changes your files | Only what you accept | No, you paste | Yes |
| Runs commands | No | No | Yes |
| Checks its work | No | No | Can run tests |
| Your job | Typing | Asking | Reviewing |
Autocomplete is still the fastest way to write code you already know how to write. An agent pays off when the task spans several files, needs investigation, or has a clear test.
Where do coding agents run?#
- In a terminal, as a command in the project folder: Codex CLI, OpenCode, and Claude Code’s terminal version. See terminal coding agents.
- In an editor, as a panel next to the code: Claude Code and Codex both ship IDE extensions. The Agent Client Protocol (ACP) lets one agent work in several editors.
- In a desktop app, review sessions, diffs and approvals in one window. Claude Code, OpenCode and goose each offer a desktop app. OpenCode can also pair its local session with a browser or phone. OpenCode product · Goose desktop setup
- In your browser, served from your own machine. DeepSeek Harness, DeepSeek’s open-source agent, works this way:
npx @deepseek-ai/dsh webstarts it onlocalhost. - In the cloud, on a copy of your repository. Codex cloud, Claude Code on the web and GitHub’s Copilot in the cloud work this way: you hand over a task, and get back a branch or a pull request to review.
A local agent works on your real files with your user’s access. A cloud agent works on a copy, which is safer but slower to steer.
Is an AI coding agent safe to use?#
It is as safe as what you let it do. An agent that can run shell commands can delete files, push to a remote or print a secret, and a web page or issue comment it reads can contain instructions aimed at it. Three habits cover most of the risk:
- Use git and start from a clean working tree, so every change is visible and easy to undo. See Git workflow with AI agents.
- Make risky actions ask first: pushing, deleting, installing, anything touching secrets. See AI agent permissions.
- Keep secrets out of reach. See keep secrets away from AI agents.
Where do agents go wrong?#
They fail in familiar ways, and knowing them makes review faster:
- Plausible but wrong. The code compiles and reads well but solves a slightly different problem.
- Doing too much. Asked to fix one bug, it refactors three files.
- Cheating on tests. A test fails, and the agent loosens or skips the test instead of fixing the code.
- Losing the thread. On long tasks, early instructions get crowded out and the agent drifts.
- Claiming success. “All tests pass” in the summary is a claim. The diff and your own test run are the evidence.
Clear tasks make the first three less likely, short sessions help with the fourth, and only careful review catches all five.
How do I get started?#
You need three things:
- An agent: a terminal tool, an editor with an agent panel, or a desktop app.
- A model: a hosted model through a subscription or API key, or a local model. See how to choose a model for coding, and AI coding costs for what you will pay.
- A project in git, with a clean working tree before each task.
Start with a read-only task: “Explain how sessions are created in this project. Don’t change anything.” Then a small one with a test. Watch what the agent does before you hand it bigger work.
If you want a desktop app that works with the model provider you choose and asks before the actions you gate, Contenox Harness is free and open source.
Related guides#
AI coding: autocomplete, agents and app builders, sortedAI coding: what it is, how it works, and the tools in 2026AI coding explained: the three kinds of tools (autocomplete, agents, app builders), which fits which job, what it costs, where it goes wrong, how to start.
How to review AI-written code: what to check before you keep itHow to review AI-written code: what to check, in orderHow to review AI-written code: read the diff, not the summary, then check scope, tests, invented APIs and error handling. Git commands and a checklist to copy.
AGENTS.md explained: give the agent your project’s rules onceWhat is AGENTS.md? What to put in it, with an exampleWhat is AGENTS.md? A Markdown file that tells coding agents how to build and test your repo. A short example, what to include, and how Claude Code and Codex read it.
What is MCP?: how agents get extra toolsWhat is MCP? The Model Context Protocol, explained simplyWhat is MCP? The Model Context Protocol in plain words: what it does, how it differs from an API, how to add a server to your coding agent, and when to skip it.
What is an AI coding harness?: the program that runs the loop, and why it matters as much as the modelWhat is an AI coding harness? Harness vs agent vs modelWhat is an AI coding harness? The program around the model: loop, tools, context, permissions. How it differs from the model, and why it changes the results.
AI agent permissions: what to allow, ask and blockAI agent permissions for coding agents: a safe starting rule set, real config for Claude Code and Codex, the gaps in command rules, and when to skip prompts.
GlossaryAI coding glossary: agents, MCP, RAG, KV cache and moreAI coding glossary: plain definitions of the terms you meet when building software with AI agents, from ACP and AGENTS.md to prompt caching, RAG and worktrees.
What is an AI harness?What is an AI harness? Agent = model + harness, explainedWhat an AI harness is, what's inside one, an example loop in 20 lines, why the same model scores 14 points apart in two harnesses, and which harnesses exist.