AI-native engineering · L1Working with coding agents

Working with coding agents

Explore, plan, build and verify, and treat the agent's context like a budget you can run out of.

L1 Must-knowAI-native engineering19 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 21 Oct 2026 · How we check content
AI tools change fast: we review this lesson every quarter (next by 19 Jan 2027).
Senior at work · lesson 10 of 26
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

This story is made up, but it may have happened to you. Arjun has a flaky checkout test. His agent session is already long: a CSS fix, a question about logs, a big stack trace.

He types: "fix the flaky checkout test". The agent reads forty files. It finds a timing problem and adds a two-second sleep to the test. On the way, it "cleans up" a helper in the payment code. It reports: "Fixed. The test should pass now."

Arjun did not ask it to run the test 50 times. He did not read the diff closely. The next day, a reviewer finds the changed payment helper. The test is still flaky. It just fails less often.

He tries again: /clear, plan mode, and the exact command that shows the failure. The agent finds a missing await, writes a plan, fixes it, and runs the test 50 times. All pass. The diff is four lines.

The agent was the same both times. Only the way he worked with it changed.

Section 2 of 8

The idea in simple words

A coding agent is not a smarter autocomplete. It works in a loop. Claude Code describes three phases: gather context, take action, and verify results. 2 It searches and reads files, edits code, runs commands, reads the output, and decides the next step. It repeats this until it thinks the job is done.

Two facts shape everything about working with it.

First, context is a budget. The context window holds your whole conversation: every message, every file the agent reads, and every command output. 1 It fills up fast. As it fills, the model can forget earlier instructions and make more mistakes. 1 This is not only a Claude problem. An Anthropic engineering post calls context "a finite resource with diminishing marginal returns". 5

Second, the agent stops when the work looks done. Without a check it can run, "looks done" is its only signal. Then you become the checker for every mistake. 1

The key idea. Spend context on what matters, and give the agent a way to prove its work. Most good habits with agents come from these two rules.

Section 3 of 8

How it works

Step through one task and watch the context fill up. Use Next and Back, or the ← and → keys.

One task with a coding agent, and the context window filling upContext limited 1 · Exploreplan mode · read filesfiles 2 · Planyou read and edit itplan 3 · Codeedit filesedits 4 · Run tests2 tests failtest log 5 · Fix, run againall tests passfixes 6 · Reviewfresh subagent + you✓ /clear before next task SeniorPath
  1. Explore. In plan mode the agent reads files but changes nothing. Every file it reads uses context, so point it at the right folders instead of the whole repo.
  2. Plan. The agent writes a plan: which files change, and why. You read it and fix it now. A wrong idea is cheapest to catch here.
  3. Code. The agent leaves plan mode and edits the files. Every edit and every file it reads adds to the context.
  4. Run tests. Two tests fail. That is good news: the agent got a clear signal instead of guessing that it was done. The test output also uses context.
  5. Fix and run again. The agent loops between fixing and testing until all tests pass. The context is now mostly full, and early details may start to get lost.
  6. Review. A subagent reviews the diff in its own, fresh context, so your main context does not grow. Then you read it too. Before the next task, run /clear.
Step 1 of 6

Explore, plan, implement, commit

The Claude Code guide recommends four phases. 1

  1. Explore. Press Shift+Tab until plan mode is on. In plan mode the agent reads files and answers questions, but does not change them.
  2. Plan. Ask for a plan: which files change, and why. Press Ctrl+G to open the plan in your editor and change it. This is the cheapest moment to catch a wrong idea.
  3. Implement. Approve the plan or leave plan mode, and let it code against the plan. Ask it to write tests and run them.
  4. Commit. Ask for a clear commit message and a pull request.

Plan mode has a cost, so skip it for small work. The guide's test: if you could describe the diff in one sentence, skip the plan. 1

Give it a check it can run

A check is anything with a clear pass or fail: a test suite, a build, a linter, a script, a screenshot to compare. 1 Put the check in the prompt. Then ask for evidence, not claims: the command it ran and the output. 1

Manage the budget

  • Run /clear between unrelated tasks. 1
  • Run /context to see what uses space. 2
  • When the context gets full, Claude Code compacts it: it clears old tool output and then summarizes. Early instructions may be lost. 2 You can run /compact with a focus, like /compact focus on the API changes. 2
  • Correct early. Esc stops the agent. Esc twice, or /rewind, goes back to an earlier point. 1
  • If you have corrected it twice on the same issue, run /clear and write a better first prompt. 1

