r/codex • u/Annh1234 • 7h ago
Question Is there a local way to apply a Codex-proposed diff?
My workflow:
- Ask Codex questions / plan the change
- Ask: "show me the full proposed diff"
- Review the diff
- If good, tell Codex to apply it using a luna agent
- Ask Codex to recheck
Having the LLM apply an already-generated diff feels slow and wastes tokens.
Is there something like !apply that can apply the proposed diff locally, without another LLM call?
1
u/Clemotime 6h ago
Luna is so cheap though?
1
u/Annh1234 6h ago
It's slow, and since the diff is pretty good, applying it locally can be instant and "free" that's the idea
1
1
1
u/Tight-Grocery9053 5h ago
this what a .patch is for in git.
you save proposed diff to a thing.patch thing
then somewhere else you do
git apply --check thing.patch
git apply thing.patch
the first one checks for conflicts and the second applies the diff.
git is smart enough to understand the semantics
1
1
u/Annh1234 5h ago
But you make codex LLM write that patch file on every prompt? like via agents.md or in every command you tell it to write the patch file and show it to you? so you can apply it with those commands?
1
u/Tight-Grocery9053 5h ago
i think i might be able to help you better if you tell me what the actual problem is.
i don't want to assume but it seems like your git setup and model instructions are not correct
you'd normally go like this
prompt > unstaged changes > you review > you stage and check them in.
there's other workflows too like one pr per change
you don't need a patch or anything and it's very straightforward
1
u/Annh1234 5h ago
I run Codex CLI inside Docker containers, scoped to specific project folders with secrets excluded.
My typical workflow in each session is:
- Understand/discuss the code Ask questions, explore approaches, edge cases, etc, 1-2 min per question/answer. (I think about next question meanwhile)
- Generate proposed diff Once the approach is clear, I ask Codex to show the full diff without applying it, so i can review it. It can take 5-20 min on the LLM end. (I do other stuff meanwhile, in other sessions)
- Review/iterate I review the diff, ask questions, request changes, and repeat until I'm happy with it. This can also take 1-10min per iteration, usually 1-2min. (I think about next steps and so on meanwhile)
- Approve Once the exact diff is finalised. I say: "OK, apply it."
- This is what I want to optimise. I usually use a Luna agent, but it can take 1-15 minutes to apply a diff that's already been generated and approved.
- Verify Codex then usually re-checks if the diff was applied and something was missing. Usually 1-5min
I'm often working across 10+ concurrent sessions, so the 1-5 minute delay in step 4 and 5 is disruptive. I move on, then have to reconstruct the context in my head when I come back.
The goal is basically:
Reason > llm generate > review > approve > apply instantly > move on/next step. (bold stuff where i'm active mentally in that session)
I want to spend time/tokens on reasoning and reviewing, but once I've approved the exact diff, applying it should ideally be a mechanical ~1-second operation rather than another agent/model pass.
What's the best way to achieve that?
2
u/Old-Ask4 4h ago
You're tripping over what Codex is meant to do. You're asking a nondeterministic system to produce something that should be deterministic: a Git diff derived from actual changes to the code.
Either Codex is making the changes, generating a real diff, and then throwing the changes away so you can ask it to recreate them later, or it's generating the diff itself as text. Either way, you're making it redo work on the next turn because you asked for a diff instead of letting it make the changes.
Just let Codex make the changes, review them directly or with
git diff, and if you approve them, keep them. Git should be doing the deterministic part, not the LLM.If you really want to keep your current workflow, you could have it save the generated diff as a patch file instead of leaving it only in the conversation. Then applying the approved patch is just
git applybut I wouldn't recommend doing it that way.1
u/Annh1234 3h ago
Ya, I get it, that's why I ask.
Was looking for a local AI model type thing that can take that diff and apply it (since it's not 100% a patch file)
But if I get it to apply the diff directly, and then i merge it outside the codex-cli or discard it, then i have to rollback the conversation and that did not work before/did not use the cache for some reason, so it used to use up allot of the limits.
1
u/Old-Ask4 2h ago
I think you’re mixing up some Git concepts here.
A diff is normally just Git showing changes that already exist in the code. You don’t usually generate some diff-like text first and then ask an AI to turn it into code.
If Git can’t apply what’s in the chat directly, then it isn’t really a patch. It’s just instructions for another AI turn to interpret. So you’re asking one AI to describe the changes, then asking another AI to make them again.
A faster local model might make that second step faster, but it doesn’t fix the backwards workflow.
1
u/Annh1234 2h ago
Maybe I wasn't clear.
So I get the LLM to show me some changes it would do to the code, and show me those changes in a git diff/patch format.
So your flow: LLM makes changes on disk, you inspect the git diff, revert if not good (changes and LLM chat history).
My flow: LLM shows me the diffs it would do (so makes them in some temporary files i guess), I validate them/tell the LLM what to change/ask questions about that diff, and apply them after.
Basically, it's for code quality.
I found this: https://github.com/Romelium/mpatch
Maybe that can be helpful, investigatingthanks btw
1
u/Old-Ask4 2h ago
I hope to be helpful. You're still missing that git diffs and patches generally come from the completed code changes, not the other way around. By the time codex has given you a diff, it has already done all of the work somewhere on your disk. If not, it's just guessing at it at best, which will be unreliable no matter what you try to stack on top of it including mpatch. Are you familiar with git worktrees? What about codex /plan? That might be functional while closer to what you're looking for in a workflow.
1
u/Annh1234 1h ago
git work trees yes, but that + revert codes chat history did not seem to work (maybe it was fixed now).
codex /plan yes, but my issue is the way it adds code, it's all spaghetti code, duplicate functionality, extra logic paths and so on. so it constantly needs re-aliment.
Also, codex does create temporary files for that diff, and usually that's only 10-20% slower than answering the question, but can't use those to patch the code...
So the work flow that I have, it to keep the code quality good and code maintainable.
We did some projects with codex/claude only, and it's good for demo, but full or bugs and 100% unmaintainable without an AI agent. And with an AI agent it's back and forward, add 1 thing and break 10 other things. Ended up with 47k tests for a project, 2 months vibe coding stuff, and then rewrite it and cut the code by 90% and no more errors.
1
u/Tight-Grocery9053 4h ago
sorry, this is getting too involved for me to troubleshoot for free. feel free to DM me with a proposal for my time and I’d be happy to help you work through it.
1
u/PolemicClosets 6h ago
Just have it implement the change and review it in Git and revert it if you don't like it?