AI Patch Apply
Apply AI code changes from your chat to your workspace. Copy an AI reply (ChatGPT, Claude, Gemini — any chat) containing structured BEFORE / AFTER code blocks, paste it in with one shortcut, and review every edit in VS Code's native diff view before accepting it.
Usage
- Copy the entire AI response to the clipboard.
- Press
Ctrl+Alt+V (Cmd+Alt+V on macOS).
- VS Code opens a native diff tab per file.
- Step through the diffs:
Ctrl+Alt+W (Cmd+Alt+W) accepts the current diff tab and moves to the next one.
- Made a mistake?
Ctrl+Alt+Z (Cmd+Alt+Z) undoes the last applied patch.
Want to touch up the AI's code first? The right side of every diff is editable — your edits become what gets applied when you accept (or Apply Pending). The left side shows the current file and stays read-only.
The AI Patch view in the Activity Bar (left sidebar) shows the files waiting in the diff tabs — click one to reopen its diff — plus quick access to every command. Its icon carries a badge with the number of pending files.
If some edits could not be applied, the extension builds a failure report — the exact reason, a diagnostic hint, and the current file content. Copy it back into the chat (AI Patch: Copy Failed Report) and the AI can retry against up-to-date code.
Re-running the same clipboard is harmless: edits whose AFTER is already in the file are skipped as already applied.
Troubleshooting
Everything the extension does is logged to the output channel: View → Output → AI Patch (match strategy used per block, rejects with reasons, timing). When something applies unexpectedly — check there first, and attach the relevant lines to a bug report.
The extension expects a strict response format. Run the AI Patch: Copy Prompt command and paste the copied prompt into any AI chat — the AI will then answer with BEFORE/AFTER blocks the extension can parse.
**Location:** File: `path/to/file.py` | Function: `func_name`
**BEFORE:**
```python
old code
```
**AFTER:**
```python
new code
```
The Function: part is optional. Two operational markers are supported:
Function: (new file)`` — creates the file; fails if it already exists.
- `Function:
(delete file) — deletes the file.
Commands
| Command |
Keybinding |
| AI Patch: Apply from Clipboard |
Ctrl+Alt+V |
| AI Patch: Accept Current Diff and Go to Next |
Ctrl+Alt+W |
| AI Patch: Undo Last Patch |
Ctrl+Alt+Z |
| AI Patch: Redo Last Patch |
Ctrl+Alt+Y |
| AI Patch: Apply Pending |
— |
| AI Patch: Cancel Pending |
— |
| AI Patch: Copy Failed Report |
— |
| AI Patch: Clear Failed Report |
— |
| AI Patch: Copy Prompt |
— |
| AI Patch: Show Patch History |
— |
Undo/redo works per patch (up to 10 steps back), and a review interrupted by a window reload is restored: the pending diff tabs re-open on startup.
Every apply attempt is journaled locally. Failed edits are kept with truncated BEFORE/AFTER fragments and the closest matching block from the file — enough to see why the AI's edit failed; whole file contents are never stored. By default only problem entries are kept (aiPatch.patchHistory: failuresOnly); set it to all for success statistics (the exact-vs-fuzzy match ratio) or off to disable the journal entirely. Open AI Patch: Show Patch History to see totals, the most frequent failure reasons and how often the AI's code blocks had to be matched fuzzily — useful for telling "the AI got the format wrong" from "the extension mis-matched".
Settings
| Setting |
Default |
Meaning |
aiPatch.afterMaxBytes |
20000 |
Largest accepted AFTER block, in characters. |
aiPatch.fuzzyMatch |
true |
Ignore tabs vs spaces and trailing whitespace when matching BEFORE. |
aiPatch.pinDiffTabs |
true |
Pin diff tabs so they do not replace each other. |
aiPatch.focusFirstDiff |
true |
Focus the first diff tab after preview. |
aiPatch.failureThreshold |
0.4 |
Share of failed changes in a file that rejects the whole file (needs ≥2 failures). |
aiPatch.patchHistory |
failuresOnly |
What the patch history journal stores: failuresOnly, all, or off. |
Languages
The extension UI follows VS Code's display language and falls back to English when no translation exists. Translations ship for: English, Russian, German, Spanish, French, Simplified Chinese, Japanese, Brazilian Portuguese.
Build & install locally
npm install
npm run compile
npx @vscode/vsce package
code --install-extension ai-patch-apply-<version>.vsix
Then run Developer: Reload Window — the new version works in every project of your main VS Code.
Development
Open the folder in VS Code and press F5. A second window ("Extension Development Host") opens — test the command there.
Run the unit tests with npm test. After changing UI strings, run npm run check-l10n to make sure every locale bundle is in sync. To run the live smoke test (real VS Code, 37 checks): node scripts/verify-live.js — the same test runs in CI on every push.
Bug reports and contributions are welcome — see CONTRIBUTING.md for the setup and the few rules the codebase lives by. Found a problem? Open an issue (there is a template; a clipboard sample makes it fixable in minutes).