How to Run Parallel Agents in OpenCode and Zed
Both tools run several agents at once. Give each agent its own Git worktree so two agents never edit the same files, then review and merge each branch on its own.
Goal
Run two or more coding agents on one repository at the same time, in OpenCode or in Zed, without the agents overwriting each other's work.
Prerequisites
- A Git repository with at least one commit on the branch you start from
- OpenCode v2 or a current Zed release. OpenCode was at v2.4.5 on December 4, 2026.
- One dependency install per worktree, if the project needs one
The Rule: One Agent per Worktree
An agent session is a conversation. A Git worktree is a directory. Several sessions in one directory still write to the same files and the same index, so their edits interleave. Parallel agents stay separate only when each one works in its own worktree, on its own branch. Parallel Coding Agents Without Branch Chaos explains why in more detail.
OpenCode: Parallel Sessions
Each OpenCode session has its own history and its own directory. Start one session per task, each in a new worktree.
Desktop app. Start a new session and select New worktree. Click the base branch in the composer, such as from dev ▾, to pick another base.
Terminal UI. Press Ctrl+O to open recent sessions and projects. Press Right on a project to list its worktrees, then Ctrl+N to create one, and open a session in it.
Sessions open in tabs, which are on by default. Ctrl+Tab and Ctrl+Shift+Tab move between them, and Ctrl+X then L lists every session. You can also create worktrees with Git and open each one in its own terminal:
git worktree add -b agent/search ../repo-search main
git worktree add -b agent/billing ../repo-billing main
opencode ../repo-search # terminal 1
opencode ../repo-billing # terminal 2
OpenCode treats every worktree of a repository as one project, so both sessions show up under it. Set worktree.directory in opencode.json to choose where OpenCode creates worktrees. OpenCode worktrees covers that setting.
OpenCode: Background Subagents
Inside one session, the agent can hand work to subagents. Each subagent runs in its own child session with a fresh context. Since v2.3.0, released November 13, 2026, subagents return immediately and keep running in the background. Several can run at once, and the parent gets a report each time one goes idle.
Subagents share the parent session's directory. Use them for parallel research or for edits to separate files. Give tasks that touch the same files to separate sessions in separate worktrees instead.
Zed: Parallel Threads
Zed runs each agent in a thread. Every thread has its own agent, context window and history, and the Threads Sidebar lists them all by project.
- Open the Threads Sidebar with
cmd-alt-jon macOS orctrl-alt-jon Linux and Windows. Panel Layout > Agentic in the title bar user menu moves the Agent Panel and the sidebar to the left. - Before each thread that edits code, open the worktree picker in the title bar, or run
git: worktree, and create a linked worktree. - Use the branch picker to create a branch. New worktrees start in detached
HEAD. - Click
+on the project's header in the sidebar to start a thread. - Press
ctrl-tabto cycle through recent threads.
Each thread can use a different agent. Zed's own agent can run next to external agents such as Claude Code or Codex, and Terminal Threads run any command-line agent in a terminal. Threads in linked worktrees appear under the main project. Zed worktrees shows how to copy .env into each new worktree with a create_worktree task hook.
When you archive a thread, Zed saves its worktree's Git state and removes the worktree from disk, unless another active thread uses it. Restoring the thread from Thread History, cmd-g or ctrl-g, brings the worktree back. You cannot archive a thread while it runs.
Review and Merge
When an agent finishes, review its diff in its worktree, run the tests there, and push its branch:
git -C ../repo-search status
git -C ../repo-search diff main
git -C ../repo-search push -u origin agent/search
Open one pull request per branch. If two agents changed the same lines, Fix Merge Conflicts Created by Coding Agents covers the rebase.
With Treq
Treq gives each task its own workspace, a separate working copy and branch under .treq/workspaces/. Treq does not start OpenCode as an agent. Open a terminal session in a workspace and run opencode there. Each workspace is an ordinary directory, so you can also open it in Zed.
Sources
Checked December 5, 2026: