Sub topic 1
Why Ask for a Plan Before Code
A coding agent that edits files as soon as it receives a request can solve the wrong problem or change more code than you intended. This chapter explains why a written plan, reviewed before any edit, reduces that risk. It also covers where planning stops being worth the effort. Later chapters cover what goes into a plan and how to request one.
Prerequisites
This chapter assumes you have:
- Basic experience using a coding agent or AI assistant on a code repository.
- Familiarity with version control: commits, diffs, and branches.
- Enough comfort with the project's test suite to run it and read the results.
You do not need to know any particular agent product. The ideas apply to any tool that can read and edit files in a repository.
What goes wrong when the agent edits first
When you give an agent a short request such as "add rate limiting to login," it must fill in many details you did not state. It picks a storage mechanism, chooses which files to touch, and decides what counts as done. Each choice is a guess. If you only see the guesses after the edits exist, you have to find them by reading a diff.
Four failure patterns come up repeatedly.
- Wrong problem solved. The agent builds something that matches the words of the request but not your intent. For example, it limits all requests to the endpoint when you meant only failed attempts.
- Scope creep. The agent renames a helper, reformats a file, or adds a dependency "while it was there." The diff grows, and reviewing it takes longer than the feature did.
- Hidden assumptions. The agent assumes a single server process, a certain database, or a certain config style. The code works in its mental model and fails in your deployment.
- No way to check. The agent reports success, but neither of you stated what success looks like, so you have no test to run.
All four share a cause. The agent's interpretation of the task was never made visible before it was acted on.
What a plan changes
A plan is a written statement of how the agent intends to do the work, produced before it changes anything. It moves the point at which you find a misunderstanding from after the edits to before them.
The cost difference is the main argument. Correcting a plan means changing a few lines of text. Correcting a finished implementation means reading a diff, working out which parts are wrong, asking for changes, and re-reviewing. The later the error is found, the more work depends on it.
A plan also gives you three practical things.
- A review surface. You can judge the approach, the file list, and the assumptions as prose, without reading code.
- A reference for the diff. When the edits arrive, you compare them to what was agreed. A file the plan did not mention is an immediate question.
- A shared definition of done. A plan that includes a verification method states in advance which tests or checks must pass.
A concrete comparison
Consider this request sent without a plan step:
Add rate limiting to the /login endpoint.The agent might add a third-party package, store counts in memory, limit every request regardless of outcome, and change the error format. Each choice is defensible, and each might conflict with your project.
Now compare a request that asks for a plan first:
I want to add rate limiting to the /login endpoint.
Goal: reject more than 5 failed attempts per IP address in 10 minutes.
Constraints: do not add new dependencies; keep the existing error response format.
Do not edit any files yet. Read the relevant code and give me a plan with:
1. The files you expect to change and why
2. Ordered implementation steps
3. Risks and anything you are assuming
4. How we will test that it works
Ask me questions if something is unclear.This request does three things. It states the goal and the constraints. It forbids edits for now. It tells the agent what the plan must contain. The agent's reply is something you can read in a minute and correct if it is wrong.
A returned plan might include this line:
- Assumes a single server process; an in-memory counter is not shared across processes.If your service runs several processes, you have just caught a design flaw before any code exists. Without the plan, you would likely have found it in production, when the limit failed to apply consistently.
Why planning helps the agent as well
The benefit is not only on your side. Writing a plan forces the agent to read the relevant code and commit to an approach before it starts editing. Two effects follow.
- Better grounding. An agent that has to name the files it will change must first look at them. Plans that cite real files and functions tend to reflect the actual code, not a generic pattern.
- Surfaced uncertainty. When asked for risks and assumptions, the agent lists things it would otherwise have decided silently. It can also ask questions, which is cheaper than guessing.
A plan does not guarantee that the agent understood the code. It can name a file that does not exist, or misread how a function behaves. That is why the review step matters, and why a later chapter treats reviewing a plan as a task of its own.
The cost of planning
Planning is not free. You pay for it in three ways.
- Time. Writing the request, reading the plan, and replying take minutes. For a task that would take one minute to do and check, this overhead is larger than the work.
- Attention. A plan you approve without reading provides no protection. A rubber-stamped plan is worse than none because it gives false confidence.
- Staleness. A plan reflects the code at the moment it was written. If the code changes before implementation, or if the agent discovers something mid-task that contradicts the plan, the plan needs updating.
Planning pays off when the cost of a wrong edit is higher than the cost of the review. That depends on the task, not on a fixed rule.
| Situation | Plan first? | Reason |
|---|---|---|
| Change touches several files or modules | Yes | More places for a wrong guess to spread |
| Requirements have open design choices | Yes | The plan makes the choices visible |
| You do not know the code well | Yes | The agent's reading of the code becomes reviewable |
| Change is hard to undo (migrations, deploys, deletions) | Yes | Mistakes cost more |
| Fixing a typo or a one-line bug with an obvious cause | No | The diff is its own plan |
| Renaming a variable in one file | No | Review takes seconds either way |
| Exploratory throwaway script | Usually no | Low cost of being wrong |
A later chapter returns to this decision in more detail. For now, a useful rule is this: if you could review the finished diff in under a minute and be sure it is right, a plan adds little.
What a plan does not replace
A plan sits alongside other safeguards and does not substitute for them.
- Version control. Work on a branch and commit before the agent starts, so any edit is reversible.
- Tests. A plan names how to verify the result. The tests do the verifying.
- Diff review. Approval of a plan does not mean the implementation matches it. You still check the diff.
The workflow in outline
The rest of this tutorial expands each stage of one loop:
- Give the agent the context it needs, then write a planning request that forbids edits.
- Let the agent read the code and ask questions.
- Review the plan, correct wrong assumptions, and ask for a revision.
- Approve explicitly, so the agent knows edits are now allowed.
- Implement in small steps, checking each against the plan.
- Verify the finished change against the plan and the tests.
Each stage has a specific failure that it prevents. Skipping one weakens the others. An approval without a review has no value, and a review without a stated goal has nothing to measure against.
Summary of key points
- An agent that edits immediately makes many silent guesses, and you find them only by reading a diff.
- A plan makes those guesses visible while correcting them is still cheap.
- A plan gives you something to review, something to compare the diff against, and a stated way to verify the work.
- Planning costs time and attention, and it protects you only if you read the plan.
- For small, obvious, easily reviewed changes, skip it.
Exercise
You ask an agent to "speed up the report page." It edits six files, adds a caching library, and changes the database query. The page is faster, but you wanted only the query changed and no new dependencies. Name two things a planning step would have given you that would have prevented this outcome.
Show answer
First, the plan would have listed the files the agent expected to change and any new dependency, so you would have seen the six files and the caching library before any edits and could have rejected them. Second, a planning request can state constraints such as "do not add new dependencies" and "change only the query," and the plan would have shown whether the agent respected them. The plan would also have exposed the agent's assumption about what "speed up" meant, which you could correct in a revision.
Exercise
For each task, decide whether to ask for a plan first and give one reason: (a) fix a typo in a README, (b) add a database column and update the three services that read the table, (c) rename a local variable inside one function.
Show answer
(a) Skip the plan. The diff is one word and takes seconds to check. (b) Ask for a plan. The change spans a schema and several services, and a migration is hard to undo, so a wrong assumption is costly. (c) Skip the plan. The change is local, trivial, and fully visible in the diff.