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

QuestionOpenCodechecked at 2.0.29
Fork a session

Yes. In the TUI run /fork (or bind session.fork) and pick "Full session" or a prompt; from the command line use opencode run --fork or opencode mini --fork together with --continue or --session <id>.

In 2.0.28 the full-screen opencode command has no --fork flag (1.x had one); use /fork after opening the session, or opencode mini --fork.

Fork or rewind from an earlier point

Yes. /fork lists earlier prompts, and choosing one copies the history before that prompt into a new session and pre-fills the prompt; a message's action menu also has Fork. To rewind in place, /undo (<leader>u) or a message's Revert stages a rollback that becomes final when you submit, and /redo (<leader>r) cancels it.

What the fork keeps

The fork copies finished history (assistant turns still running are skipped), the session's agent, model, permission rules, metadata, and current instruction state, and opens in the original session's directory and workspace. It gets the title <original> (fork #1) and starts with zero cost and token counts.

2.2.2 keeps media in forked and imported sessions. A fork stores copied media as blobs when the parent location has experimental.media_blob on, inline otherwise; an import turns only the inline media it carries into blobs, based on the destination's config. A /goal is stored per session, so forks and child sessions start without one.

File changes and worktrees

Partly

No. The fork shares the same working directory. Files are rewound only by /undo and Revert, which restore paths from OpenCode's snapshot store (needs a Git repository; turn off with "snapshots": false). For isolation, ask the agent to call worktree_create and session_move, or use /worktrees to move the session to another workspace.

Where a fork came from

Partly

Each fork records its source session and boundary in the fork field (sessionID, boundary) returned by the session API, but the TUI does not show it. Forks are top-level sessions, so you switch between them with /sessions (<leader>l).

Fork from the SDK or API

Yes. POST /api/session/{sessionID}/fork takes an optional before message ID (omit it to copy everything). opencode run --continue --fork and opencode run --session <id> --fork fork headlessly, and opencode acp advertises and handles ACP session/fork.

To change the model or agent, pass --model or --agent to the opencode run --fork call that sends the next prompt; the fork endpoint itself accepts no overrides.

Notes and sources

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