Patch or Pay

Aider's own docs describe four edit formats a coding agent can use to hand back a fix, and the format a model gets sets what each edit costs. They are whole (return the entire file), diff and diff-fenced (search/replace blocks), and udiff (unified-diff style). The diff formats are roughly 20x cheaper in tokens, for one reason: less capable models can't be trusted to produce them, so Aider silently defaults those models to the expensive whole format for every edit, forever. That eligibility cliff, not the occasional bad retry, is the number most coding-agent cost audits never measure. This post builds the illustrative math, shows where Aider already routes around it with its architect/editor split, and ships a verified-escalation pattern that checks whether a patch actually applies before ever paying for a stronger model.

Published 2026-09-13 by Dor Amir on the Nadir blog.

Filed under Agents.

Abstract.

Aider, the open-source AI pair-programming tool, ships four different ways for a model to hand back a code edit: whole (return the entire file), diff (search/replace blocks for just the changed lines), diff-fenced (the same thing with the file path moved inside the fence, added specifically because Gemini models kept breaking the plain version), and udiff (a modified unified-diff format built for GPT-4 Turbo, because that model family kept getting "lazy" and skipping code it was supposed to keep). Source: Aider, "Edit formats". The diff-style formats are dramatically cheaper: the model only has to emit the lines that changed, not the file around them. Aider's own documentation is direct about why every model doesn't just use the cheap one: "for less capable models, or models with strange code-editing behaviors, aider defaults to using the whole editing format." A model too unreliable to be trusted with diff doesn't retry more often on the cheap format — it never gets offered the cheap format at all. It pays the whole-format token bill on every single edit, for the rest of the session. That eligibility cliff, not the occasional bad guess, is the number this post is about.

All token counts and cost figures in this post are an illustrative worked example built to show the mechanism, not a benchmark measurement or a proprietary trace. Format descriptions, the whole-format default for less capable models, and the architect/editor split are sourced directly from Aider's own documentation, linked throughout.

Four formats for the same five-line fix.

Say a coding agent needs to change five lines inside a 400-line file. Here is what each format actually asks the model to produce:

Bar chart: token cost for the same 5-line edit in a 400-line file across four Aider edit formats — whole (~3,200 tokens), udiff (~190), diff-fenced (~160), diff (~150). Illustrative worked example, not a benchmark measurement.
Bar chart: token cost for the same 5-line edit in a 400-line file across four Aider edit formats — whole (~3,200 tokens), udiff (~190), diff-fenced (~160), diff (~150). Illustrative worked example, not a benchmark measurement.

Roughly a 20x gap between the cheapest and most expensive way to say the same thing to the same model. That gap is exactly the kind of number a cost-optimization checklist tells you to go collect. The part the checklist usually skips: collecting it requires a model that can be trusted to produce a syntactically exact patch, and not every model can.

The cheap format needs an expensive kind of trust.

A diff block only works if the search half matches the file byte-for-byte. Miss a line, get the whitespace wrong, paraphrase a comment instead of copying it verbatim, and the patch does not apply. whole has no such failure mode — there is nothing to match, the model just overwrites the file with what it returned. That is precisely why Aider's docs describe whole as the fallback for "less capable models, or models with strange code-editing behaviors": it is the format that cannot be gotten wrong, at the cost of being the format that is never cheap.

This is a second, separate axis from the one most routing advice already covers. Model-tier routing asks "is this model smart enough to solve the task." Format eligibility asks a narrower, more mechanical question: "can this model's raw output be trusted to apply, verbatim, without a human or a verifier catching the mismatch." A model can clear the first bar and miss the second — plenty of small, fast models reason well enough to propose the right five-line fix and still botch the exact-match formatting required to express it as a diff. Route only on capability and you will hand a fast, cheap model a diff job it cannot format, then pay for the failure anyway.

What a missed patch actually costs.

Aider's benchmark harness gives every attempt a second try: if the model's edit does not apply, or the resulting code fails its hidden tests, aider feeds the error back and asks for a corrected version before scoring the attempt as failed. Source: Aider, "Benchmark notes". That second attempt is a second full round trip — the original context plus the failure message, generated again — and it is the mechanism most homegrown coding-agent harnesses reach for by default because it is the simplest thing that could work.