Project memory: CLAUDE.md

Each session starts with a fresh context. 2 CLAUDE.md is a file the agent reads at the start of every session. 1 Put in it what the agent cannot guess from the code: build and test commands, unusual style rules, branch rules and known traps. Leave out what it can read from the code. /init creates a first version for you. 1

Keep it short. The docs suggest under 200 lines. 3 For each line, ask: "Would removing this cause mistakes?" If not, cut it. A long file makes the agent ignore your real rules. 1 Remember that CLAUDE.md is context, not enforced configuration. 4 Check it into git, so your team improves it together like code. 1

Four extensions, one paragraph each

Subagents run in their own context window with their own allowed tools, and send back a short summary. 1 Use them for research that reads many files, or for a review in a fresh context. The reviewer sees only the diff and your criteria, not the reasoning that produced it. 1

Skills are Markdown files (SKILL.md) with knowledge or a repeatable workflow, each in its own folder under .claude/skills/. The agent sees only their descriptions at the start. The full text loads when a skill is used, or when you run it with /skill-name. 3

Hooks are scripts that run at fixed points, for example after every file edit. CLAUDE.md instructions are advice. Hooks are deterministic and always run. 1 Use a hook to run the linter after each edit, or to block writes to a folder. If a rule must hold every time, make it a hook. 3

MCP (Model Context Protocol) is an open standard that connects AI tools to outside systems, such as files, databases and other tools. 6 An MCP server can read your data and take actions for you. 6 So treat it like any other dependency: install only servers you trust, and give them the least access you can.

Plugins package skills, hooks, subagents and MCP servers so a team can share one setup. 3

When not to use an agent

  • The change is faster to type than to explain.
  • You are learning something new. Doing it yourself first builds the skill. See "With AI" below.
  • The action touches live systems. Checkpoints undo edits made with the agent's file-edit tools. They do not undo shell commands. Use git as well. 1 They also cannot undo changes to remote systems, such as databases, APIs or deployments. 2 Run those live steps yourself, on purpose.
  • You cannot check the result. The guide says it plainly: if you can't verify it, don't ship it. 1

What the evidence says

The evidence is mixed, so read it carefully. In a 2025 randomized study by METR, 16 experienced developers did real tasks in large open-source projects they knew well. With early-2025 AI tools, tasks took about 19% longer. Yet the developers believed AI had made them about 20% faster. 7 METR now says these results are out of date. 7 Its 2026 update says developers are probably faster with newer tools, but the data is too weak to say by how much. 8

Google's DORA 2025 report found that AI acts as "an amplifier". It makes a team's existing strengths and weaknesses bigger. 9 This is survey data, so it shows what people report, not a measured cause.

The lesson: do not trust how fast it feels. Measure it.

Section 4 of 8

Trade-offs

Way of workingQualityCostUse it when
Write it yourselfYes You understand every line.Slower for large or boring changes.Small fixes, new topics you are learning, risky code.
One vague prompt, no checkNo It may solve the wrong problem.Feels fast. Review and rework come later.Quick experiments you will throw away.
Explore → plan → implement → commitYes , if the check is good.A few minutes of planning and setup.Most real tasks across several files.
Add subagents for research and reviewYes Your main context stays clean.More tokens in total, and more output to read.Large codebases, or work you want checked with fresh eyes.

Simple rule: the less you watch the agent, the stronger its checks must be.

Section 5 of 8

At work: how a senior uses this

  • Before you prompt, ask yourself: "How will the agent know it is done?" Write that check into the prompt.
  • Start every new task with /clear. One session, one task.
  • Use plan mode for anything that touches more than one or two files. Read the plan as you would read a design doc.
  • Keep CLAUDE.md short and in git. When the agent makes the same mistake twice, add one line. When a line stops mattering, delete it. 3
  • Turn "must always" rules into hooks, and leave advice in CLAUDE.md. 3
  • Review agent code like code from a new teammate: read every line, run the tests yourself, and check for changes outside the task.
  • Ask for a fresh-context review before you open the pull request. The bundled /code-review skill reviews your diff in a fresh subagent. 1
Section 6 of 8

With AI

This whole lesson is about AI, so this section covers one risk: using an agent in a way that stops you from learning.

Anthropic ran a randomized study with 52 mostly junior engineers. They learned a new Python library, with or without AI help. On a quiz afterwards, the AI group scored 50% and the group without AI scored 67%. The biggest gap was on debugging questions. The AI group was only about two minutes faster, and that difference was not statistically significant. 10

