Plan-First Pattern for Coding Agents: How Strong Reasoning Models Should Plan Before They Act
This article explains the plan-first pattern for AI coding assistants, which splits development into a decision phase and an execution phase with a human review gate in between. It covers why single-turn conversational coding breaks down on larger tasks, the three defining traits of planning mode (read-only state isolation, reviewable plans instead of patches, and cheaper models for execution), and the rationale behind model tiering. Platform implementation details include routing logic, differentiated context assembly, and structured session continuity. The article also provides guidance on when to enable planning mode, a prompt template, metrics for evaluation, and a list of limitations and risks.
1. Background: From Conversational Coding to Planning First
Over the past two years, the dominant interaction pattern for AI coding assistants has been a single-turn loop: ask a question, get a code change, inspect the result. This works well when the change touches a single file, adds a utility function, or fixes a localized defect, because the task boundary is clear and the context window can hold all the relevant code.
The weaknesses of the single-turn loop surface all at once when the task becomes “add a configurable idempotent retry mechanism to the order module” or “consolidate time-handling logic scattered across four places into a shared utility layer”:
- Rising context assembly cost: Developers have to repeatedly paste in different files. In long conversations, early information gets diluted, and the model tends to “forget” the original constraints.
- High rework rate: The model starts editing before the approach is settled, only to discover at step three that the interface design conflicts with an existing module, invalidating the output of the first two steps.
- Uncontrolled cost: When a high-intensity reasoning task is split across turns, the actual spend far exceeds the cost of one high-quality planning pass.
- Human review is absent: The code diff appears directly, leaving reviewers to passively accept the result with no chance to intervene at the design level.
The planning mode is an interaction-level adjustment aimed at exactly this set of pain points. Its core is not swapping in a different model, but splitting the development workflow into a decision phase and an execution phase, with a human review point inserted between them.
2. What “Plan First” Means
Planning mode typically has three identifiable characteristics.
1. State isolation: read-only, no writes
In the planning state, the assistant only reads code, searches, analyzes dependencies, discusses approaches, and produces documents. It does not modify any source file or run commands with side effects. This matters because it fully separates “thinking it through” from “making changes” in time, so no plan iteration can pollute the workspace.
From an engineering standpoint, this is equivalent to making write access a mode-level switch rather than relying on prompt constraints:
Mode Read tools Write toolsNormal/auto File read, symbol search, log viewing File write, dependency install, test executionPlanning mode File read, symbol search, log viewing None (or plan document write only)
2. The deliverable is a plan, not a patch
The value anchor of planning mode is a reviewable implementation plan. A qualified plan contains at least: a list of change points (at file/module granularity), interface and data structure change descriptions, dependency and ordering arrangements, verification steps, and risk and rollback strategy. Missing any one of these means the plan cannot serve as a review gate.
3. The execution phase switches to a more economical model
Once the plan is settled, implementation work is largely mechanical and locally verifiable: write code against the checklist, add tests, run formatting and static checks. These tasks need noticeably less reasoning depth than solution design, so using a more cost-effective general-purpose model in this phase can significantly cut cost and latency with almost no quality loss.
3. Why Tier Models: Capability Density and the Cost Curve Are Misaligned
The idea behind model tiering is essentially to acknowledge that different stages demand different intensities of model capability.
| Stage | Reasoning depth | Context scope | Value per interaction | Suitable model |
|---|---|---|---|---|
| Requirement clarification, approach selection | High | Cross-module, includes docs | Determines all downstream work | Flagship reasoning model |
| Implementation, refactoring, test writing | Medium | Mostly local files | Linear accumulation | General balanced model |
| Formatting, naming, comments | Low | Single file | Very low | Lightweight model / rule-based tools |
Applying the flagship model to the entire flow yields rapidly diminishing marginal returns: at the third stage, the output difference between a flagship model and a general model is usually smaller than the cost of one manual rewrite. Conversely, using a general model during approach selection can lead to one wrong tradeoff that causes hundreds of lines of rework, which is where the real expense lies.
A common rule of thumb in engineering practice can be summed up in one sentence: spend the strongest reasoning budget on stages where the decision is irreversible.
4. Platform Implementation
The following describes how to build this two-phase interaction from a system implementation perspective. All code is illustrative pseudocode.
1. Routing layer
def handle_request(req, ctx):if req.mode == Mode.PLAN:if ctx.user.has_flagship_access:plan = flagship.chat(messages=build_planning_messages(req, ctx.repo_map),tools=READ_ONLY_TOOLS, # Key: no write tools)return PlanResult(doc=plan, requires_review=True)# Fallback when flagship access is unavailable: keep the planning# interaction but signal reduced capabilityreturn PlanResult(doc=balanced.chat(req, READ_ONLY_TOOLS),degraded=True)# Execution state: use the general balanced model, open write tools,# keep a minimal safety netreturn balanced.stream(req, ctx, tools=READ_WRITE_TOOLS_WITH_GUARDS)
Three design details are worth emphasizing:
- Check permissions up front: Planning mode depends on flagship model access, so the routing layer must validate this at session start, rather than letting users discover it is unavailable after a deep conversation.
- A fallback path must exist: Users without access should get explicit interaction feedback (plan quality may drop), not a silent failure or a hard error.
- Write tools need guardrails: When the execution state opens write access, keep mechanisms such as path allowlists, dependency install confirmation, and second confirmation for dangerous commands.
2. Different context assembly
The planning phase needs broader context; the execution phase needs deeper context. A practical approach is to maintain two levels of index:
- Repository-level summary (module breakdown, directory responsibilities, shared dependencies, code conventions), serving mainly the planning phase;
- File-level and symbol-level index (class/function signatures, call relationships, recent changes), serving mainly the execution phase.
routing:plan:model_class: flagship_reasoningtools: [read_only]context: ["repo_summary", "symbol_index", "issue_text"]edit:model_class: general_balancedtools: [read_write, guarded_shell, test_runner]context: ["plan_doc", "target_files", "symbol_index"]
3. Session continuity
When switching from the planning state back to the execution state, the plan document should be injected as structured context rather than relying on the model’s memory of the conversation history. Passing it with a fixed schema is recommended:
{"goal": "Add configurable idempotent retry to payment callbacks","changes": [{"file": "src/payment/callback.py", "action": "modify", "reason": "add retry branch"},{"file": "src/common/retry.py", "action": "create", "reason": "unify backoff policy"}],"interfaces": [{"name": "retry_policy", "signature": "...", "note": "backward-compatible default"}],"verify": ["pytest tests/payment -q", "mypy src/payment"],"risks": ["duplicate callback consumption", "backoff window exceeds gateway timeout"]}
This structure brings two direct benefits: reviewers can check items off one by one, and the execution phase can diff-verify item by item, making the plan-to-result path traceable.
5. Usage Guide: Which Tasks Are Worth Planning Mode
Recommended
- New feature development touching more than three files or requiring a new shared abstraction;
- Large-scale refactoring, interface signature changes, cross-layer call chain adjustments;
- Requirements that are themselves ambiguous and need boundary clarification before any code is written;
- Tasks with high upfront investment and expensive rework (such as data migration or build pipeline overhaul).
Not necessary
- Small single-file changes, localized defect fixes, comment and documentation additions;
- Exploratory tasks (“what does this code do”, “where might the performance bottleneck be”), where pure Q&A is more efficient;
- Tasks with an existing clear reference implementation that can simply be copied.
Prompt template for usable planning output
Goal: <one sentence describing a verifiable business outcome>Constraints: <performance/compatibility/dependency/convention limits>Known information: <relevant file paths, error messages, log snippets>Expected output:1. List of change points (file level)2. Interface changes and compatibility strategy3. Verification steps (directly executable commands)4. Risks and rollback planDo not modify files; output the plan only, for review.
The key to the template is writing the acceptance criteria into the input. Without verifiable acceptance conditions, the planning phase easily produces long documents that look complete but cannot be implemented.
6. Measuring Whether the Mechanism Works
Run an A/B comparison rather than switching based on intuition. Observable metrics include:
- First-pass rate: The proportion of execution-phase output that passes the first review;
- Rework line ratio: Lines of code ultimately rolled back or rewritten / total lines produced;
- Task cycle time: Wall-clock time from requirement intake to passing tests;
- Cost per task: In per-session billing scenarios, convert to the combined cost “per completed task” rather than cost per interaction;
- Review intervention quality: Whether the share of review comments at the “design level” (architecture tradeoffs, boundary definition) increases.
A healthy signal is review comments shifting from “this is written wrong” to “is this abstraction appropriate”, which means human attention has been freed up for higher-value positions.
7. Limitations and Risks
- Upfront cost: Planning itself consumes one fairly strong model inference, which may not pay off for small tasks; consider a task complexity threshold or let users decide.
- Over-engineering: Strong reasoning models tend to produce structurally complete plans with clear module separation. With insufficient constraints, they easily introduce new abstractions the current requirement does not need. The mitigation is to explicitly state “minimal change first” in the prompt.
- Plan and implementation drift: The execution-phase model may find flaws in the plan while implementing. The execution phase should be allowed to report that “the plan needs revision” and support returning to the planning state, rather than rigidly following the original checklist.
- Permission and version differences: Planning mode depends on flagship model access and a recent client version; behavior degrades when environments differ, so this needs explicit signaling at the interaction layer.
- Context length limits: Repository-level summaries for very large codebases carry maintenance cost, and a stale summary leads to plans built on false premises.
8. Conclusion
The plan-first interaction pattern adjusts how AI coding assistants are used, from “let the model write the whole feature” to “let the model and the human settle the plan together, then split up the implementation”. It brings benefits on three levels: quality, where moving decisions earlier surfaces errors at the lowest-cost stage; cost, where the strong reasoning budget concentrates on decision-making and implementation goes to a more economical model; and process, where the structured plan naturally becomes a review artifact that fits existing code review and compliance workflows.
It is worth stressing that this mechanism is not optimal by default. Whether to enable it depends on task complexity, rework cost, and the team’s review habits. Treating it as one tool in the toolbox rather than the only correct way of working is the prerequisite for getting the most out of it.
