---
title: Working with coding agents
summary: What LLMs, agents, harnesses, skills, and MCP actually are, and how to work with them effectively.
section: start-here
phase: any
order: 2
last_reviewed: 2026-11-20
---

# Working with coding agents

An agent is an LLM in a loop with tools. Once you understand that loop, you understand both its strengths and its failure modes.

## You'll be able to
- Explain the difference between a model, an agent, a harness, a skill, and an MCP server
- Know what an agent can and can't "see" at any moment
- Structure work so an agent succeeds on the first or second try

## The mental model

```
 you ──prompt──▶ ┌──────────── harness ────────────┐
                 │  context window (what it sees)  │
                 │        ▲            │           │
                 │   tool results   tool calls     │
                 │        │            ▼           │
                 │   files · shell · web · MCP     │
                 └─────────────────────────────────┘
```

The model reads its context, decides on an action (edit a file, run a command, search), and the harness executes that action and feeds the result back in. This repeats until the model decides the task is done. **The model knows only what's in its context window**, plus whatever it learned in training, and that training may be out of date.

## Key concepts
- **LLM (model):** The engine that predicts text. Examples: Claude, GPT, Gemini, and open models like Llama or Qwen.
- **Context window:** Everything the model can see right now, including your prompt, files it has read, and tool outputs. It's finite. When it fills up, the harness compacts or drops older material, and the agent can lose track of earlier details.
- **Agent:** A model plus a loop plus tools. It acts, observes the result, and acts again.
- **Harness:** The program that runs the agent loop and provides its tools. Examples: Claude Code, Cursor, GitHub Copilot agent mode, OpenAI Codex, Aider, Cline.
- **Tools:** Actions the agent can take, such as reading or editing files, running shell commands, searching the web, or browsing.
- **MCP (Model Context Protocol):** An open standard for plugging external tools and data into agents (GitHub, databases, Figma, Sentry…). Think of it as USB-C for agent tools.
- **Skills / rules files:** Reusable instructions the agent loads when relevant, such as `CLAUDE.md`, `AGENTS.md`, `.cursor/rules`, or skill folders. This is where your project's conventions live, so you don't repeat them in every prompt.
- **Subagents:** Child agents spawned for a sub-task, each with a fresh context. They're useful for parallel or exploratory work.
- **Hallucination:** Output that sounds confident but is wrong. Invented APIs, package names and config options are the classics.

## Decisions you make (not the agent)
| Decision | Sensible default | Choose otherwise when… |
|---|---|---|
| Task size | One feature or one bug per session | You're scaffolding something brand new |
| Plan first? | Yes, for anything touching >3 files: ask for a plan, review it, then build | It's a one-line fix |
| Project rules file | Always keep one (`AGENTS.md`/`CLAUDE.md`) with stack, commands, conventions | Never skip it |
| Version control | Commit before every agent session, so a bad run is easy to throw away | Never skip it |
| Verification | The agent runs tests, lint and type-check before it says "done" | Prototype you'll throw away |

## What good output looks like
- The agent reads relevant files before editing them
- It runs the build and tests, and reports the results
- It asks you about ambiguity instead of guessing on important choices
- Its diffs are small and focused, and match the existing code style

## Red flags
- **Invented packages or APIs** → check that the package actually exists on npm or PyPI before installing it. Malicious packages are sometimes published under names models tend to hallucinate ("slopsquatting").
- **"Done!" without having run anything** → ask it to run the tests and show you the output.
- **A sprawling diff for a small ask** → reject it and re-prompt with a narrower scope.
- **Disabling tests or type checks to get green** → reject it immediately.
- **Hardcoded secrets** → see [Environments & secrets](/docs/shipping/environments-and-secrets.md).
- **Editing a file it never read** → ask which files it read first. Edits made from guesses tend to duplicate or contradict code that already exists.
- **A new helper that duplicates an existing one** → search the repo for similar names before accepting new utility files.
- **Old-version patterns** (the wrong major version of a framework or library) → the model's training may be out of date. Name the versions in your rules file and check the diff against the docs for the version you use.

## Worked example

**Task:** Add a "cancel booking" feature to an app you did not write.

You prompt: *"Add a cancel booking button and endpoint."* The agent immediately starts writing, creates `lib/booking-utils.ts` with a new `cancelBooking` helper, adds an endpoint and a button, and says it is done.

**What a good result contains:** the agent first reads how bookings are already handled, proposes a plan naming the files it will change, reuses what exists, and ends by running the tests and showing the output.