How people used AI mattered. Those who asked conceptual questions, or asked for explanations of the code, scored 65% or more. Those who handed over the work, or let AI do the debugging, scored under 40%. 10 The authors say the sample was small, the quiz came right after the task, and their pattern analysis does not prove cause. 10

So when the goal is to learn, use the agent as a teacher, not as a typist.

What to ask the agent

"Don't write the code. Explain how this library handles errors, then give me a small exercise to try myself."

"Here is my solution. Before you show yours, list the bugs and edge cases I missed, and explain why each one matters."

"Explain this diff line by line. Then ask me three questions to check that I understood it."

What to check yourself

  • You can explain every line the agent wrote, without asking it again.
  • You could debug this code alone at 2 a.m. during an incident.
  • The tests check real behaviour, and the agent did not weaken a test to make it pass.
  • The diff contains only what the task needed. No quiet changes elsewhere.
Section 7 of 8

Check yourself

1. Your session has run for two hours across three different tasks. The agent starts to ignore rules you gave it at the start. What is the most likely cause?

Show answer

The context window is full of old, unrelated work, so early instructions get lost. Everything in the session uses context. As it fills, the agent can forget early instructions and make more mistakes. Use /clear between tasks.

2. You have corrected the agent twice on the same problem, and it is still wrong. What should you do?

Show answer

Run /clear and start again with a better first prompt that includes what you learned. Failed attempts fill the context and mislead the agent. A clean session with a better prompt usually wins.

3. The agent must never edit the .env file, with no exceptions. Where do you put this rule?

Show answer

In a hook that blocks the edit. CLAUDE.md and prompts are advice the model reads. A hook is code that runs every time, so it enforces the rule.

4. You want to rename one variable in one file. Should you use plan mode first?

Show answer

No. If you can describe the change in one sentence, skip the plan. Planning helps when the approach is unclear or many files change. For a tiny, clear change it only adds time.

5. In Anthropic's 2026 study, people learned a new library with or without AI help. Which group scored better on the quiz afterwards?

Show answer

The group without AI. Among AI users, those who asked questions to understand did better than those who handed over the work. The AI group scored 50% against 67%. AI users who asked conceptual questions scored much higher than those who only delegated.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 10 sources and related lessons
  1. Anthropic, “Best practices for Claude Code”, Claude Code documentation (this page replaced the engineering blog post “Claude Code best practices”) (opens in a new tab)
    The main guide. Context limits, verification, explore-plan-code, CLAUDE.md, subagents, hooks and common failure patterns.
  2. Anthropic, “How Claude Code works”, Claude Code documentation (opens in a new tab)
    The agent loop, the tools, what fills the context window, and what checkpoints can and cannot undo.
  3. Anthropic, “Extend Claude Code”, Claude Code documentation (opens in a new tab)
    When to use CLAUDE.md, skills, subagents, hooks, MCP and plugins, and what each one costs in context.
  4. Anthropic, “How Claude remembers your project”, Claude Code documentation (opens in a new tab)
    Where CLAUDE.md files live, how they load, and why they are context, not enforced rules.
  5. Anthropic, “Effective context engineering for AI agents” (September 2025) (opens in a new tab)
    Why context is a limited resource for any model, and the idea of "context rot".
  6. Model Context Protocol, “What is the Model Context Protocol (MCP)?” (opens in a new tab)
    The open standard that connects AI tools to outside systems. Read the security page too.
  7. METR, “Measuring the Impact of Early-2025 AI on Experienced Open-Source Developer Productivity” (July 2025) (opens in a new tab)
    A randomized controlled trial with 16 experienced developers. METR now marks these results as out of date.
  8. METR, follow-up results on AI and developer speed (February 2026) (opens in a new tab)
    Newer data. The results are not conclusive, and the page explains why.
  9. DORA (Google Cloud), State of AI-assisted Software Development 2025 (opens in a new tab)
    A large survey on how teams use AI. Its main finding is that AI amplifies what a team already is.
  10. Anthropic, “How AI assistance impacts the formation of coding skills” (January 2026) (opens in a new tab)
    A randomized study on learning a new library with and without AI help. Read the limits section.

Related: Project memory: CLAUDE.md and rules files · Extending agents: skills, hooks and MCP (coming soon) · Skill atrophy and deliberate practice (coming soon)

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper