multiroot-workspace.mdx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ---
  2. title: "Multi-Root Workspaces"
  3. sidebarTitle: "Multi-Root Workspaces"
  4. ---
  5. Cline works with VSCode's multi-root workspaces, letting you manage multiple project folders or repositories in a single window. Whether you're working with a monorepo or separate Git repositories, Cline can read files, write code, and run commands across all of them.
  6. <Frame>
  7. <video
  8. src="https://storage.googleapis.com/cline_public_images/multiworkspace.mp4"
  9. autoPlay
  10. muted
  11. loop
  12. playsInline
  13. controls
  14. />
  15. </Frame>
  16. <Warning>
  17. Multi-root workspaces have two limitations:
  18. - **Cline rules** only work in the primary workspace folder
  19. - **Checkpoints** are disabled (restored when you return to a single folder)
  20. See [Current Limitations](#current-limitations) for details.
  21. </Warning>
  22. ## Understanding Multi-Root Workspaces
  23. Before diving in, it helps to understand the two common patterns for organizing related projects.
  24. ### Why Use Multi-Root Workspaces?
  25. Cline can complete tasks that span multiple projects or repositories:
  26. - **Refactoring**: Update an API contract and fix all consumers across repos
  27. - **Feature development**: Implement a feature that touches frontend, backend, and shared code
  28. - **Dependency updates**: Coordinate version bumps across related projects
  29. - **Documentation**: Generate docs that reference code from multiple repositories
  30. **Example prompt:**
  31. ```
  32. Update the User type in the contracts repo, then update both the frontend
  33. and backend to use the new fields. Make sure the API validates the new
  34. required field.
  35. ```
  36. ## Setting Up a Multi-Root Workspace
  37. ### Monorepos vs Multiple Repositories
  38. **Monorepo**: One Git repository containing multiple projects or packages. All code shares the same version history.
  39. ```
  40. my-company/ # Single Git repo
  41. ├── .git/
  42. ├── packages/
  43. │ ├── web/ # React frontend
  44. │ ├── api/ # Node.js backend
  45. │ └── shared/ # Common utilities
  46. └── package.json
  47. ```
  48. **Multiple Repositories**: Separate Git repositories, each with their own history, opened together in one VSCode workspace.
  49. ```
  50. ~/projects/
  51. ├── fullstack.code-workspace # Workspace config file
  52. ├── frontend/ # [email protected]:acme/frontend.git
  53. │ └── .git/
  54. ├── backend/ # [email protected]:acme/backend.git
  55. │ └── .git/
  56. └── contracts/ # [email protected]:acme/api-contracts.git
  57. └── .git/
  58. ```
  59. Cline supports both patterns, as well as hybrid setups where some folders are Git repositories and others are not. The key difference: with multiple repositories, each folder has its own `.git` directory and Cline tracks them independently.
  60. ### Adding Folders to Your Workspace
  61. You can add folders to your workspace in several ways:
  62. - **File menu**: Use `File > Add Folder to Workspace` in VSCode
  63. - **Drag and drop**: Drag folders directly into VSCode's file explorer
  64. - **Workspace file**: Create a `.code-workspace` file (recommended for teams)
  65. - **Command palette**: Run `Workspaces: Add Folder to Workspace`
  66. For detailed instructions, see [Microsoft's multi-root workspace guide](https://code.visualstudio.com/docs/editor/multi-root-workspaces).
  67. ## Working with Multiple Repositories
  68. When you open separate Git repositories in one workspace, Cline treats each as an independent project with its own version control.
  69. ### What Cline Tracks Per Repository
  70. For each workspace folder, Cline detects:
  71. | Property | Description |
  72. |----------|-------------|
  73. | **Path** | Absolute path to the folder |
  74. | **Name** | Derived from folder name or workspace file |
  75. | **VCS Type** | Git, Mercurial, or None |
  76. | **Commit Hash** | Current HEAD commit (for Git/Mercurial repos) |
  77. This means Cline understands that your frontend and backend might be at different commits, on different branches, or even use different version control systems.
  78. <Note>
  79. While Cline detects VCS information for all workspace folders, certain features only use the **primary workspace** (the first folder): [Cline rules](/features/cline-rules), [workflows](/features/slash-commands/workflows/index), and [Git-related features](/features/at-mentions/git-mentions) like `@git` mentions.
  80. </Note>
  81. ## Referencing Files Across Workspaces
  82. ### Natural Language References
  83. Cline understands natural references to your workspaces:
  84. ```
  85. "Read the package.json in the frontend folder"
  86. ```
  87. ```
  88. "Compare the user model in backend with the TypeScript types in contracts"
  89. ```
  90. ```
  91. "Search for TODO comments across all workspaces"
  92. ```
  93. ### Workspace Hints Syntax
  94. For explicit references, use the `@workspace:path` syntax:
  95. | Syntax | Description |
  96. |--------|-------------|
  97. | `@frontend:src/App.tsx` | File in the "frontend" workspace |
  98. | `@backend:server.ts` | File in the "backend" workspace |
  99. | `@contracts:types/` | Folder in the "contracts" workspace |
  100. This syntax is especially useful when:
  101. - Multiple workspaces have files with the same name
  102. - You want to be explicit about which project you mean
  103. - Cline needs to resolve ambiguity
  104. ### How Workspace Names Work
  105. Workspace names are derived from:
  106. 1. The `name` field in your `.code-workspace` file (if specified)
  107. 2. The folder name (default)
  108. If two folders have the same name, append numbers or use the workspace file to give them unique names.
  109. ## Common Configurations
  110. ### Monorepo Development
  111. ```
  112. ~/projects/my-app/
  113. ├── my-app.code-workspace # Workspace config file
  114. ├── web/ (React frontend)
  115. ├── api/ (Node.js backend)
  116. ├── mobile/ (React Native)
  117. └── shared/ (Common utilities)
  118. ```
  119. All folders share one Git history. Changes across packages are atomic.
  120. **Example prompt:** *"Update the API endpoint in both web and mobile apps to match the new backend route"*
  121. ### Microservices with Separate Repos
  122. ```
  123. ~/projects/services/
  124. ├── services.code-workspace # Workspace config file
  125. ├── user-service/ (git: github.com/acme/user-service)
  126. ├── payment-service/ (git: github.com/acme/payment-service)
  127. ├── gateway/ (git: github.com/acme/api-gateway)
  128. └── proto/ (git: github.com/acme/service-protos)
  129. ```
  130. Each service has its own repository. Cline can update the proto definitions and regenerate clients across all services.
  131. **Example prompt:** *"Add a new field to the UserProfile message in proto, then update user-service and gateway to handle it"*
  132. ### Full-Stack with Shared Contracts
  133. ```
  134. ~/projects/fullstack/
  135. ├── fullstack.code-workspace # Workspace config file
  136. ├── client/ (git: github.com/acme/web-client)
  137. ├── server/ (git: github.com/acme/api-server)
  138. └── types/ (git: github.com/acme/shared-types)
  139. ```
  140. The types repository defines interfaces used by both client and server. When you update a type, Cline can fix both consumers.
  141. ### Hybrid Setup
  142. ```
  143. ~/projects/project/
  144. ├── project.code-workspace # Workspace config file
  145. ├── main-app/ (git: github.com/acme/main-app)
  146. ├── vendor/ (no VCS - vendored dependencies)
  147. └── scripts/ (no VCS - local automation)
  148. ```
  149. Mix of repositories and plain folders. Cline adapts to each folder's configuration.
  150. ## Current Limitations
  151. Two features have limitations in multi-root workspace mode:
  152. ### Cline Rules
  153. [Cline rules](/features/cline-rules) (`.clinerules/` directory) only work in the **primary workspace** (the first folder in your workspace). Rules in other workspace folders are ignored.
  154. **Workaround:** Place shared rules in the primary workspace, or use global rules (`~/Documents/Cline/Rules/`) which apply everywhere.
  155. ### Checkpoints
  156. [Checkpoints](/features/checkpoints) are disabled in multi-root workspace mode. Cline displays a warning when this happens.
  157. **Why:** Checkpoints use a shadow Git repository to track changes. With multiple repositories, coordinating checkpoints across independent Git histories adds complexity that isn't yet supported.
  158. **Workaround:** Use your normal Git workflow. Commit frequently, or create branches for experimental work.
  159. Both limitations are restored when you return to a single-folder workspace.
  160. ## Best Practices
  161. ### Organizing Your Workspaces
  162. 1. **Group related projects** that often need coordinated changes
  163. 2. **Use a workspace file** for reproducible setups across your team
  164. 3. **Name folders clearly** so workspace hints are intuitive
  165. 4. **Consider the primary workspace** for Cline rules placement
  166. ### Effective Prompting
  167. - **Be specific** when it matters: *"Update the user model in the backend workspace"*
  168. - **Reference relationships**: *"The frontend uses types from the contracts workspace"*
  169. - **Describe cross-workspace changes**: *"This needs to update both web and mobile"*
  170. - **Scope searches** for large codebases: *"Search for 'TODO' only in the frontend workspace"*
  171. ### Working with Large Workspaces
  172. - Break large tasks into workspace-specific operations when possible
  173. - Use [Plan mode](/features/plan-and-act) to let Cline understand structure first
  174. - Add a `.clineignore` file to reduce noise, speed up scanning, and keep Cline focused on source code:
  175. ```text
  176. # Dependencies
  177. **/node_modules/
  178. # Build outputs
  179. **/dist/
  180. **/build/
  181. # VCS metadata
  182. **/.git/
  183. ```
  184. For more patterns and gotchas, see the [.clineignore File Guide](/prompting/prompt-engineering-guide#clineignore-file-guide).