Reducing AI Coding Costs with a Planning-Execution Split
Teams often face higher-than-expected AI coding bills without faster delivery. This article examines the efficiency paradox behind those costs, breaks down the total cost of AI-assisted development, and proposes separating high-capability planning from cost-effective execution. It covers task granularity, context management, external documentation, verification loops, measurement, and implementation risks, with a pseudo-code workflow for applying the approach.
Reducing AI Coding Costs with a Planning-Execution Split
1. From Bill Anxiety to the Efficiency Problem
Since AI coding assistants became widespread, many developers have encountered the same situation: usage details at the end of the month show costs above budget, while code delivery speed has not increased noticeably. The bill is only the most visible signal. The core issue behind it is an efficiency paradox.
Industry surveys show that more than 80% of interviewed developers subjectively believe AI tools have improved their productivity. However, a controlled experiment with open-source developers reached the opposite conclusion: the group using AI assistance took about 19% longer to complete tasks. This gap between subjective experience and objective time shows that “feels convenient” and “is truly efficient” are two different things.
Another survey of professional developers identified two main pain points:
- 66% of respondents said AI-generated solutions were “almost right”—nearly correct but with details that were off.
- 45.2% said debugging AI-generated code took more time than writing it from scratch.
Together, these pain points create hidden costs. Every “try again” consumes both API usage fees and developer attention.
2. Breaking Down the Real Cost
The total cost of AI-assisted development can be roughly expressed as:
Total cost = cost per call × number of calls+ review and debugging hours × hourly rate+ potential loss from defects reaching production
Many teams focus only on the first item. In practice, the number of calls and debugging hours often account for a larger share, for three reasons:
- In a single task, the model may need to make architectural decisions, write boilerplate code, and fix type errors. Both input and output are long, so the cost per call is naturally high.
- When context is unclear, the model may repeatedly produce similar but incorrect changes, creating a retry loop.
- Without automated verification, problems may surface only during integration, multiplying the cost of fixes.
Therefore, the key to reducing costs is not only switching to cheaper models, but also reducing wasted calls and rework.
3. Core Approach: Separate Planning from Execution
An AI coding workflow can be divided into two layers:
| Dimension | Planning layer | Execution layer |
|---|---|---|
| Primary tasks | Requirement understanding, architecture design, interface definition, risk assessment | Implement functions to specification, add tests, complete repetitive changes |
| Model capability requirements | Deep reasoning and a global view | Stable instruction following, fast response, low cost |
| Call frequency | Low | High |
| Output format | Structured task list and specification | Concrete code changes |
The planning layer uses the most capable models. Its value lies in reducing later directional errors. The execution layer uses cost-effective models for small, clearly bounded tasks. The two layers are connected through structured task specifications rather than relying on a long conversation to carry information.
This division resembles collaboration between architects and developers in an engineering team. The architect defines boundaries and interfaces, while developers implement within the specification.
4. Workflow Design
4.1 Slice Tasks into Verifiable Units
Each task should include four pieces of information: objective, inputs and outputs, files involved, and acceptance criteria. Example:
Task: Add a paginated query by time range to the order moduleInput: start time, end time, page number, page sizeOutput: query function and corresponding unit testsFiles involved: order repository layer, order service layerAcceptance criteria: the time range includes both the start and end dates; an out-of-range page number returns an empty list; all existing tests pass
Task granularity should be judged by whether the task can be independently verified. Requirements that span multiple modules should first be decomposed by the planning layer.
4.2 Context Management Rules
Context quality directly determines output quality. Teams should follow these rules:
- Use a new session for each task to avoid interference from previous conversations.
- Load only files and code snippets relevant to the current task. Do not place the entire repository in context.
- Put project conventions—naming style, directory structure, and error handling—into a fixed instruction file and reference it automatically for each task.
- Preserve complete error messages, including stack traces and version numbers. Do not replace them with a summary.
- If a model’s change does not match the specification, ask it to regenerate rather than patching it line by line.
4.3 Inject External Documentation
A model’s training data may be outdated, and its knowledge of specific library APIs may not be accurate. A retrieval system can inject relevant sections from official documentation, API definitions, and version notes into context. When doing so:
- The documentation version must match the version used by the project dependencies.
- Inject only relevant sections to avoid distracting the model with unrelated content.
- Verify any API the model references by compiling or running the code; do not rely solely on its description.
4.4 Build a Verification Loop
Verification is central to controlling rework. Code produced by the execution layer should pass the following checks in order before entering review:
- Static checks: type checking and code style checks.
- Unit tests: coverage of the acceptance criteria listed in the task specification.
- Integration tests: run in a continuous integration environment, not dependent on a developer’s local environment.
- Human review: focused review of business logic and security-related code.
If a step fails, do not proceed to the next step. Failure information should be passed back to the execution layer unchanged as input for the next round of fixes.
5. Illustrative Workflow
The following pseudo-code shows the basic structure of this workflow:
function run_task(spec):plan = planner.decompose(spec)for subtask in plan.subtasks:context = retrieve_docs(subtask.dependencies)context += load_project_conventions()for attempt in 1..MAX_ATTEMPTS:patch = executor.implement(subtask, context)result = run_checks(patch) // static checks and testsif result.passed:apply(patch)breakcontext += result.errors // pass errors back unchangedelse:escalate_to_human(subtask) // delegate after max attemptsreturn summarize(plan)
Set a maximum number of attempts to prevent retry loops from consuming costs without limit. Once the limit is exceeded, hand the task to a human so that costs do not spiral out of control.
6. Measurement and Calibration
Teams should evaluate results using their own data rather than directly applying general conclusions. Track the following metrics:
- Average number of calls and total spend per task.
- First-pass rate: the percentage of execution-layer outputs that pass checks on the first attempt.
- Rework time: average time from first submission to passing review.
- Defect density: number of defects after release per thousand lines changed.
Review the data every two to four weeks. If the first-pass rate remains low, it usually indicates that tasks are too large or that context rules are insufficient—not necessarily that model capability is the problem. Savings depend on task structure, model pricing, and team habits, so actual data should be the basis for decisions.
7. Implementation Risks and Boundaries
Keep the following points in mind during implementation:
- Core business modules, security-related code, and authorization logic should be designed with human leadership; models should only assist with implementation.
- Code containing sensitive data or secrets should not be placed directly in context. Secrets should be injected through environment variables or a secret management service, not written into code or prompts.
- Write access to the repository for the execution layer should be limited to task branches, and merging must go through review.
- For dependency packages introduced by models, verify their source and license to prevent the introduction of untrusted components.
8. Conclusion
The core of separating planning from execution is to use high-cost reasoning capability for decisions, use low-cost execution capability for clearly bounded implementation, and connect the two with verifiable specifications and automated checks.
