Sub topic 7
Asking for a Plan Before Any Edits
This chapter assumes you can read and write code in one language, use Git branches and commits, run a test suite and a linter from the command line, and have used an AI coding assistant before. It covers one habit: asking the agent to describe what it intends to do, and approving that description, before it changes any file.
Why a plan comes first
A coding agent works in a loop: it reads files, edits them, runs commands, and looks at the results. In that loop an edit is cheap for the agent to make and expensive for you to undo. If the agent misunderstands the task, you find out after it has touched several files. You then have to read a large diff to work out where the misunderstanding started.
A plan moves that discovery earlier. A plan is a short written description of the steps the agent intends to take, the files it expects to touch, and how it will check each step. Reading a plan takes a minute. Reading a wrong diff takes much longer.
A plan helps in three ways:
- It exposes misreadings of the task. If you wanted
calculate_taxextracted fromformat_invoiceand the plan says "rewrite the whole pricing module", you can correct it before any code changes. - It shows what the agent knows. A plan that names a file that does not exist, or a function with the wrong name, tells you the agent lacks context or is guessing.
- It gives you a document to compare against later. When you review the diff, you can ask whether each change appears in the approved plan.
What a plan request looks like
The scoped task from the earlier chapter on task scoping already ends with a planning request. Here it is again:
Refactor pricing.py: extract the tax calculation from format_invoice into its own function named calculate_tax.
Constraints:
- Do not change the public signature or the return value of format_invoice.
- Touch only pricing.py and tests/test_pricing.py.
- Run `pytest tests/test_pricing.py` before and after the change and report both results.
First describe your plan in a few bullet points. Wait for my approval before editing.The last two sentences carry the planning request. Two details matter:
- "First describe your plan" asks for the plan itself, in a bounded size ("a few bullet points"). Without a size limit, plans tend to turn into long essays that nobody reads closely.
- "Wait for my approval before editing" sets a stop point. Without it, many agents write the plan and then carry on straight into edits in the same turn.
A good reply to that request might look like this:
Plan:
1. Run pytest tests/test_pricing.py and record the baseline result.
2. In pricing.py, add TAX_RATE = 0.2 and calculate_tax(subtotal), which returns round(subtotal * TAX_RATE, 2).
3. Change format_invoice to call calculate_tax(subtotal) instead of computing tax inline.
4. Leave the signature and return dictionary of format_invoice unchanged.
5. Run pytest tests/test_pricing.py again and compare with the baseline.
Files touched: pricing.py. I do not plan to edit tests/test_pricing.py unless a new test is needed.This plan is easy to check. It names the files, it repeats the constraints, and it includes the before-and-after test runs you asked for.
What to look for when you read a plan
Reading a plan is a review task with its own checklist. Go through these questions.
- Scope. Does the plan stay inside the files and behavior you named? Extra files are a warning sign, especially configuration files, shared utilities, and test fixtures.
- Order. Does it check the current behavior before changing anything? For a refactoring, the first step should be a baseline test run. If the code has no tests, the first step should be writing characterization tests.
- Step size. Is each step small enough to verify and commit alone? A step like "update all callers" is too large. A step like "update the three callers in
billing/" is better. - Verification. Does each step say how it will be checked? Look for named commands, such as the test runner, the type checker, or the linter.
- Facts. Do the file names, function names, and library calls in the plan exist? Spot-check two or three with a search. Invented names at the plan stage are a cheap warning that the agent may invent APIs later.
- Unstated assumptions. Does the plan quietly decide something you did not decide, such as a new dependency, a renamed public function, or a changed default value?
You do not need to approve a plan in one pass. Ask questions, request changes, and approve only when the plan matches what you want.
Asking for a better plan
Plans are often too vague on the first try. You can steer them with follow-up requests:
- "List the exact files you will edit and why each one is needed."
- "Split step 3 into steps that each leave the tests passing."
- "Which steps are reversible by a single
git restore, and which are not?" - "What could change behavior in this refactoring? List the risks."
- "Before planning, read
pricing.pyandtests/test_pricing.pyand tell me what you found."
The last request is useful when the agent has not yet read the code. A plan made without reading the code is a guess. Asking the agent to read first, and report what it found, gives you evidence that the plan rests on the real files.
Plans for larger changes
For a small refactoring, a plan of five bullets is enough. For a migration, such as moving from one library to another, the plan has more parts. Ask for these:
- Inventory. Every place the old library is used, found by search rather than from memory.
- Order. Which modules move first, and why. Start with code that has the best test coverage.
- Checkpoints. Where you will commit, and what must pass before each commit.
- Open questions. Anything the agent cannot decide without you, such as which behavior to keep when the old and new libraries differ.
Large plans are better stored in a file in the repository, such as MIGRATION.md, than left only in the chat. A file persists across sessions, shows up in version control, and can be handed to the agent again when context is lost. Later chapters on large migrations build on this idea.
When a plan is not worth it
A plan costs a round trip. For a one-line fix, such as renaming a misspelled variable in a single file, the plan is longer than the change. A rule of thumb:
| Situation | Plan first? |
|---|---|
| Rename one local variable | No. Review the diff instead. |
| Extract one function in one file | Yes, a short plan. |
| Change a function used in many files | Yes, with the inventory of callers. |
| Library or framework migration | Yes, written to a file and reviewed in detail. |
| Unfamiliar code you do not understand | Yes, and ask the agent to explain it first. |
Cost is not the only consideration. The risk of an edit also matters. A one-line change to a function used everywhere may deserve a plan, while a large edit to a throwaway script may not.
Where plans fail
A plan reduces risk but does not remove it. Know these limits.
- A plan is not a guarantee. The agent may follow a different path during the edit. Compare the final diff against the plan, and stop the agent if it drifts.
- Plausible plans can be wrong. A fluent plan can still name an API that does not exist. Verify facts, as described in the checklist above.
- Approval can be too casual. If you approve plans without reading them, the plan step adds delay and no safety. Read the plan, or skip the step.
- Plans go stale. If tests fail mid-task and the agent changes its approach, the approved plan no longer describes the work. Ask for a revised plan and approve it again.
The diagram shows the flow, including the return to planning when something does not fit.
A short worked example
Suppose you ask for the calculate_tax extraction and the agent replies with this plan:
1. Add calculate_tax to pricing.py.
2. Update format_invoice to use it.
3. Change TAX_RATE to be read from config.yaml so it can vary by region.
4. Update tests.Step 3 is not part of your request. It adds a new config file dependency and changes where a value comes from. Under a refactoring, observable behavior must stay the same, and this step could change it if the config file is missing or has a different value.
A good reply is: "Remove step 3. This task is only an extraction. If you think the rate should be configurable, mention it as a follow-up suggestion and do not do it now." The agent then revises the plan, and you approve the revised version. You have prevented an over-broad edit without reading any diff.
Summary of the habit
- End every non-trivial task description with a request for a short plan and an explicit instruction to wait.
- Read the plan against the checklist: scope, order, step size, verification, facts, assumptions.
- Push back until the plan is right, then approve it.
- Store large plans in a file in the repository.
- Compare the final diff against the plan, and re-plan when the work changes direction.
Exercise
An agent replies to your refactoring request with a plan of four steps. Step 1 is "Rewrite format_invoice and its helpers for clarity." Name two problems with this step and write one follow-up message that would fix them.
Show answer
The step is vague about which files and functions will change, and it is too large to verify or commit alone. It also invites behavior changes, because "for clarity" is not tied to your request to keep behavior the same. A follow-up message: "Replace step 1 with smaller steps. List the exact files and functions you will touch, limit changes to extracting calculate_tax, and say which command you will run after each step to confirm behavior is unchanged."
Exercise
You are migrating from one HTTP client library to another across 40 files. Which four items would you ask the agent to include in the plan, and where would you keep the plan?
Show answer
Ask for an inventory of every usage of the old library found by search, the order in which modules will move (starting with the best-tested code), the checkpoints with the checks that must pass before each commit, and a list of open questions where the two libraries behave differently. Keep the plan in a file in the repository, such as MIGRATION.md, so it persists across sessions and can be reviewed and updated in version control.