Cutting AI Coding Costs: A Dual-Core Workflow That Separates Planning from Execution

    Scaling up to the most powerful models and calling them without restraint is not the right way to control costs. This article explains a more effective approach: restructure your workflow so that high-capability models handle planning—problem clarification, solution design, and task decomposition—while cost-effective models handle execution—writing code to spec, completing tests, and fixing known defects. The two stages connect through structured specifications and are backed by strict context constraints and automated verification. You'll learn how AI coding costs actually break down, why perceived speed often diverges from real delivery efficiency, a five-step planning method, engineering constraints for execution, three-layer context engineering, cost observability metrics, a phased rollout roadmap, and the common pitfalls to avoid.

    Introduction: The Question Behind the Bill

    When last month’s bill arrived, you probably felt that small jolt: subscriptions to an AI coding tool, plus a few heavy sessions calling a high-capability large model for refactors, adding up to a non-trivial expense. People joke that they’re paying the AI a salary—giving it a senior architect’s pay while it spends its time adding and deleting fields or filling in null checks in the codebase.

    At the same time, the vendors behind these tools often announce another big funding round, with valuations hitting new highs and annual recurring revenue climbing steadily. Developers are both the most direct beneficiaries of these tools and the paying group that fuels their commercial growth. Rather than agonizing over whether you can afford it, it’s worth asking from a different angle: where is the marginal output of this spending, and how should it be reallocated?

    The conclusion up front: endlessly upgrading models and calling them without limit is not the right way to cut costs. A more effective approach is to restructure the workflow—high-capability models focus on planning (problem clarification, solution design, and task decomposition), while cost-effective models handle execution (writing code to spec, completing tests, and fixing known defects). When the two are connected through structured specifications and combined with strict context constraints and automated verification, you can cut costs from three digits down to two and halve debugging time—all without sacrificing code quality. In the end, the developer’s role shifts from “the person who writes code line by line” to “the person who orchestrates the AI workflow.”

    1. Where the Costs Come From: The Real Cost of AI Coding

    1.1 Hidden Costs: Four Categories Beyond the Bill

    API and subscription fees are only the tip of the iceberg. The full cost of one AI-assisted development task includes at least five parts:

    Cost item Description Main drivers
    Model call fees Subscription or pay-as-you-go API billing Unit price, input/output tokens, number of rounds
    Context overhead Code snippets and conversation history resent on every call Context length per request
    Rework cost Reviewing and debugging “almost correct” output First-pass success rate, number of rework rounds
    Context switching Moving back and forth between AI suggestions and manual coding Coherence of suggestions
    Decision fatigue Attention consumed by repeated confirmation, comparison, and trade-offs Trustworthiness of generated content

    1.2 The Efficiency Paradox: Feels Faster, Actually Slower

    Behind rising costs lies an even more worrying phenomenon. Numerous surveys show that more than 80% of developers subjectively feel that AI has improved their productivity. Yet a controlled experiment with experienced open-source developers familiar with large codebases reached a different conclusion: when allowed to use AI, they took nearly 20% longer to complete tasks than without it—despite expecting beforehand that AI would make them about 25% faster.

    This gap between “expectation” and “reality” isn’t an isolated case. A developer survey covering tens of thousands of respondents found that two-thirds of professional developers consider AI-generated code “almost right, but not quite,” and more than 40% admitted that debugging AI-generated code takes longer than writing it themselves from scratch.

    Mapping these subjective feelings onto objective indicators yields two patterns:

    • Subjective fluency ≠ delivery efficiency. The instant satisfaction of code that “looks runnable” easily masks hidden costs like misread requirements and missed boundary conditions.
    • AI changes where the bottleneck is. Once coding speed is sharply compressed, the bottleneck shifts to review and verification. The “80/20 rule” applies here too: roughly 80% feel faster, while average time actually rises by about 20%.

    1.3 Root Cause: The Wrong Model in the Wrong Seat

    The root of these problems is usually not that models aren’t capable enough, but that models are misassigned to roles:

    • Strong models doing low-value repetition. Using the model with the strongest reasoning and long-context abilities—and the highest unit price—to write boilerplate, add type annotations, or rename fields is a serious misallocation.
    • Weak models making hard decisions. To save money, using a lightweight model to directly handle cross-module refactors, ambiguous requirement decomposition, or tricky bug localization produces a flood of “almost correct” code—and rework ends up costing more.
    • Out-of-control context. Every round carries large blocks of code and history, so input tokens swell and costs rise directly with context length on services where input billing dominates.
    • No verification loop. Without automated checks to catch generated code, everything relies on manual line-by-line review, so defects aren’t found until they flow into later stages.

    In one sentence: it’s not that models are expensive—it’s that they’re used in the wrong role, and used clumsily. By analogy, having a senior architect tighten screws on the assembly line every day: he certainly can do it, but the cost is absurd, and he may not even be faster than a skilled worker. The sensible approach is to have the architect design “how to tighten, where to tighten, and to what standard,” leave the actual motion to the line worker, and let a quality inspector handle acceptance.

    2. The Dual-Core Workflow: Planner Plans, Executor Executes

    2.1 Core Principle: Allocate by Capability, Not Unit Price

    The basic form of the dual-core workflow is: the Planner “thinks it through,” and the Executor “makes it happen.”

    Dimension Planner Executor
    Core responsibility Clarify requirements, design solutions, decompose tasks, define acceptance criteria, re-plan after failures Complete coding, testing, and docs to spec; make targeted fixes based on verification feedback
    Capability needs Strong reasoning, long-context understanding, cross-module trade-offs Stable code generation, instruction following
    Cost strategy Higher unit price, few calls Low unit price, high call frequency; dominant share of total volume
    Output Structured spec (task list, impact scope, acceptance criteria) Code changes, tests, and verification reports
    Context Architecture docs, key modules, historical decisions A few files and conventions directly relevant to the task

    It’s worth stressing that “dual-core” is a logical role division, not a requirement that the two roles map to two different vendors’ models. Different model tiers from the same provider, or different inference configurations of the same model, can each fill the two roles. What matters is aligning three things: model capability, task difficulty, and cost structure.

    2.2 Why It Works: Value Density Determines Cost Allocation

    You can roughly rank work in AI-assisted development by “value density”:

    1. Problem definition and solution trade-offs (high value density, short time)
    2. Architecture design and interface contracts (high)
    3. Core business logic and algorithm implementation (fairly high)
    4. Boilerplate code, type completion, docs, and comments (medium)
    5. Formatting, renaming, mechanical edits (low)

    The traditional approach is “one-size-fits-all”: the same most-powerful model does all the work. The total cost per task then is roughly:

    cost ≈ high-capability unit price × tokens of (high-value work + low-value work)

    The dual-core workflow allocates compute by value density:

    cost ≈ high-capability unit price × tokens of high-value work + cost-effective unit price × tokens of low-value work

    Here, planning and acceptance require far fewer tokens than execution, and the concrete form of execution code is highly predictable—well suited to a cost-effective model working to a uniform spec. Assuming execution accounts for 70% of total call volume and the execution model’s unit price is one-fifth that of the high-capability model, this single structural change alone can cut model-call spending by about 50%.

    But cost reduction can’t come at the expense of quality. Three prerequisites:

    1. Clear specs. The Planner’s output must be specific enough that the Executor doesn’t have to “guess” requirements.
    2. Reliable verification. Every step’s output is backed by automated checks, so errors are caught during execution.
    3. Ordered escalation. When the execution model fails repeatedly or fails verification, the task escalates promptly to the high-capability model rather than spinning in place.

    2.3 An Example of the Division of Labor

    Take the same feature request—“add filtering by creation-time range to the order list.” The two modes handle it very differently.

    One-size-fits-all mode (illustrative):

    1. User: Add a filter by creation-time range to the order list
    2. AI: [reads through multiple files and returns a large batch of code changes]

    Dual-core mode (illustrative):

    1. Planner: Confirmed the change spans 3 files. Task 1 (Executor): add time-range parameters
    2. in the query layer; Task 2 (Executor): validate and pass through the parameters
    3. in the API layer; Task 3 (Executor): add boundary-case tests.
    4. Acceptance: open/closed intervals are explicit, invalid input returns a clear
    5. error code, and all tests pass.
    6. Executor: Complete each task to spec in turn and submit for verification
    7. Validator: Static checks, type checks, and unit tests all pass

    The first mode outputs “a large block of plausible-looking code”; the second outputs “a series of tasks that can be accepted one by one.” Their reviewability and rollback-ability are completely different.

    3. The Planner’s Five-Step Method: Turning Planning into an Executable Contract

    The planning stage should not produce prose-style suggestions, but a structured specification. Work through five steps:

    1. Clarify the goal. Define “what to change, why, and how to verify afterward,” confirming boundary conditions and compatibility requirements with the user when needed.
    2. Build global awareness. Quickly map out module boundaries, dependency directions, key data structures, and build/test entry points—avoid guessing the global design from local information.
    3. Decompose in layers. Split the requirement into three layers—“architecture decisions, interface contracts, task list”: architecture decisions need human confirmation, interface contracts are frozen once set, and the task list is handed to the execution model.
    4. Rehearse risks. List boundary conditions, exception paths, data migration, performance and compatibility risks, and the points where human intervention is required.
    5. Freeze the spec. Once frozen, the spec becomes the sole basis for the execution stage; if requirements change mid-stream, you must return to planning to update the spec.

    An example spec ready to hand to the execution model:

    1. {
    2. "task_id": "order-filter-time-range-01",
    3. "goal": "Support filtering the order list by a creation-time range",
    4. "constraints": [
    5. "Keep the existing API backward compatible; all new parameters are optional",
    6. "Do not modify the database schema; reuse existing indexes"
    7. ],
    8. "files": [
    9. {"path": "src/query/order_query.py", "change": "Add optional created_after / created_before parameters"},
    10. {"path": "src/api/order.py", "change": "Parse and validate time parameters; return 400 on invalid input"},
    11. {"path": "src/utils/time.py", "change": "Add a parse_range helper"}
    12. ],
    13. "acceptance": [
    14. "Both endpoints are closed intervals; return a clear error when start > end",
    15. "Behavior is unchanged when parameters are omitted",
    16. "New unit tests cover normal, boundary, and invalid-input cases"
    17. ],
    18. "verification": ["ruff check .", "mypy src/", "pytest tests/order -q"],
    19. "risks": ["Time-range queries under large data volumes need an index-hit check"]
    20. }

    The static-check, type-check, and test commands here should be replaced with the commands from your project’s actual toolchain. The more specific the spec, the less room the execution model has to “guess,” and the lower the probability of rework.

    4. Engineering Constraints for the Executor: Small Steps and Automated Verification

    4.1 Make the Execution Model “Change Only What It Should”

    The execution-stage prompt should carry five types of information: task ID, file list and change points, constraints, acceptance criteria, and verification commands. Beyond that, four execution disciplines apply:

    • One task, one goal. Handle a single subtask at a time; avoid wide changes spanning multiple modules.
    • Minimal changes. Don’t refactor code unrelated to the task, and don’t opportunistically “tidy up” formatting or naming.
    • Self-verification. After finishing changes, proactively run the checks agreed in the spec.
    • Fail by reporting. If you can’t complete within the constraints, output the blocking reason and the information needed—don’t fabricate an implementation.

    4.2 Leave Verification to Machines, Not Human Eyes

    “Almost correct” is costly precisely because it lulls you into lowering your guard. The goal of the verification stage is to have the machine stop “not-quite-correct” work before it merges:

    • Static checks. Enforce uniform formatting and static-analysis rules to eliminate back-and-forth over style.
    • Type checks. Surface mismatches in interface signatures and data types early.
    • Unit tests. Convert the acceptance criteria from the Planner directly into test cases, especially for boundary and exception scenarios.
    • Change-scope review. Use version control to compare the files actually changed against the spec’s list, preventing the execution model from “casually editing” unrelated code.
    • Quality gate. Only allow entry to manual review once all the above checks pass; on failure, return to the execution stage with failure logs for targeted fixes.

    4.3 Orchestration Pseudocode: Cost Budget and Escalation

    1. MAX_ATTEMPTS = 3 # max execute-verify cycles allowed per task
    2. def run_task(task, spec):
    3. context = build_context(spec) # load only task-relevant context
    4. for attempt in range(1, MAX_ATTEMPTS + 1):
    5. result = executor.generate(spec, context, temperature=0) # low-cost execution
    6. report = verifier.run(result, spec) # automated verification
    7. if report.passed:
    8. record_metrics(task, spec, attempts=attempt, usage=result.usage)
    9. return result
    10. context = update_context(context, report.failures) # targeted context on failures
    11. if attempt == MAX_ATTEMPTS:
    12. return escalate_to_planner(task, spec, report) # escalate to high-capability model or human

    This is illustrative pseudocode. The executor, verifier, and escalate_to_planner pieces can each connect to different model tiers, plus your project’s own check and test tools. Two things to note in practice:

    • Temperature during execution. In most mainstream APIs, the temperature parameter adjusts output randomness; lower values make output more deterministic. Code generation usually needs stable, reproducible output, so temperature is often set low—but the exact default should follow the provider’s documentation.
    • Retries and cost. More retries isn’t always better—it scales execution cost linearly. Set an upper limit and monitor each task’s actual number of cycles.

    5. Context Engineering: Lean and Precise Beats Large and Complete

    5.1 Three-Layer Context Structure

    Layer Content Loading strategy
    L1 Global Coding conventions, directory structure, tech-stack versions, general prohibitions Always loaded; keep lean (aim for ~1–2K tokens)
    L2 Task Files, interface definitions, and data structures directly relevant to the task Loaded on demand; keep only relevant functions and type definitions
    L3 Feedback Verification failure logs, error stack traces, prior failed attempts Appended only in targeted rework rounds

    5.2 An Example of a Lean Rules File

    Many AI coding tools support giving the model persistent constraints via a rules file in the project root. Rules should be written as checkable clauses, not lengthy introductions. Example:

    1. # Project Conventions
    2. - Stack: Python 3.12 / Django 5.x / PostgreSQL; dependencies managed via pyproject.toml
    3. - Layers: api (interface) → service (business) → repository (data access); no cross-layer calls
    4. - Prohibited: building SQL directly in view functions; committing print debug statements; editing auto-generated files
    5. - Required: new or modified functions must have type annotations; logic changes must include unit tests
    6. - Verification: ruff check . && mypy src/ && pytest -q

    5.3 Four Practical Recommendations

    • Retrieve on demand, don’t stuff everything at once. Use semantic or keyword search to locate relevant snippets from the codebase and docs, rather than pasting large blocks of code into the conversation wholesale.
    • Draw the dependency graph before editing. For cross-module changes, have the planning model first map call relationships and impact scope; this sharply reduces cases where the execution model “fixes one thing and breaks a whole area.”
    • Manage conversation state. In long sessions, periodically archive or trim history to avoid early, irrelevant information occupying context and inflating the input cost of every call.
    • Have the model “look it up,” not “guess.” Expose internal API docs, database schemas, and dependency versions in a structured form so the model can query them on demand rather than fabricating APIs from training memory. To connect to model services on Baidu AI Cloud, refer to the official documentation for the specific interfaces and parameters.

    6. Cost and Efficiency Observability: Measure First, Then Optimize

    Cost reduction can’t be done by feel. Set up a “task-level bill” for each AI-assisted development task:

    • Token usage: Record input and output tokens separately for the planning, execution, and rework phases.
    • Rework rate: The proportion of tasks that fail verification out of the total.
    • First-pass rate: The share of tasks that pass all verification on the first execution.
    • Cost per effective output: Total cost divided by lines of merged code changes (or user stories completed).
    • Escalation rate: The proportion of tasks escalated from the execution model to the high-capability model.

    Summarize weekly and watch three signals:

    1. A high share of planning-phase spend. This may mean the spec isn’t clear enough, or the model is “thinking in circles” without converging.
    2. A high number of rework cycles. This usually points to insufficient context, vague constraints, or missing verification standards.
    3. An abnormal escalation rate. This may mean task difficulty has exceeded the execution model’s capability, requiring a change to the division-of-labor strategy.

    7. Phased Rollout Roadmap

    1. Phase 1 (Weeks 1–2): Establish a baseline. Review the past month’s call records, break down spend by model and scenario, and identify typical cases of “a high-capability model doing low-value work.”
    2. Phase 2 (Weeks 3–4): Separate planning from execution. Introduce spec templates and a planning checklist, switch task types to “plan first, execute second,” and compare quality and cost changes for equivalent tasks.
    3. Phase 3 (Weeks 5–8): Systematize context and verification. Refine the project rules file, the on-demand retrieval mechanism, and the automated verification pipeline, gradually raising the first-pass rate to a stable level.
    4. Phase 4 (long term): Make orchestration the norm. Codify spec generation, task dispatch, automated verification, failure escalation, and cost accounting into a reusable pipeline. Individual developers can use lightweight scripts, while teams can leverage platforms like Baidu AI Cloud—which offer model services, application development, and monitoring and alerting capabilities—to build the orchestration and observability system.

    8. Common Pitfalls and Risk Boundaries

    • Pitfall 1: Cheaper is always better. For architecture design, safety-critical logic, and complex bug localization, low-cost models may produce hard-to-spot errors whose rework cost far exceeds the saved call fees.
    • Pitfall 2: More detailed specs are always better. Overly detailed specs drive up planning cost and are hard to maintain; choose a granularity that fits task complexity.
    • Pitfall 3: Automated verification can replace humans. Automated checks catch “whether the code follows conventions and whether tests pass,” but they struggle to judge “whether the approach is sound and whether the requirement is correctly understood.” Key design reviews should still be gated by people.
    • Data security and compliance. Before sending code and business data to external model services, complete data masking and access-control assessments; for sensitive codebases, prefer solutions that support on-premises or private deployment.
    • Licensing and intellectual property. AI-generated code may raise open-source license compatibility issues, so enterprise teams should establish a corresponding review process.

    Conclusion

    The path from the anxiety of “paying the AI’s salary” to the ease of “scheduling the AI” is separated not by a more expensive model, but by a clearer workflow. To recap, the four pillars of cost reduction are:

    • Separate planning from execution. Let high-capability models make the “few but hard” decisions, and let cost-effective models do the “many but deterministic” execution.
    • Specs are contracts. Use structured specs to connect the two stages, reducing guessing and rework.
    • Automate verification. Keep “almost correct” from merging.
    • Make cost observable. Use data to drive ongoing adjustments to the division of labor.

    When developers stop chasing the AI’s output line by line and instead design rules, define acceptance criteria, and orchestrate the process and models, they go from “people chased by the AI bill” to people truly in command of the AI workflow.