AI Diff Merge
Review, edit, and merge AI-generated code — without it ever touching your source file until you say so.
AI models like Claude, ChatGPT, and Gemini often produce code that's almost right — missing context, wrong variable names, inconsistent formatting. AI Diff Merge gives you a side-by-side, fully editable diff to scrub AI output clean before it lands in your codebase, plus a way to hand your own edits back to the AI so it knows exactly what you changed.
Requirements
- VS Code 1.100+
- Node.js-based extension host (desktop VS Code — not required for the Compare/Merge flow in a browser workspace, but Human Edit Diff needs local filesystem access)
Install
Search "AI Diff Merge" in the Extensions view (Ctrl+Shift+X), or install from the VS Code Marketplace.
Keyboard Shortcuts
| Shortcut (Win/Linux) |
Shortcut (macOS) |
Command |
What it does |
Ctrl+Alt+C |
Cmd+Alt+C |
AI Diff: Compare with Clipboard |
Opens an editable diff: your code vs. clipboard |
Ctrl+Alt+D |
Cmd+Alt+D |
AI Diff: Human Edit Diff |
Generates a patch: clipboard vs. your current code |
| — |
— |
AI Diff: Apply Changes to Original |
Merges the diff's right side into your file |
All three are also available from the Command Palette (F1 or Ctrl+Shift+P).
🚀 Core Features
1. Two-Way Editable Diff
Unlike VS Code's built-in "Compare with Clipboard," which treats the clipboard as read-only, AI Diff Merge treats it as a first-class editable buffer. Fix the AI's suggestions to match your codebase before anything is merged.
2. Selection Intelligence
- Snippet Mode: Select code first → the extension diffs the clipboard against just that selection.
- Full File Mode: No selection → it compares against the entire file.
This applies to both Compare with Clipboard and Human Edit Diff, so you're never stuck reviewing a whole-file diff when you only care about one function.
3. Human Edit Diff — tell the AI what you changed
The reverse workflow: after you've merged AI code and hand-edited a few lines yourself, run Ctrl+Alt+D to generate a git-style unified diff between what's still on your clipboard (the AI's original suggestion) and your current file or selection.
- Produces proper diff hunks (
@@ -12,3 +12,4 @@ style) with surrounding context, not just a flat list of changed lines.
- The patch is copied straight to your clipboard — paste it back into your AI chat so it knows exactly what you changed and why.
- It's also saved to a real temp file on disk (
alert-toast-new-<timestamp>.diff), so AI coding agents that read the filesystem (like Claude Code) can pick it up directly.
- Nothing is persisted after that — it's a one-shot comparison of "what's on my clipboard right now" vs. "what's in my editor right now," so it works independently of whether you ever ran
Compare with Clipboard first.
4. In-Memory File System for the Diff View (ai-diff://)
The Compare with Clipboard diff view runs entirely in RAM via a custom FileSystemProvider:
- No temp files for the diff view itself — editing the right-hand side and hitting
Ctrl+S saves to an in-memory buffer, never triggers an OS "Save As" dialog, and leaves nothing on disk.
- Buffers are automatically cleared once you merge, and also cleaned up if you just close the diff tab without merging.
Note: this in-memory guarantee applies to the Compare/Merge diff view only. Human Edit Diff intentionally writes one real file to your OS temp directory, by design, so external tools can read it.
5. Direct Language Propagation
The diff buffer automatically inherits the language ID and file extension of your active editor, so IntelliSense, syntax highlighting, and linting all work immediately on the AI-generated code.
6. Atomic Workspace Merging
Apply Changes to Original performs a single WorkspaceEdit to replace your source with the refined code — safe, undo-able, and it auto-saves the target file.
🛠 How to Use
Workflow A: Review AI code before it touches your file
- Capture — Copy a code snippet from your AI chat.
- Compare — Focus the file to update, press
Ctrl+Alt+C.
- Scrub — A diff editor opens: your code on the left, the AI's code (editable) on the right. Fix anything you don't like directly in the right pane.
- Merge — Click the checkmark (
✓) in the editor title bar, or run AI Diff: Apply Changes to Original. Your file is updated and the diff buffers are cleared.
Workflow B: Tell the AI what you changed afterward
- Make sure the AI's original suggestion is still on your clipboard.
- Make your manual edits to the file (in one place or several).
- Focus the file (select a region first if you only want that part diffed).
- Press
Ctrl+Alt+D.
- The unified diff is now on your clipboard and saved as a
.diff file in your temp folder — paste or point your AI at either one.
Troubleshooting
| Situation |
What happens |
| Clipboard is empty |
Both commands show an error and do nothing to your file |
| No differences between clipboard and editor |
Human Edit Diff shows an error instead of writing an empty patch |
| No formatter installed for the language |
The diff still opens; auto-formatting is skipped silently |
Apply Changes run outside a tracked diff tab |
Shows a warning — nothing is merged |
📸 Visual Guide
1. The Trigger
Highlight a function and press Ctrl+Alt+C to initiate a targeted comparison. The extension detects your selection automatically.
2. The Scrubber View
The right side is fully editable — fix AI errors here with full IntelliSense support. Note the ai-diff:// scheme in the tab title.
3. The Atomic Merge
Click "Apply" to replace your original code with the refined version.
⚠️ Screenshot paths above are placeholders (username/ai-diff-merge) — swap in real asset URLs before publishing, or the images will 404 on the Marketplace.
🏗 Technical Notes
For contributors and the curious:
- Diff view filesystem: custom
MemoryFileSystemProvider implementing vscode.FileSystemProvider — in-memory only, cleaned up on merge or tab close.
- Patch generation: unified diffs (Human Edit Diff) are built with the
diff package.
- Merging: uses
vscode.WorkspaceEdit for a single atomic, undo-able edit — cost scales with edit size, not O(1).
- Formatting: invokes
vscode.executeFormatDocumentProvider against whatever formatter is installed for the language; no formatter installed means no formatting, not an error.
- Reliability: Built with Node.js 22+ features and strict TypeScript configuration (
erasableSyntaxOnly).
AI Diff Merge — Build faster with AI, but review every line before it's yours.