**The wrong turn:** the repository already had `lib/bookings.ts` with a cancellation helper that also sends a confirmation email. The agent never looked, so the new helper cancels without sending the email, and now two helpers do almost the same thing.

**How review catches it:** ask *which existing files did you read before writing this?* The answer is none. Then look at the file list: a brand-new utility file in a repo that already has a `bookings` module is a red flag. Re-run the task with the orient-then-plan prompt below, and have it show its plan before it writes any code.

## Sample prompts

### Set up a project rules file
```text
Read this repository and create an AGENTS.md at the root. Include:
- Stack and versions (from package.json / lockfiles)
- How to install, run dev, run tests, lint, type-check, build
- Folder structure and what lives where
- Coding conventions you can infer (naming, file layout, state management, styling)
- Things an agent should never do in this repo (e.g. edit generated files, commit .env)
Keep it under 150 lines. Don't invent anything you can't verify from the code.
```

### Plan-then-build
```text
I want to add <feature>. Before writing any code:
1. Read the relevant parts of the codebase.
2. Propose a plan: files to change, new files, data model changes, risks.
3. List any decisions you need from me.
Stop and wait for my approval before implementing.
```
*Why it works:* It separates thinking from doing, so you catch a wrong approach before it turns into 400 lines of code.

### Orient, then plan
```text
I want to add <feature>. Don't write code yet.
1. Search the repo for how <related area> is already handled and list the files and helpers you found, with a one-line summary of each.
2. Say which of them you will reuse and which you will change.
3. Propose a plan: files to change, new files (and why none of the existing ones fit), risks.
Wait for my approval.
```
*Why it works:* It forces the search that prevents duplicated code, and "why none of the existing ones fit" makes new files a justified exception.

### Review before I commit
```text
Review the uncommitted changes (git diff) as a skeptical reviewer. List every file changed and whether it relates to the task: <task>. Flag unrelated changes, new dependencies, deleted or weakened tests, and anything that looks hardcoded. Don't change any code.
```
*Why it works:* It catches scope creep and the "make the tests green" shortcuts that agents sometimes take. See [Reviewing and verifying AI output](/docs/ai-agents/reviewing-ai-output.md) for more.

### Explain your last change
```text
Explain the change you just made as if to a teammate reviewing it: what problem it solves, why you chose this approach over the alternatives, what you assumed, and what you did not verify. If any part is a guess, say so.
```
*Why it works:* Explaining forces the agent to surface assumptions. Check the explanation against the diff rather than taking it as proof.

### Fix a failing test the right way
```text
The test <test name> is failing. Find the root cause in the code under test, not in the test. Don't change the test's expectations or skip it unless you can show the expectation is wrong, and explain why. Show the failing output before and the passing output after.
```
*Why it works:* It rules out the shortcut of editing the test to match the bug.

## Check your understanding

```quiz
Q: What can the model use when it generates an answer?
- [ ] Your whole repository, automatically
- [x] Only what is in its context window, plus what it learned in training
- [ ] Everything you have ever told it
> Why: The harness decides what goes into the context window. Anything the agent hasn't read isn't available to it, and what it learned in training may be out of date.

---

Q: Why commit before starting an agent session?
- [ ] The agent can't run without a clean commit
- [x] A bad run becomes easy to throw away
- [ ] It makes the agent faster
> Why: Version control is your undo button. With a clean starting point you can discard a messy session with one command.

---

Q: The agent says "Done!" What should you do next?
- [ ] Merge it
- [x] Ask it to run the tests, lint and type check, and show you the output, then read the diff
- [ ] Ask it to say it is sure
> Why: Confidence isn't evidence. Output from commands you can check is.
```

## Checklist
- [ ] A rules file exists and is up to date
- [ ] Work is committed before the session starts
- [ ] Task is scoped to one feature or fix
- [ ] Agent verified its own work (tests, types, build)
- [ ] You read the diff

## Go deeper
- [Model Context Protocol](https://modelcontextprotocol.io)
- [AGENTS.md](https://agents.md)
- [Claude Code docs](https://docs.claude.com/en/docs/claude-code/overview)
- Go further in the AI & Agents section: [How LLMs work](/docs/ai-agents/how-llms-work.md), [Context engineering](/docs/ai-agents/context-engineering.md), [Agents, tools and MCP](/docs/ai-agents/agents-tools-and-mcp.md), [Reviewing and verifying AI output](/docs/ai-agents/reviewing-ai-output.md) and [Security of agentic workflows](/docs/ai-agents/agent-security.md)
