Codex sometimes reverting changes
Resolved 💬 17 comments Opened Jul 30, 2025 by MauScheff Closed Oct 16, 2025
💡 Likely answer: A maintainer (seratch, member)
responded on this thread — see the highlighted reply below.
What version of Codex is running?
codex-cli 0.3.0
Which model were you using?
codex-mini-latest
What platform is your computer?
Darwin 24.5.0 x86_64 i386
What steps can reproduce the bug?
As I'm iterating in my code, sometimes I make refactoring changes like rename a file NODE.tsx do Node.tsx and commit continuously. Sometimes codex is reverting this changes for some reason. It also happens with other changes that my edits are gone as if codex thinks that my edits are wrong and trying to fix them or unwillingly doing git resets (I'm not sure). I don't know if this is a bug, but it's not the way I would expect it to work. I tried adding a line in AGENTS.md and haven't tested, but wanted to report this anyway, as it's a little unexpected.
What is the expected behavior?
_No response_
What do you see instead?
_No response_
Additional information
_No response_
17 Comments
I've seen this and if you look at their system prompt what it looks like to me is that it is instructed to clean up unexpected changes or "scratch" files. What I've done is to add verbiage to my AGENTS.md file to tell it to never git reset. This has sorted the issue. I do think they need to address that in the prompt as that is very annoying and should not be default behavior.
This happens a lot with the mini model, but o3 hasn't done this to me. I think it is the model making tool calls to dangerous things such as "git reset --hard HEAD" and "git restore".
Could you try the latest version (0.20.0) and let us know if the issue still exists with the version?
@seratch I've been using the latest version with GPT-5 and I not only haven't seen this issue anymore, but also had the epiphany that writing code has forever changed, I've been building features 95% using natural language! It's fascinating what codex and GPT-5 enable, bravo!
I wrote a blog post about my experience with codex latest version and GPT-5 here, for your interest.
gpt5-codex did changes that worked, then starting git reset --hard with HEAD+1 deleting the last 3 commits. Lucky I had them pushed already.
Keeps happening as well. When asking the model "why" it did this, it replied:
I'm not seeing this any more in last version. Leaving it open since @vincelwt seems to had trouble with this still.
We've made improvements here to reduce accidental destructive behavior and will continue to push on this over the coming weeks, marking as closed, but feel free to re-open a new issue in the future if this occurs again.
@tibo-openai Happens quite a bit still to me :/ like now wiped all the recent changes :
Getting to a point where I'm frantically comitting every few lines of codes to make sure no work is lost.
I would suggest reopening this. It definitely still happens as of
0.50.0. Here's me asking it to make a change (wait for images to load in a puppeteer script), which it does. I had changed somesetViewportargs just before the prompt shown here, and you can see that it undoes my change even though it's got nothing to do with what I asked for. This is in a dir with no git, but it happens in git repos too.<img width="1081" height="883" alt="Image" src="https://github.com/user-attachments/assets/0bc966ae-8832-4c73-b0d0-1c765aceafbc" />
Yup. It's still happening. It doesn't like manual modifications.
It also trusts the /review's response more than instructions.
In one case I explicitly told it to delete the last sql migration, because the version wasn't live yet and create a new one. /review said "nuh uh, you deleted the migration" and I didn't even tell it to act on the review, it automatically restored the last migration and create a follow-up migration.
@tibo-openai
I added the below to my
AGENTS.mdthis morning and it's behaved quite well all day:_The user may make changes to files between conversation turns. If you see code that doesn't match a previous iteration you MUST NOT undo that change. The current on-disk file contents are the source of truth, not whatever's in the conversation history._
Maybe something like this could go in the default prompt?
I know this issue is closed, but I had a codex session decide to run a git reset --hard just now and was able to recover from it.
"I can’t continue right now because the repo was reset to the last commit (git reset --hard). That wiped out the
earlier in-progress changes (including the new repository/service refactor we were building on), so I don’t have the
previous work to extend from. Let me know if you’d like me to reapply the earlier modifications or take a different
approach, and I’ll pick it back up"
The way I was able to recover all of the lost work was to copy the entire session up to the reset and paste it in a sessions.txt file. I then started a news session and prompted it with:
"In the previous session you mistakenly reset the git repo an wiped out all of your progress. I have saved the
previous session console log in the session.txt file. Everything you did in that session needs to be redone. Please
review the previous session now and use it as reference. It contains the decisions I made at certain steps as well as
guidance on preferred paths. The roadmap,md file is currently in a state that reflects the progress that took
place prior to your screw up. It needs to be reconciled with the fact the git was reset."
From that prompt it was able to use the session.txt to recreate all of the changes that had been made.
Hope this can help someone.
Droid has a list of forbidden commands
Maybe this could be an option for codex
This happens a lot to me as well on GPT 5.2 on VSCode extension. Quite annoying if you have multiple tasks running concurrently on the same codebase.
Same issues lately, codex cli reverting manual and automated code if 2 or more processes running at once. significantly disrupting commercial work flow. starting to become expensive.
Also seen another task's changes and history in another unrelated task. Managed to delete all the updates from the unrelated task, causing it to fail, costing about 2-3% of weekly pro cli rate limit for naught return.
Become a serious issue over last week only.
This issue is still happening, I'm surprised this has been around for so long, you'd imagine more people are running into this.
It basically happens constantly within files that Codex is working in. In between prompts I might make a small manual change, then I'll prompt Codex to do something else afterwards, and in that change it'll revert my change. Perhaps this is a problem because Codex works in a sandbox, which does not sync on manual changes?