Sub topic 12
A plan, implement, verify workflow
This chapter assumes you can use a shell and git, can run your project's tests, and know the agent loop from earlier chapters: the model calls a tool, reads the result, and decides what to do next. Here you will apply that loop to a repeatable task workflow.
Why a workflow helps
An agent given a vague request will start editing quickly. It may pick the wrong files, solve a different problem than the one you meant, or change more than you wanted. Each of these costs you review time, and the cost grows with the size of the diff.
A three-phase workflow limits this. You agree on a plan first, let the agent implement a small piece, and then check the result with evidence instead of trust.
Phase 1: Plan
In the planning phase you ask the agent to read and reason, but not to change anything. Reading files and searching are low-risk tools. Edits and shell commands carry more risk.
Each tool has a way to keep the agent read-only:
- Claude Code has a plan permission mode. You can cycle modes with Shift+Tab during a session, or start with
claude --permission-mode plan. - Codex CLI can run with a read-only sandbox, for example
codex --sandbox read-only. - Copilot CLI asks for approval before it runs most tools, so you can decline edits while it explores.
Mode names and flags change between releases. Check --help for your installed version.
A good planning prompt names the goal, the constraints, and the output you want:
Dates like "2024-W07-3" fail to parse in src/date/parse.ts.
Read the parser and its tests. Do not edit anything.
Propose a plan with numbered steps, the files you would change,
and the tests you would add. List any open questions.Review the plan the way you would review a colleague's design. Look for these problems:
- Files you did not expect, especially generated code, lock files, or configuration.
- A step that is too large to verify on its own.
- Assumptions about behavior that you can check yourself.
- No test step.
If the plan is wrong, correct it now. Changing a plan costs one message. Changing a finished implementation costs a review.
Phase 2: Implement
Implement one step at a time, or a few closely related steps. A narrow scope keeps the diff small enough to read.
Implement steps 1 and 2 of the plan only. Write the failing test first,
then the fix. Run `npm test -- date` after each change.
Do not touch anything outside src/date/.Three habits make this phase reliable:
- Give the agent a way to check itself. If you tell it the test command, it can run the tests, read the failure, and fix its own mistakes inside the loop. The project instruction file from the previous chapter is the right place to store these commands.
- State what is out of bounds. Name directories and files the agent must not edit.
- Interrupt early. If the agent heads in the wrong direction, stop it (Esc in Claude Code, Ctrl+C in the others) and redirect. Waiting for it to finish a wrong approach wastes tokens and fills the context window with noise.
When a session grows long or goes off course, start a fresh one with a short summary of the plan and what is done. A clean context often beats a long one full of dead ends.
Phase 3: Verify
Verification means producing evidence that the change works. The agent saying "done" is not evidence. Use the checks in this order, from cheapest to most expensive:
| Check | What it catches | Who runs it |
|---|---|---|
| Read the diff | Unrelated edits, deleted code, hard-coded values | You |
| Type check and lint | Syntax and style errors, wrong types | Agent or you |
| Targeted tests | The behavior you changed | Agent or you |
| Full test suite | Regressions elsewhere | You |
| Manual run | Problems tests do not cover | You |
Run the full suite yourself, even if the agent already ran it. You then see the real output instead of a summary of it.
Check the tests, not just the result
An agent that is told to "make the tests pass" can pass them the wrong way. Look for these patterns in the diff:
- A test was deleted, skipped, or loosened to match the broken behavior.
- An assertion was changed to expect the new wrong output.
- The fix special-cases the test input instead of fixing the logic.
- Errors are caught and swallowed.
A useful safeguard is to ask the agent to add a test that fails before the fix. Then you can confirm it by stashing the fix and running the test. A test that never failed proves little.
Ask for a review pass
You can also start a separate session and ask for a review of the diff. A fresh session has no memory of the reasoning that produced the code, so it reads the change with less bias.
Review the uncommitted changes with `git diff`. Look for bugs,
missing edge cases, and changes unrelated to date parsing.
Do not edit files. Report findings as a list.Treat the review as a source of leads, not as a verdict. Check each finding yourself.
Using git as the safety net
The workflow depends on being able to undo. Work on a branch, and commit at each verified step so you can return to a known-good state.
git switch -c agent/fix-date-parsing
# ...run the agent on a narrowly scoped task...
git diff
npm test
git add -p
git commit -m "Fix date parsing for ISO week dates"git add -p lets you stage hunks one at a time, so you accept only the changes you have read. Anything you leave unstaged can be discarded with git restore. Run that command yourself after you have checked what it will remove, because it cannot be undone.
Edge cases
- The plan was right but the code is wrong. Return to the implement step with the failure output, not to planning.
- The agent keeps failing the same test. After two or three attempts, stop. Read the failure yourself. The cause is often a wrong assumption in the plan.
- The task is too big to plan in one pass. Split it into tasks that each end in a commit.
- The change touches code with no tests. Add characterization tests first, then change the behavior.
- Another process changes files during the session. Commit or stash before you start so the diff shows only the agent's work.
Exercise
An agent reports that all tests pass after fixing a bug. Name three things you should check before you commit.
Show answer
Read the full diff for unrelated edits. Check that no tests were deleted, skipped, or weakened, and that a new test covers the bug and failed before the fix. Run the full test suite yourself and read its output. Staging with git add -p also lets you accept only the hunks you have reviewed.
Exercise
Your plan has six steps. The agent finishes all six in one run and produces a 900-line diff that includes a changed lock file. What would you do differently next time, and why?
Show answer
Ask the agent to implement one or two steps at a time and commit after each verified step. Small diffs are easier to read and easier to revert. Also state the out-of-bounds files, such as lock files, in the prompt or instruction file, and catch the unexpected lock file change during plan review.