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

Questionpichecked at 1.2.0
Fork a session

Yes, three ways. /clone copies the current branch into a new session, /fork makes a new session starting just before an earlier user message you pick, and /tree branches inside the same session file. From the shell, pi --fork <path|id> copies an existing session into a new session for the current folder before interactive mode starts.

/fork and /tree have keybinding actions (app.session.fork, app.session.tree) that are unbound by default. Pressing Escape twice on an empty editor opens /tree by default; set doubleEscapeAction to "fork" or "none" to change that.

1.5.2 adds missing-folder recovery: interactive startup, /resume and session switching offer Continue, Fork or Cancel when the stored cwd is gone. Continue uses the current folder without rewriting the source; Fork copies the full session into a new ID/header with the current cwd and parentSession pointing to the source. Non-interactive startup still errors unless an explicit fork is selected. The interactive switch removes a fork if an extension cancels the switch. Source inspection at v1.5.2; no runtime probe.

Fork or rewind from an earlier point

Yes. /fork lists your earlier user messages and starts a new session just before the one you pick, putting its text back in the editor so you can edit and resend it. /tree lets you jump to any earlier entry in the same session; picking a user message refills the editor, and the branch you leave stays saved. When you leave a branch, Pi can ask whether to summarize it into the branch you move to.

Set branchSummary.skipPrompt to true to skip the summary question and never summarize.

What the fork keeps

/fork and /clone copy only the active branch up to the chosen point (with its labels, compactions and any model or thinking-level changes) into a new file in the same session folder, and keep the session's working directory. Pi then reloads the session, so the model and thinking level come back from the copied history, and --model or --thinking flags you started Pi with apply again. pi --fork copies every entry, including other branches, and moves the copy into the current folder. Pi has no permission prompts to carry over.

File changes and worktrees

Not supported

No. Forking, cloning and moving around /tree only change the conversation; files on disk stay as they are, and Pi has no checkpoints or worktrees. The repository ships an example extension, examples/extensions/git-checkpoint.ts, that saves a git stash create snapshot each turn and offers to apply it when you /fork.

Where a fork came from

A session made by /fork, /clone or --fork stores the source file path in parentSession on its first line. The /resume picker's Threaded sort (switch sorts with Ctrl+S) nests forks under the session they came from. Inside one session, /tree shows every branch, and you can label entries with Shift+L and filter the view.

Fork from the SDK or API

Yes. In the SDK, AgentSessionRuntime.fork(entryId, { position: "before" | "at" }) forks or clones, SessionManager.forkFrom() copies a whole session file, and SessionManager.branch() and createBranchedSession() work on the tree directly. RPC mode has fork, clone, get_fork_messages and get_tree commands, and pi --fork <id> -p "..." forks for a one-off headless run.

Extensions can cancel or react to a fork through the session_before_fork event, and fork themselves with ctx.fork(entryId, { position }).

Notes and sources

pi, 20 sources
Fork a session, 8
Fork or rewind from an earlier point, 4
What the fork keeps, 4
File changes and worktrees, 2
Where a fork came from, 3
Fork from the SDK or API, 5