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

  1. Check what changed with git diff or git status. This shows the uncommitted edits the agent made since your last commit.
  2. If the changes are uncommitted and you want to discard them entirely, use git checkout -- . to restore all files to the last commit, or git checkout -- path/to/file for a specific file.
  3. If the changes were committed, use git revert <commit-hash> to create a new commit that undoes them. Do not use git reset --hard on commits you have shared with others.
  4. If you committed in stages and only the last commit is wrong, git revert HEAD undoes just that commit safely.
  5. 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.
How fenbs helps

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 account

Free 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

  1. Create a free account and add a project for the codebase you are working on with Codex CLI.
  2. Before each session, read the task context in fenbs: the current task, its plan, and the last progress note.
  3. 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.
  4. 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.
  5. 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.

Questions people ask.

Can Codex CLI save and reload a session?

Codex CLI does not have a built-in session save and reload feature. Check OpenAI's current documentation for any session export or continuation options that may have been added. As a workaround, save the relevant context to a file or an external record before closing the session.

What if Codex CLI made changes I did not ask for?

Check the diff with git diff before accepting any commit. If unwanted changes are there, use git checkout -- . to discard them and start the turn again with a clearer instruction.

Is there a way to undo a Codex CLI action without using git?

Not reliably. The CLI writes to files on your filesystem and those writes are not reversible except through git or a manual edit. Running Codex CLI in a repository with clean commits is the practical safeguard.

Can I run Codex CLI in a sandboxed environment for safety?

Yes. Running Codex CLI in a container, a virtual machine, or a git branch with nothing committed gives you a contained environment where a mistake is easier to recover from. The codex-cli-sandbox post covers sandboxing options.

More in Agent harness (for developers)

All Agent harness (for developers) articles

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.