|
| 1 | +# Workspaces |
| 2 | + |
| 3 | +Currently, cmux supports one Workspace backend: [git worktrees](https://git-scm.com/docs/git-worktree). |
| 4 | + |
| 5 | +We plan on adding support for SSH and Docker backends in the near future for |
| 6 | +additional isolation and security. |
| 7 | + |
| 8 | +## Basics of worktrees |
| 9 | + |
| 10 | +A worktree is a seperate directory on the same filesystem as the main repository that shares a `.git` |
| 11 | +but has independent working changes and checkout state. **All committed changes from any worktree are |
| 12 | +visible to all other worktrees including the main repository.** |
| 13 | + |
| 14 | +It's important to note that a **worktree is not locked to a branch**. The agent can switch to new |
| 15 | +branches, enter a detached HEAD state, etc. When you create a workspace, the agent will |
| 16 | +begin at the selected branch but may switch freely in the course of the session. **We empower users to define their agent's branching strategy in AGENTS.md** |
| 17 | + |
| 18 | +## Reviewing code |
| 19 | + |
| 20 | +Here are a few practical approaches to reviewing changes from workspaces, |
| 21 | +depending on how much you want your agent to interact with `git`: |
| 22 | + |
| 23 | +- **Agent codes, commits, and pushes**: Ask agent to submit a PR and review changes in your git Web UI (GitHub, GitLab, etc.) |
| 24 | + - Also see: [Agentic Git Identity](./agentic-git-identity.md) |
| 25 | + - This is the preferred approach for `cmux` development but requires additional care with repository security. |
| 26 | +- **Agent codes and commits**: Review changes from the main repository via `git diff <workspace-branch>`, push changes when deemed acceptable. |
| 27 | +- **Agent codes**: enter worktree (click Terminal icon in workspace top bar), run `git add -p` and progressively accept changes into a commit. |
| 28 | + |
| 29 | +## Reviewing functionality |
| 30 | + |
| 31 | +Some changes (esp. UI ones) require the Human to determine acceptability. An effective approach |
| 32 | +for this is: |
| 33 | + |
| 34 | +1. Ask agent to commit WIP when its ready for Human review |
| 35 | +1. Human, in main repository, checks out the workspace branch in a detached HEAD state: `git checkout --detach <workspace-branch>` |
| 36 | + |
| 37 | +Note: this workflow uses the detached HEAD state because the branch is already |
| 38 | +checked out in the workspace and you cannot check out the same branch multiple times |
| 39 | +across worktrees. |
| 40 | + |
| 41 | +If you want faster iteration in between commits, you can hop into the worktree directory and run a |
| 42 | +dev server (e.g. `bun dev`) there directly and observe the agent's work in real-time. |
| 43 | + |
| 44 | +## Filesystem Layout |
| 45 | + |
| 46 | +All worktrees are stored in `~/.cmux/src/<project-name>/<workspace-name>`. |
| 47 | + |
| 48 | +Example layout: |
| 49 | + |
| 50 | +``` |
| 51 | +~/.cmux/src/ |
| 52 | + cmux-main/ |
| 53 | + improved-auth-ux/ |
| 54 | + fix-ci-flakes/ |
| 55 | +``` |
0 commit comments