Spots

How to fork a Claude Code or Codex session to try another approach

The agent has a plan, and it's halfway through. You want to see what the other approach looks like, the one you talked it out of an hour ago. If you ask in the same session, you pollute the context it has built up. If you start a new session, you lose that context.

A fork gives you both. It copies the

A fork gives you both. It copies the conversation so far into a new session, and the original stays exactly where it was: Claude Code, inside a session: /branch. You're moved into the copy, and the original can be resumed later. Claude Code, from the shell: claude --resume <session-id> --fork-session. Codex, inside a session: /fork. From the shell: codex fork <session-id>, or codex fork --last.

The catch: a fork copies the conversation, not

The catch: a fork copies the conversation, not your files. Two sessions editing the same checkout will step on each other. Give the fork its own git worktree. When should I fork instead of just continuing? Fork when you want to keep the current thread intact:

Trying a different approach. The fork explores the

Trying a different approach. The fork explores the alternative. If it doesn't work out, the original session still has the plan it was following, untouched.

Comparing two approaches. Fork, then let each session

Comparing two approaches. Fork, then let each session build its version in its own worktree. Compare the diffs, not the arguments.

Asking a side question. A tangent that isn't

Asking a side question. A tangent that isn't worth keeping in the main context: how some library works, or a quick review of one file.

If you just want to undo the last

If you just want to undo the last few steps, you don't need a fork. Claude Code's /rewind (also /checkpoint) restores the conversation, the code, or both to an earlier message. How do I fork a Claude Code session? Inside a running session, type:

Claude Code copies the conversation into a new

Claude Code copies the conversation into a new session and switches you into it. The name is optional. The fork's title ends in "(Branch)", so it's easy to tell apart in /resume. The confirmation message includes the command to get back to the original, claude -r <original-session-id>. From the shell, add --fork-session to a resume: Without --fork-session, both commands reopen the original session and keep adding to it. How do I fork a Codex session? Inside a running session, type /fork. From the shell:

Like codex resume, the picker and --last only

Like codex resume, the picker and --last only look at sessions from the current directory. Add --all to see every directory.

Codex has two more ways to branch. Press

Codex has two more ways to branch. Press Esc twice to step back through your earlier prompts, pick one, and press Enter. Codex forks the conversation just before that prompt and puts the prompt back in the composer for you to edit. The original session keeps the full history. For a quick tangent, /side starts a side conversation in a temporary fork. Does forking a session copy my code?

News

How to fork a Claude Code or Codex session to try another approach

The agent has a plan, and it's halfway through.

@spots #dev
Source: Dev.to
See more like this