Promptabide Logo

Ask For The Diff, Not The File

Requesting a whole rewritten file is how silent regressions get into your codebase.

prompt-engineering
code-review
developer-workflow
Keywords:
diff prompt
code generation
unified diff
ai code review
I lost an afternoon to this and I would like nobody else to.

I asked for a fix to one function in a 300-line file. I got back the whole file, fix included, plus three lines of unrelated "tidying" that quietly changed a default from false to true. It reviewed clean, because I was reading for the fix rather than for everything else.

The prompt that stopped it happening:

`
Return your change as a unified diff against the file I gave you.
Use 3 lines of context. Do not include unchanged hunks.
If a change requires touching more than the function I named, stop and
tell me why instead of making it.
`

What each line buys you:

Unified diff - you review the change, not the file. A three-line fix is three lines on screen.

3 lines of context - enough to apply the patch by hand, not so much that the diff becomes the file again.

No unchanged hunks - stops the "here is the diff" preamble that is then followed by the whole file anyway.

Stop and tell me why - this is the important one. It converts scope creep from a silent edit into a visible question. Roughly one time in five it comes back with a genuinely good reason the fix cannot be local, and that is a conversation worth having before the code exists rather than after.

Caveat: models are noticeably worse at producing applyable diffs than at producing correct code. Line numbers in the hunk headers are often off by one or two. Do not pipe the output straight into git apply - read it, then make the edit yourself. The point is the review surface, not the automation.
31.8k16

Generated Outputs (1)

1 weeks ago
Claude
claude-opus-4
Generated Output
`diff
@@ -142,7 +142,11 @@ export async function resolveSession(req: Request) {
const token = req.cookies.session
if (!token) return null

  • • const payload = verify(token, SECRET)

  • + let payload: SessionPayload
    + try {
    + payload = verify(token, SECRET)
    + } catch {
    + return null
    + }

    return loadUser(payload.sub)
    `

    One note before you apply this: loadUser can still throw if the user row was deleted while the cookie is live. That is outside the function you named, so I have not touched it - but it is the same class of bug and you probably want it in the same pass.
    Comments (16)
    No comments yet. Be the first to share your thoughts!
    Top Contributors
    Loading...
    Follow PromptAbide

    New bides, prompt breakdowns and community picks, on whichever feed you already read.

    Trending Tags
    Loading...
    Ask For The Diff, Not The File | PromptAbide