|
| 1 | +--- |
| 2 | +title: "Workspaces" |
| 3 | +description: "Create isolated git worktrees (sandboxes) from within a project" |
| 4 | +--- |
| 5 | + |
| 6 | +In OpenCode, a **workspace** is an isolated **git worktree** attached to a project. |
| 7 | + |
| 8 | +- The project’s main worktree is the **local** workspace. |
| 9 | +- Additional worktrees are **sandbox** workspaces (extra directories tracked on the project). |
| 10 | + |
| 11 | +Each workspace has its own git branch and directory, so you can experiment without disturbing your main working tree. |
| 12 | + |
| 13 | +## Create a workspace from within a project |
| 14 | + |
| 15 | +<Steps> |
| 16 | +<Step title="Open the project">Open the project in the OpenCode TUI so it appears in the sidebar.</Step> |
| 17 | + |
| 18 | +<Step title="Create a new workspace">In the project’s **Workspaces** section, choose **New workspace**.</Step> |
| 19 | + |
| 20 | +<Step title="Wait for boot">OpenCode creates the underlying git worktree, populates it, then starts it.</Step> |
| 21 | + |
| 22 | +<Step title="Use it">Select the new workspace to start new sessions inside its isolated directory.</Step> |
| 23 | +</Steps> |
| 24 | + |
| 25 | +## What OpenCode does under the hood |
| 26 | + |
| 27 | +When a new workspace is created, OpenCode: |
| 28 | + |
| 29 | +- Creates a git branch using the `opencode/<generated-name>` naming scheme. |
| 30 | +- Adds a git worktree directory under OpenCode’s data directory (scoped to the project id). |
| 31 | +- Runs a hard reset/population step so the new worktree has the repo contents. |
| 32 | +- Bootstraps the worktree, then runs startup scripts. |
| 33 | + |
| 34 | +Startup scripts run in this order: |
| 35 | + |
| 36 | +1. **Project startup**: the project’s `commands.start` (if configured). |
| 37 | +2. **Worktree startup**: an optional extra startup command for the new worktree (primarily used when creating worktrees programmatically). |
| 38 | + |
| 39 | +## Manage workspaces |
| 40 | + |
| 41 | +From the workspace sidebar menu you can typically: |
| 42 | + |
| 43 | +- **Rename** the workspace label. |
| 44 | +- **Reset** the workspace branch back to the project’s default. |
| 45 | +- **Delete** the workspace (removes the worktree and its branch). |
0 commit comments