Working inside Cursor / Claude Code / Aider / Copilot

Cursor: the diff envelope

4 min read

When you're prompting an LLM inside an IDE — Cursor, Zed, IntelliJ AI Assistant, JetBrains AI — the model isn't free to chat. It needs to produce output the IDE can parse and apply directly to your buffer. The right output shape is a unified diff wrapped in a code block.

This module's flow:

Cursor's user-message → diff round-trip:

A short system prompt + a focused user request gets you there. Here's the system prompt that makes the model behave like an IDE-native pair:

You are an expert pair programmer working inside an IDE. The user shows you code; you respond with a unified diff (--- / +++ / hunk markers) only — no prose unless explicitly asked. Always preserve unrelated lines exactly.

Now the user message is just the file and the change request:

File: src/utils/email.ts

export function isValidEmail(s: string): boolean {
  return s.includes("@") && s.includes(".");
}

Task: tighten the validation. Reject leading/trailing whitespace, require at least one char before "@", require a dot AFTER "@", and a TLD of at least 2 letters. Keep the same signature.

Claude Sonnet 4.5 returned:

--- src/utils/email.ts
+++ src/utils/email.ts
@@ -1,3 +1,11 @@
 export function isValidEmail(s: string): boolean {
-  return s.includes("@") && s.includes(".");
+  if (s !== s.trim()) return false;
+  
+  const atIndex = s.indexOf("@");
+  if (atIndex <= 0) return false;
+  
+  const domain = s.slice(atIndex + 1);
+  const lastDotIndex = domain.lastIndexOf(".");
+  if (lastDotIndex === -1) return false;
+  
+  return domain.slice(lastDotIndex + 1).length >= 2;
 }

Captured from Claude Sonnet 4.5 (claude-sonnet-4-5) on 2026-04-27. Re-runs may differ slightly.

This output is paste-ready. The IDE can apply it directly. There's no prose to strip, no explanation to ignore, no alternative implementations.

The system prompt is doing four things at once:

PhraseEffect
"expert pair programmer"Sets the persona toward concise senior-engineer voice
"working inside an IDE"Frames the output for tool consumption
"unified diff only"Locks the output format
"preserve unrelated lines exactly"Stops the model from sneaking in formatting changes

That last constraint matters more than it looks. Without it, the model often "improves" indentation, changes single quotes to double quotes, or adds a missing trailing newline. Each of those creates noise in the diff and in the eventual git history. The constraint forces the diff to contain only your intended change.

A useful extension: ask the model to also add the test in the same diff:

Task: tighten the validation as described, AND add a unit test in src/utils/email.test.ts covering the new rules. Both changes in the same diff.

The diff envelope handles multi-file changes naturally — each file gets its own --- / +++ pair. The IDE applies all hunks together, and you get an atomic change.

When the diff comes back wrong, the fix is rarely "rerun with a better prompt." It's usually "show me what you tried, and apply the patch I describe." Cursor, Zed, and similar tools let you do this through their chat surface. The conversation pattern: model proposes diff → you apply mentally → you correct one specific line → model rewrites the diff. Three turns, one merged change.

The four IDE-style envelopes you'll meet across this module, side by side:

IDE-style prompt envelopes

Diff

Cursor / Zed

Input shapeFile + task in chat
Output shapeUnified diff (---/+++)
Apply stepIDE patches buffer
Strong atInline edits, multi-file hunks
Pros
  • Atomic multi-file change
  • Reviewable hunk by hunk
Cons
  • Line-number drift breaks stale diffs
  • Tempts model to re-format unrelated lines
SEARCH/REPLACE

Aider

Input shapeRepo context + task
Output shape&#x3C;&#x3C;&#x3C; SEARCH / === / REPLACE >>>
Apply stepAider matches exact text
Strong atLong sessions, line-shift safety
Pros
  • Survives surrounding edits
  • Apply fails loudly on misread
Cons
  • One block per logical edit or rollback gets ugly
  • Verbose for tiny one-line changes
Plan + execute

Claude Code

Input shapeConversational task + repo
Output shapePlan → tool calls → diff
Apply stepAgent edits + runs tests
Strong atMulti-step features, invariants
Pros
  • Plan-then-go gate prevents scope creep
  • Agent self-checks invariants
Cons
  • Long context required
  • Failure mode is silent file edits without 'go'
Completion

Copilot / Tabnine

Input shapeFile above cursor
Output shapeInline completion
Apply stepTab to accept
Strong atFunction bodies given good signature
Pros
  • Zero-friction in flow
  • Improves with comments above cursor
Cons
  • No control surface beyond the file
  • Generic if function name is vague

Next up: the SEARCH/REPLACE block format used by Aider. :::

Quiz

Module 5: IDE & Tool Prompts

Take Quiz
Was this lesson helpful?

Sign in to rate

FREE WEEKLY NEWSLETTER

Stay on the Nerd Track

One email per week — courses, deep dives, tools, and AI experiments.

No spam. Unsubscribe anytime.