It is also the smaller of the two costs on the table. Model B below occasionally fails to apply on the first try and pays for a reflection round; Model C is unreliable enough with diff that it is not attempting diff at all, and pays the full whole-format token count on one hundred percent of its edits, not just the ones that would have failed.

Bar chart comparing illustrative effective cost per edit for three models: Model A on diff format with ~98% first-try apply (~160 tokens), Model B on diff format with ~70% first-try apply and a reflection retry (~195 tokens), and Model C too unreliable for diff and permanently defaulted to whole format (~3,200 tokens, every edit). The jump from B to C is losing the format entirely, not the retry rate.
Bar chart comparing illustrative effective cost per edit for three models: Model A on diff format with ~98% first-try apply (~160 tokens), Model B on diff format with ~70% first-try apply and a reflection retry (~195 tokens), and Model C too unreliable for diff and permanently defaulted to whole format (~3,200 tokens, every edit). The jump from B to C is losing the format entirely, not the retry rate.

Going from Model A to Model B costs about 22% more per edit — a real number, worth measuring, not worth panicking over. Going from Model B to Model C costs roughly 16x more per edit, and that gap has nothing to do with how often the model gets the answer right. It is a formatting eligibility problem wearing a reasoning-quality costume. Judge these three models by accuracy alone and Model C might not even look like the worst one; judge them by what a coding agent actually bills per edit, and the format it is allowed to use is doing most of the work.

Aider already routes this. Most agent harnesses don't.

In September 2024, Aider shipped exactly the fix this implies, months before "routing" was a term most teams applied to their own coding agents: the architect/editor split. Source: Aider, "Separating code reasoning and editing," September 26, 2024. An architect model reasons about the problem and describes the fix however comes naturally to it, in prose, with no formatting constraints. A second, editor model takes that description and turns it into a syntactically exact set of edits — and, per Aider's own docs, "the architect and editor can use two different models." The reasoning step and the formatting step are decoupled on purpose, because they are different skills with different failure modes, and pinning both to one model means one of the two jobs is always being done by a model that wasn't picked for it.

That is a routing cascade wearing a code-editing name tag. This blog has already argued that a verified escalation, not a blind retry, is what makes a cascade worth its cost; Aider's own two-attempt benchmark loop is a verifier by construction — the check is "did the patch apply, did the tests pass" — it just is not wired to escalate to a different, more format-reliable model when the check fails, only to re-ask the same one. Most agent frameworks built after Aider skipped the format-eligibility half of this lesson entirely: they inherited the idea of retrying on a bad tool call, and dropped the idea of treating "can this model be trusted to produce an exact patch" as its own measured, per-model, per-format signal.

What to check this week.

A minimal version: try the cheap model's diff, verify it actually applies before trusting it, escalate only on a real failure.

import subprocess
import tempfile
import openai

client = openai.OpenAI(
    base_url="https://api.getnadir.com/v1",
    api_key="ndr_...",
)

def propose_edit(prompt, model):
    response = client.chat.completions.create(
        model=model,
        messages=[{"role": "user", "content": prompt}],
    )
    return response.choices[0].message.content

def patch_applies(diff_text, repo_path):
    with tempfile.NamedTemporaryFile(mode="w", suffix=".diff") as f:
        f.write(diff_text)
        f.flush()
        result = subprocess.run(
            ["git", "apply", "--check", f.name],
            cwd=repo_path,
            capture_output=True,
        )
        return result.returncode == 0

def edit_with_verified_escalation(prompt, repo_path):
    # Cheap and fast first — "auto" lets Nadir route to whichever model
    # clears the accuracy bar for this prompt at the lowest cost.
    diff = propose_edit(prompt, model="auto")
    if patch_applies(diff, repo_path):
        return diff, "auto", 1

    # The check failed locally, no second model call spent finding that out.
    # Escalate to a model picked for format reliability, not just capability.
    diff = propose_edit(prompt, model="claude-opus-4-8")
    return diff, "claude-opus-4-8", 2

