Inspiration
AI coding agents like Codex are brilliant, but they share a wasteful habit: rewriting entire files just to change a single line. That's slow, burns tokens, and — worse — it's dangerous when two agents touch the same file at the same time. Whoever writes last silently overwrites the other's work. There's no way to know if the file changed underneath you.
What it does
PatchCode is a lightweight, open-source CLI that gives AI agents surgical, hash-verified file editing:
- Read:
hashline readreturns only the lines you ask for, tagged with a content hash — a fingerprint of that exact version of the file. - Patch:
hashline patchapplies a targeted edit (swap, delete, insert) — but only if the hash still matches. If another agent already changed the file, the patch is automatically rejected. No silent overwrites, no corrupted edits, no guessing. - Result: agents patch just the lines that changed instead of rewriting the whole file — roughly 99% fewer tokens per edit, with a real safety guarantee baked in.
How we built it
The core concept is adapted from Oh My Pi (MIT License) — full credit to the original approach of line-numbered anchors + content-hash tags for surgical edits.
We built and debugged the entire CLI live inside OpenAI Codex using GPT-5.6. When the tool broke with a relative-path error (running it from a different working directory), Codex diagnosed the bug instantly and shipped the fix — swapping a relative path for an absolute one — in the same session.
Challenges we ran into
- Getting the hash-matching logic airtight so a stale edit is always rejected, never silently applied — this is the whole safety guarantee of the tool, so it had to be bulletproof.
- Reproducing a real multi-agent race condition (two agents editing the same file concurrently) to prove the protocol actually holds up under pressure, not just in theory.
What we learned
Small, surgical changes to how AI agents interact with files can eliminate an entire class of silent-corruption bugs — and save massive amounts of token spend — without needing a heavier, more complex system. Sometimes the fix isn't a bigger model, it's a smarter protocol.
What's next for PatchCode
- Expand language/framework coverage for auto-detecting patch targets
- Publish as an npm package for one-line install into any agent framework
- Add a visual diff view for the live demo so reviewers can watch two agents "race" in real time
Built With
- cli
- gpt-5.6
- hashing
- javascript
- mit
- node.js
- open-source
- openai-codex
Log in or sign up for Devpost to join the conversation.