Problem
When multiple Claude Code tasks run in the same workspace, they share a single git working tree. This causes:
- Race conditions on file edits — two tasks modifying the same file overwrite each other
- Git state conflicts — Task A commits while Task B has uncommitted changes, blocking B's commit
- No branch isolation — all tasks operate on the same branch with the same staging area
Traditional file locking (e.g., flock, LockFileEx) is not a viable solution because:
- Git operations are atomic across many files — you can't lock "a commit"
- Cross-file dependencies create deadlock risk
- Cross-process file locking is fragile and platform-inconsistent
Proposed Solution
Use git worktrees to give each task (or group of tasks) its own isolated working directory and branch.
Detailed design: docs/plans/git-worktree-support.md
Note: The plan document needs to be committed to main for the link above to resolve.
Scope
| Priority |
Item |
Description |
| P0 |
WorktreeManager backend module |
list, create, remove, prune wrapping git worktree commands |
| P0 |
REST/WS endpoints for worktree CRUD |
Query-param based (/api/worktrees?workspace=...) |
| P1 |
Auto-worktree mode |
Per-workspace toggle: new tasks auto-create an isolated worktree |
| P1 |
Sidebar UX |
Worktree workspaces grouped under parent, branch icon, count badge |
| P2 |
Worktree management panel |
List, remove, prune stale worktrees |
| P2 |
MCP isolate parameter |
Let orchestrator agents request worktree isolation via claudia_create_task |
| P3 |
Warning for concurrent tasks without isolation |
Toast when 2+ tasks run in the same workspace without worktrees |
What already exists
- Atomic writes for Claudia internal files (
tasks.json, config.json)
- Mtime-based detection of multiple server instances
- Detailed design doc (linked above)
Key edge cases to handle
- Windows path encoding in REST URLs (use query params, not path params)
.git/info/exclude instead of modifying tracked .gitignore
- Submodule initialization in new worktrees
- Stale worktree cleanup when directories are deleted externally
- Block parent workspace removal if worktree children exist
Problem
When multiple Claude Code tasks run in the same workspace, they share a single git working tree. This causes:
Traditional file locking (e.g.,
flock,LockFileEx) is not a viable solution because:Proposed Solution
Use git worktrees to give each task (or group of tasks) its own isolated working directory and branch.
Detailed design: docs/plans/git-worktree-support.md
Scope
WorktreeManagerbackend modulelist,create,remove,prunewrappinggit worktreecommands/api/worktrees?workspace=...)isolateparameterclaudia_create_taskWhat already exists
tasks.json,config.json)Key edge cases to handle
.git/info/excludeinstead of modifying tracked.gitignore