Same call shape as talking to any OpenAI-compatible endpoint. The git apply --check call is free — it costs no tokens and no extra request — so the escalation only fires when the cheap attempt actually failed, not on a fixed retry schedule. Nadir reports the routing decision and the model actually used per request, so which of the two branches above fired, and how often, becomes a number on your dashboard instead of a guess.

Related reading


Sources: [Aider, "Edit formats"](https://aider.chat/docs/more/edit-formats.html). [Aider, "Separating code reasoning and editing," September 26, 2024](https://aider.chat/2024/09/26/architect.html). [Aider, "Benchmark notes"](https://aider.chat/docs/leaderboards/notes.html). [Aider, "Code editing leaderboard"](https://aider.chat/docs/leaderboards/edit.html).

More on agents

What Nadir is

Nadir is an LLM router. Nadir sends each prompt to the cheapest model that can handle it. A small decision model reads each prompt against your model menu and picks the lowest-cost model it expects to handle it. When the decision model is uncertain or unavailable, the request goes to the strongest model on the menu. The routing step makes no call to your model provider.

Nadir runs two ways. The decision API returns a model, reasoning-effort, cache, context, and policy recommendation without calling a model provider, beside the gateway you already run. That is how a shadow-mode evaluation works, and its projected savings stay advisory. The OpenAI compatible managed proxy executes the route, and migration is a two-line change: point the base URL at api.getnadir.com and set model to auto. On that path an optional verifier can score a complete non-streaming answer and escalate to a stronger model when it misses the configured bar. Streaming bypasses post-generation verification. BYOK is supported on every tier.

For coding agents, Nadir Auto is a terminal launcher for Claude Code or Codex that asks Nadir for the main-session model before each turn, with your configured model as the fallback and cost ceiling. Delegation integrations for Claude Code, Codex, or Cursor instead recommend a model tier for subagent work, and the agent decides; the Claude plugin can also move a main-thread turn to Haiku when Nadir's cache check prices it cheaper, unless its switch_main_model option is off. Either way inference runs on your own provider account, so Nadir holds no provider keys on that path.

What the numbers are, and what they are not

Nadir publishes each evaluation with its scope. On checkable code, run-check-escalate solved 392 of 395 common HumanEval and MBPP problems (99.2%), graded by running the canonical tests; that applies only to tasks with runnable deterministic tests. Nadir-Tumbler posts an arena_score of 72.3 on RouterArena's public scorer, 5th of 23 routers, which measures the routing decision on RouterArena's own model pool. A reference-assisted RouterBench evaluation over 11,420 held-out triples produced a 60% lower projected cost than always-Opus with about 98% retained quality and a 1.7% catastrophic-route rate. That experiment gave the verifier the expensive-model reference answer, which production does not have, so it is a research ceiling and not the deployed path.

None of these is a production guarantee, a universal savings rate, or a forecast for any particular workload. Customer savings are reported from measured execution against a declared baseline, and customer quality only from outcome-labelled traffic. Projected savings and realized savings are separate artifacts and are never blended.

Design-partner program

Three rungs, picked by risk appetite. Rung 0 Shadow runs advisory decision calls alongside live traffic and returns a projected receipt, with nothing in the request path changed. Rung 1 Hosted is the two-line swap on a production slice and returns a realized receipt. Rung 2 On-prem is a supervised six-week proof of concept inside the partner's VPC, where no prompt, response, or usage reaches Nadir. The commitments are the same at every rung. Apply for a rung directly: Rung 0 Shadow, Rung 1 Hosted, or Rung 2 On-prem. Not sure which fits? Start at getnadir.com/contact/?reason=design-partner.

Licensing

NadirClaw is the self-hosted core, source-available under the PolyForm Noncommercial License. Source-available is the correct label; NadirClaw is not open source. Nadir Route's hosted plan has no base fee and charges a variable fee only on measured savings from requests Nadir executed.

Pages on this site

Machine-readable summaries of this site: llms.txt and llms-full.txt.