Aident AI

Codex Esc-Esc Backtrack Failed? Preserve the Prompt
If Codex CLI 0.147.0 shows Failed to branch before the selected prompt: the selected prompt was not found in the persisted thread, stop before submitting the restored text. Copy that text somewhere safe, leave the original chat intact, and use the supported /fork, codex fork, or /new path instead. Do not edit the session JSONL or keep testing on the only copy of a useful thread.
This guide covers one narrow regression: pressing Esc twice, selecting an earlier prompt, and receiving the persisted-thread error instead of a new branch. It does not claim that every Codex fork or resume failure has the same cause.
Confirm the Exact Failure
The August 7 report reproduces the problem with these steps:
Start or resume a Codex CLI chat with several completed user prompts.
Leave the composer empty.
Press Esc twice to open the transcript and backtrack overlay.
Select an earlier prompt and press Enter.
Observe the error instead of a branch.
The selected prompt is restored to the composer even though Codex says it cannot find that prompt in the persisted thread. A second reporter also reproduced the failure after cancelling a running turn, then selecting the aborted prompt. In that case, submitting the edited text appended it to the original rollout instead of creating a fork.
That distinction matters. The prompt text may still be recoverable even when the requested branch was not created.
If your message instead mentions an active writer, use the separate Codex active-writer recovery guide. If chats disappeared after an update, follow the missing Codex chats guide.
Step 1: Copy the Restored Prompt Before You Submit
When the selected prompt appears in the composer, copy it to a temporary local note before pressing Enter again. Include only the prompt you intended to change, not the full transcript.
Do not submit the restored prompt in the original chat as a branch test. The corroborating report observed that doing so continued the original rollout. Also avoid these destructive responses:
Do not delete, rename, or rewrite a session JSONL.
Do not clear the chat or remove the Codex data directory.
Do not run repeated Esc-Esc tests against the only copy of an important session.
Do not upload a full transcript or
codex doctor --jsonoutput without reviewing private paths and prompt content.
The immediate success condition is simple: you have the prompt text, and the original saved chat still appears in Codex.
Step 2: Choose Full Context or a Clean Branch
Codex documents two supported ways to continue without mutating the original transcript.
Preserve the current transcript with /fork
After copying the restored prompt, clear the composer without submitting it. Then, in the original chat, run:
Codex should clone the current chat into a new chat with a fresh ID while leaving the original transcript untouched. Paste the saved prompt into the new fork and state that it replaces the earlier instruction.
This is safe containment, not identical backtracking. The fork contains the full current transcript, including turns after the prompt you wanted to change.
If the original chat is no longer open, exit to your shell and run:
Choose the affected saved session in the picker. If it is the most recent chat in the current working directory, codex fork --last skips the picker. Prefer the picker when you are not certain which session is most recent.
Start clean with /new
If later turns would contaminate the alternate path, run:
Paste the saved prompt, then add only the minimum context needed to continue. This loses inherited transcript context but keeps the original chat unchanged.
Use this decision table:
Goal | Supported path | Tradeoff |
|---|---|---|
Keep the complete current context |
| Later turns remain in the fork |
Fork a saved chat from the shell |
| You must select the correct session |
Start without later transcript state |
| You must restate necessary context |
Continue the original chat unchanged |
| No alternate branch is created |
Step 3: Verify That the Original Stayed Intact
Before doing more work in the alternate chat, verify three things:
The new chat has a different session identity.
The original chat remains available through
/resumeorcodex resume.The saved prompt appears in only the place you intentionally submitted it.
Do not compare raw session files unless a maintainer asks for that evidence. The supported picker is enough to prove that the original and alternate chats both exist.
If the original chat vanishes, stop. Do not create more forks or rewrite local state. Record codex --version, the operating system, terminal, working directory, and the last successful action, then preserve the Codex data directory before further investigation.
Step 4: Update and Test on a Throwaway Chat
The primary report remains open, so treat the supported fork path as containment rather than an upstream repair. Check your installed version:
If an update is available, install it once and test with a disposable chat containing three short prompts. Repeat the Esc-Esc flow there. A useful production thread should not be the canary.
The regression is confirmed only when the exact sequence creates a new chat before the selected prompt and leaves the original transcript unchanged. A restored composer alone is not proof that a branch exists.
If the error persists, report:
exact Codex CLI version;
operating system and terminal;
whether the selected turn was completed or aborted;
whether the prompt was restored to the composer;
whether submitting it appended to the original chat;
whether
/forkorcodex forkstill worked;a minimal throwaway reproduction.
Share only the smallest relevant diagnostic excerpt. The source report intentionally withheld its full doctor output because it contained unrelated local session paths.
Why the Safe Workaround Works
Esc-Esc backtracking asks Codex to find one selected prompt in persisted history and branch immediately before it. The reported 0.147.0 failure shows the transcript overlay and branch lookup disagreeing about that prompt.
/fork and codex fork use the documented whole-session fork path instead. They preserve the original transcript and create a new chat identity. /new avoids persisted-history branching entirely.
Neither path fixes the failed lookup. They reduce the risk while the regression is unresolved:
the selected text is copied before another submission;
the original chat is not rewritten;
the alternate work receives its own chat identity;
verification happens before more turns accumulate.
Reusable Recovery Prompt
After creating the safe fork or new chat, use this bounded instruction:
Treat the prompt below as a replacement for my earlier instruction. First summarize the minimum assumptions you inherited from this chat. Then follow the replacement prompt. Do not edit or delete saved sessions, inspect session JSONL files, or continue work from the superseded instruction.
Success is measurable: the original chat remains resumable, the alternate chat has a different identity, the intended prompt is preserved, and no session file was manually changed.
To check whether the upstream report has changed, start with Aident Loadout:
Follow https://aident.ai/SETUP.md
Then ask:
Check Aident Loadout authentication and Vault status. Discover the current read-only GitHub issue Action, inspect its schema, and preflight a lookup for openai/codex issue 37421. If the lookup is valid and free, execute it and return only state, updated time, comment count, reactions, labels, title, and canonical URL. Do not comment, react, edit, close, or create anything.
Set up Aident Loadout and monitor the backtrack regression.
Sources
Refresh this guide when issue 37421 changes state, a Codex release names the repair, the Esc-Esc backtrack contract changes, or the supported fork and resume commands change.



The one tool
for every tool
your agent needs.
Give any AI agent real capabilities in seconds. Connect 1,000+ tools once, skip the setup headache, and let your agents execute.
