Codex CLI: Go Back to a Previous Message or Task State
Codex CLI does not have a command to replay a previous message. Here is what "going back" actually means in a terminal coding agent, how to undo file changes, and how to preserve checkpoints so you always have a safe state to return to.
Updated 4 min read
Codex CLI does not have a "go back" command that replays or restores a previous message in a conversation. Once a turn is complete and file changes are written, you cannot rewind the session to the state it was in two instructions ago. What you can do is undo the file changes and restart from a known state — and the tools for that are git, not the CLI itself.
Tools like fenbs keep checkpoints, decisions, and the next confirmed step outside the CLI session. When a session goes wrong and you need to restart, you know exactly where to return to rather than reconstructing that from memory.
What "going back" actually means in a CLI agent
There are two things people usually want when they ask to go back: replay the conversation from an earlier point, or undo the changes the agent made to the code. These are different problems with different solutions.
Replaying a conversation is not possible without a conversation export or a saved session log. The CLI does not store sessions you can reopen and continue from a mid-point. If you need to resume exactly where you left off, save the relevant context before closing a session.
Undoing code changes is a git operation, not a CLI operation. If the agent made changes you want to reverse, you reverse them with git checkout, git revert, or git reset — the same tools you would use for any unwanted change in a codebase.
How to undo file changes Codex CLI made
- Check what changed with
git difforgit status. This shows the uncommitted edits the agent made since your last commit. - If the changes are uncommitted and you want to discard them entirely, use
git checkout -- .to restore all files to the last commit, orgit checkout -- path/to/filefor a specific file. - If the changes were committed, use
git revert <commit-hash>to create a new commit that undoes them. Do not usegit reset --hardon commits you have shared with others. - If you committed in stages and only the last commit is wrong,
git revert HEADundoes just that commit safely. - Before starting any substantial agent session, make a commit first. An empty "checkpoint" commit gives you a clean anchor to return to.
How to navigate conversation history
Codex CLI keeps a conversation history within a session that you can scroll through in the terminal. You can read what was said earlier in the same session and copy relevant context into a new message. You cannot instruct the agent to "go back to message 4 and continue from there."
If you need to start over with a slightly different instruction, begin a new session and include the corrected context. Being explicit is faster than trying to guide the agent back through earlier reasoning: "Ignore the previous approach; do this instead" works better than a partial undo.
The checkpoint habit that prevents most "go back" needs
Most requests to go back come from a session that ran further than expected before a problem appeared. The fix is checkpoints: commit at each confirmed milestone so that any subsequent problem can be cleanly reversed.
- Commit before asking the agent to start a new sub-task, even if it is a small change.
- Commit after any change you have verified works. A passing test is a good commit point.
- Write a useful commit message. "Before adding authentication" is a checkpoint you can find later; "wip" is not.
- Before a session where the agent will make many changes, make a branch. You can always merge, discard, or cherry-pick from it.
Keep decisions and the safe next step outside the session
When a session goes wrong and you restart, the question is not just what was the last git commit but what was the agreed next step and what decisions led to it. fenbs keeps those records outside any CLI session. Before restarting, read Where we left off in the relevant task. After the restart, save progress again so the record stays current.
Create a free accountFree for one person · No credit card · Works with Claude, ChatGPT, Cursor and more
How to pick up mid-task after restarting a session
After reverting the code changes and starting a fresh session, the most common mistake is giving the agent the same instruction you gave the first time. If the first session produced something wrong, the same instruction is likely to produce the same wrong result.
Before restarting, identify what specifically went wrong: did the agent misunderstand the scope? Did it make a correct change in the wrong place? Did it go further than it should have? The answer changes the instruction for the new session.
Start the new session with the corrected scope explicitly stated. Include what the previous session did that you do not want repeated. If the task has prerequisite context — a decision, a constraint, a pattern to follow — include that too. A fresh session has no memory of the previous one; everything it needs to start correctly has to be in the new prompt.
How to do this with fenbs
- Create a free account and add a project for the codebase you are working on with Codex CLI.
- Before each session, read the task context in fenbs: the current task, its plan, and the last progress note.
- After each confirmed step, save progress: what was done, what was checked, and what comes next. This is the checkpoint for the next session, not just for you but for any tool that reads the same record.
- When a session goes wrong, revert the code changes with git, then check fenbs for the last confirmed state. Start the new session from the task context rather than reconstructing it from memory.
- Connect Codex CLI to fenbs at /integrations to have it read and save context directly.
For related Codex CLI operations, see the codex cli commands and codex cli best practices posts.