Script to apply browser AI code edits to local files when IDE tokens run out

When you run out of AI tokens in your coding editor (IDE), this lets you use a AI instead and automatically apply its suggested code changes to your . You paste the AI's output into the terminal, and the script finds the right files and writes the edits for you. It uses difflib, a built-in Python comparison tool, to tolerate minor mistakes the AI makes — like wrong indentation or extra blank lines — and still apply the edit correctly.

It can also track down the target file even if the AI forgot part of the file path. Before writing anything to disk, it shows you a preview of the exact changes and a so you can catch errors. Setup is simple: save patcher.py in a scripts folder, add a shell function to your .bashrc or .zshrc, and it is ready to use from any terminal.

The author warns this is a quick personal tool, not a polished product, so caution is advised.

Key points

  • Bridges the gap between browser AI and when IDE tokens are exhausted
  • Uses difflib to tolerate AI indentation and blank-line mistakes
  • Tracks down files even when the AI omits part of the path
  • Shows a preview and before any file is modified
  • Setup: save patcher.py, add a shell function to .bashrc/.zshrc
Read original