Harness Notes

Forking

Updated 2026-11-22,

On this page

Branching a session into a copy you can take somewhere else, and going back to an earlier point. Subagents that start from your conversation are on the Subagents page.

Worktrees: create, set up, integrate and clean up isolated checkouts

QuestionCodex CLIchecked at 0.162.1
Fork a session

In the TUI, type /fork (or /fork <name> to name the copy) to copy the current chat into a new chat with a fresh ID; the original is left untouched. From the shell, codex fork opens a session picker, codex fork --last forks the most recent session, and codex fork <id-or-name> forks a specific one. /side (alias /btw) opens a throwaway side chat forked from the current one.

codex fork --help says SESSION_ID must be a UUID, but 0.162.1 also accepts a session name, like codex resume.

Fork or rewind from an earlier point

Partly

You can't fork from an earlier turn in the CLI: /fork, codex fork and codex exec fork always copy the whole conversation. You can rewind the current chat instead: press Esc twice with an empty composer, pick an earlier prompt with Left/Right, and press Enter. Codex drops that prompt and everything after it from the saved history and puts the prompt back in the composer to edit.

The docs say Esc-Esc forks the chat from that point. Since 0.156.0 it rewinds the same chat in place, so the later turns are gone from that chat. To keep them, /fork first.

Rewinding only works on sessions in the newer paginated history format. Older sessions can be converted with codex migrate-rollouts --apply.

The app-server thread/fork request can fork at a turn (lastTurnId, or experimental beforeTurnId), but the CLI doesn't expose this.

What the fork keeps

A fork copies the full conversation and keeps the current model, reasoning effort, permissions profile, working directory and any active goal. It doesn't keep the session name. You can rename it with /fork <name> or /rename. codex fork accepts the usual overrides, such as -m, -s, -a, -c key=value, -C <dir>, --add-dir and -p, to change these for the new chat.

A /side chat inherits history only as reference. It is told not to make edits or use subagents, and it can't be renamed.

0.166.0: resume and fork take the approval policy, reviewer and permission profile from the source thread's own most recent accepted settings update, not from a possibly stale turn record. An unnamed permission profile is restored only when the update can be attributed to that thread. Explicit sandbox or permission overrides on the request still win.

File changes and worktrees

Partly

Forks don't snapshot or rewind files. By default a fork shares the same working directory. In a Git repo, /fork asks Where should the forked conversation run?, and you can pick Create new Git worktree. codex fork <id> --worktree and codex exec fork <id> --worktree do the same thing. Esc-Esc rewinds only the conversation and never your files.

The managed worktree is a detached checkout of the current HEAD commit, so uncommitted changes are not copied into it.

--worktree needs an explicit session ID and local execution. It can't be combined with --last, the picker, --ephemeral or resume.

Where a fork came from

Partly

When a fork opens, Codex prints Thread forked from <parent name> (<id>), and /status shows a Forked from line. To switch between the parent and the fork, use /resume, codex resume <id-or-name>, or the codex agents command center. There is no branch tree view.

Fork from the SDK or API

In headless mode, codex exec fork <id-or-name> [PROMPT] copies a saved session. Add --json for JSONL events, --ephemeral to keep the fork unsaved (this needs a prompt), or --worktree. With no prompt, the fork is created without starting a turn. The app-server thread/fork request and the Python SDK codex.thread_fork(thread_id, ephemeral=..., model=..., sandbox=...) also fork. thread/fork adds lastTurnId/beforeTurnId to fork from an earlier turn.

0.165.0 App Server thread/fork accepts experimental attachToSource. The fork is saved as an attached thread of its source, hidden from ordinary thread/list results (list them with experimental attachedToThreadId), does not send thread/started, and blocks deleting the source while it exists. It needs a paginated source and local thread storage, and cannot be combined with ephemeral or deferGoalContinuation.

Notes and sources

Codex CLI, 24 sources
Fork a session, 3
Fork or rewind from an earlier point, 5
What the fork keeps, 7
File changes and worktrees, 4
Where a fork came from, 3
Fork from the SDK or API, 10