Ask for the Patch, Not the Whole File

Often cuts output tokens 40-70% on edits to large files, varies by file size Beginner 1 min read

The single most wasteful habit in chat-based coding is letting the model echo back a 600-line file just to change three lines. Output tokens are billed at a higher rate than input tokens on every major API (typically 3-5x), so a full-file rewrite is the most expensive way to make a small change.

Before

Here's my auth.py (580 lines pasted). Add rate limiting to the login function.

The model returns all 580 lines with the change buried inside. You pay output tokens for 577 lines you already had, then you have to diff it by eye to find what actually changed.

After

Here's my auth.py (580 lines). Add rate limiting to login. Reply with ONLY a unified diff, or just the changed function — do not reprint the whole file.

The model returns ~15 lines: the modified function plus a one-line note on where it goes.

Why it works

The model generates every output token sequentially, and you are billed for all of them. Reprinting unchanged code is pure waste — the file already exists on your disk. By constraining the response to a diff or a single function, you collapse the output from hundreds of lines to a handful.

This also reduces your downstream cost: a tight diff is easier to review, so you spend fewer follow-up turns asking "what did you change?" Each of those clarifying turns re-sends the whole conversation as input.

Phrases that reliably trigger compact output:

  • "unified diff only"
  • "just the changed lines with 2 lines of context"
  • "return only the function you modified"

The one caveat: for brand-new files or near-total rewrites, a full file is correct and a diff is noise. Use this for surgical edits, which are the common case.

Applies to: ChatGPTClaudeGeminiCopilot ChatCursorAPIs
Don't just read it — build the habit

Get a fresh tip every morning

You're reading a free Beginner tip. Pro unlocks all 38 advanced tactics and sends a new one daily — $9/mo, cancel anytime.