03 / 19
The plan, code, test loop and subagents in tools like Claude Code and Cursor.
Working with an agent is nothing like the "ask a question, copy the answer" pattern of a chat. You give the agent a job: it opens files, changes code, runs commands. Your job is to set the task up properly and to check what comes out.
The Claude Code docs describe how an agent works in three stages: it gathers context, it takes action, it verifies the result. It repeats the loop until the goal is met, and at each step it picks what to do next based on what it learned from the step before.1 You are inside the loop too, and you can stop it and steer it whenever you want.1
When you say "the cart total is coming out wrong, fix it", the agent moves like this: it runs the tests, reads the failure output, searches the relevant files, edits CartSummary.tsx and runs the tests again.1 So the quality of the result depends on there being a check the agent can use: a test, a linter, a type check. In the Prompt and context engineering guide we called that the "definition of done".
The Cursor team starts here: the most effective change you can make is to plan before you code.2
Not every job needs a plan. Plan mode is for changes you want to review before they reach the disk.3
Switch to Plan mode with Shift+Tab (the same shortcut in both tools). The agent reads the project without touching any files, asks you questions where it needs to, and produces a plan.23 You can edit the plan.
| A plan helps | A plan is overkill |
|---|---|
| Adding filtering and sorting to the product list | Changing the text on a button |
| Moving the cart state to another library | Adding a log line |
| Adding a feature in a codebase you don't know | Something you have done many times before |
Approve the plan and have the agent write the code by following it. If the result is not what you expected, don't try to patch it with follow-up messages: undo the changes, write the plan more clearly and run it again. Cursor says this usually gives a faster and cleaner result.2
Sometimes the agent adds files, abstractions or flexibility you didn't ask for. When you see that, draw the line: "Make only the requested change. Don't add features, refactors or abstractions."4
When the agent says "done", ask for proof: the test output, the command it ran, a screenshot. Reading the proof is faster than verifying everything from scratch.5 Having the tests written first also works well (Cursor's TDD flow):2
Have the agent write tests from the expected input-output pairs. Tell it not to write a fake implementation for code that does not exist yet.
Run the tests and watch them fail. It should not write application code at this stage.
Commit the tests.
Ask the agent to write code without touching the tests, until they all pass.
Commit the implementation.
In frontend work this means giving the agent the component tests you wrote in the Component testing with Vitest guide as its target.
Passing the tests isn't the goal by itself. The agent sometimes writes code that fits the test inputs instead of a general solution. Say "Don't special-case the test inputs or hard-code values. If a test is wrong, tell me."4
Commit small and often. Every commit is a checkpoint you can return to the next time the agent gets something wrong. Addy Osmani's rule is clear: do not commit code you cannot explain.6
/rewind rolls the code, the conversation or both back to an earlier request, which makes the bolder approach cheap to try.5 Claude Code's checkpoints still don't replace git, though. They cover only the changes the agent made with its file-editing tools, not terminal commands or operations on remote systems (a deploy, a database).15
Tip
The faster the agent gets, the more your review matters.2 Read the diff, and stop it when it heads the wrong way. Don't leave the agent unattended and expect a flawless result. Addy Osmani also writes that he uses the agent under supervision, watching every step and intervening where he has to.6
A subagent is a helper agent with its own context window. It does the heavy work there and returns only a summary to the main conversation.78 That keeps your main conversation's context from filling up (see Prompt and context engineering).
For example: "Look at every fetch call in the project and report which ones have no error handling." The agent is going to read dozens of files. If you hand that to a subagent, the contents of those files never enter the main conversation; only the summary "these four are missing it" comes back.
Handing a job to a subagent doesn't get you a better answer, since it runs the same model or a smaller one. What you get is parallelism, long output kept out of the main conversation, a fresh pair of eyes and a restricted set of tools. The price is tokens, and a subagent starting from nothing has to gather context first, so it can end up slower than doing the job directly.5 Current models delegate on their own, sometimes more than they should. For simple work, tell them to stay in the main conversation.4
| Use a subagent | Stay in the main conversation |
|---|---|
| Work that produces long output you will not look at twice: test output, logs, code searches | Work that needs constant back and forth |
| Independent pieces of research (auth, API, the data layer) | Work where planning, implementing and testing share the same context |
| Having the finished work verified by someone independent | Fast, small changes |
The ready-made ones: in Claude Code, Explore, which is read-only and searches fast, and Plan, which researches in plan mode, kick in on their own. Cursor has Explore and Browser, which drives the browser and summarizes the noisy DOM output.78 You don't have to set these up.
Writing your own subagent: if you keep giving the same job with the same instruction, write the subagent into a Markdown file. It goes under .claude/agents/ in Claude Code and .cursor/agents/ in Cursor (Cursor reads the .claude/agents/ folder too).78 The most important field is description: the agent reads it to decide when to hand over.78
---
name: a11y-reviewer
description: Reviews accessibility problems in changed components. Use after a component has been written or changed.
tools: Read, Grep, Glob
---
You are a frontend developer who is meticulous about accessibility.
In the changed components, look for: form fields without labels, images
with no `alt` text, interactions you cannot reach with a keyboard, and
insufficient contrast. Do not write to files; report what you find with
the file and line number.In Claude Code you restrict the tools with tools. In Cursor the equivalent is readonly: true.78
Tip
Keep the writer and the checker separate. One session writes the code, and another session or a subagent reviews it in a clean context, with no attachment to what was just written.5 In the terminal, /code-review reviews the diff in a fresh subagent that never saw the conversation.5 Cursor's verifier example is the same idea: it tests the work the agent called "done" with suspicion instead of taking the claim at face value.8
Warning
A reviewer told to "find the gaps" will find something even in solid work, and chasing it produces needless abstraction and defensive code. Tell the reviewer to report only the gaps that affect correctness or the stated requirements.5
Running several agents at once is in Parallel agents, and connecting the spec, code and test roles into one line is in Building an agent team. Every subagent spends its own tokens. Start with two or three focused subagents; don't open dozens of general "helper" ones.8
Cursor's Debug Mode does not fix things by guessing. It produces a few hypotheses first, adds logs to the code, asks you to reproduce the bug, looks at the runtime data to find the root cause and fixes it accordingly. It helps with race conditions, performance problems and "it used to work" bugs.2
Tip
You can watch Cat Wu and Boris Cherny, who build Claude Code, talk about how they use plan mode and subagents in their own workflows.9
Pick a small feature that touches a few files (sorting the product list by price, say). Ask for it in plan mode, read the plan, then delete or add a step and have it implemented.
For the same feature, have the tests written first, watch them fail, then have code written until they pass. Note how many rounds it took.
Have a subagent answer "are there accessibility problems in this change? only report them". If you are in Claude Code, use /context to see how much the main conversation's context moved.
Sources
The agent loop, tools, permission modes and checkpoints.
January 9, 2026. Lee Robinson. Plan mode, the TDD flow, parallel agents and Debug Mode.
Plan mode and reviewing a change before it reaches the disk.
Overengineering, fixating on passing tests, and overusing subagents.
Asking for proof, `/rewind`, `/code-review`, what subagents cost, and independent review.
Frequent commits, not committing code you cannot explain, and using the agent under supervision.
What a subagent is, when to use one, how to write one.
Subagents in Cursor, running them in parallel and their cost.
How Claude Code's own developers use plan mode, subagents and code review.
Check the lesson's main ideas with three questions.
Your progress is stored only in this browser.
Last updated: November 3, 2026