parallel-worktrees
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseParallel Worktrees
并行 Worktree
Zero dead time. While one session runs tests, work on something else.
零等待。当一个会话运行测试时,可以同时处理其他工作。
Trigger
触发场景
Use when waiting on tests, long builds, exploring approaches, or needing to review and develop simultaneously.
在等待测试、长时间构建、探索不同方案,或需要同时进行审查和开发时使用。
Quick Start
快速开始
Claude Code:
bash
claude --worktree # or claude -w (auto-creates isolated worktree)Cursor / Any editor:
bash
git worktree add ../project-feat feature-branchClaude Code:
bash
claude --worktree # or claude -w (auto-creates isolated worktree)Cursor / 任意编辑器:
bash
git worktree add ../project-feat feature-branchOpen the new worktree folder in a second editor window
Open the new worktree folder in a second editor window
Both approaches create an isolated working copy where changes don't interfere with your main session.
两种方式都会创建一个隔离的工作副本,其中的更改不会干扰主会话。Claude Code Extras
Claude Code 附加功能
These features are Claude Code-specific (skip if using Cursor):
- auto-creates and cleans up worktrees
claude -w - Subagents support in agent frontmatter
isolation: worktree - kills all background agents (two-press confirmation)
Ctrl+F - sends a task to background
Ctrl+B
以下功能为 Claude Code 独有;如果使用 Cursor,可以跳过:
- 自动创建并清理 worktree
claude -w - Subagents 支持在 Agent frontmatter 中设置
isolation: worktree - 终止所有后台 Agent(需按两次确认)
Ctrl+F - 将任务发送到后台
Ctrl+B
Workflow
工作流
- Show current worktrees:
git worktree list - Create a worktree for the parallel task.
- Open a new editor/terminal session in the worktree.
- When done, clean up the worktree.
- 显示当前 worktree:
git worktree list - 为并行任务创建 worktree。
- 在 worktree 中打开新的编辑器或终端会话。
- 完成后清理 worktree。
Commands
命令
bash
git worktree list
git worktree add ../project-feat feature-branch
git worktree add ../project-fix bugfix-branch
git worktree add ../project-exp -b experiment
git worktree remove ../project-feat
git worktree prunebash
git worktree list
git worktree add ../project-feat feature-branch
git worktree add ../project-fix bugfix-branch
git worktree add ../project-exp -b experiment
git worktree remove ../project-feat
git worktree pruneUsage Pattern
使用模式
Terminal 1: ~/project → Main work
Terminal 2: ~/project-feat → Feature development
Terminal 3: ~/project-fix → Bug fixesEach worktree runs its own AI session independently.
Terminal 1: ~/project → Main work
Terminal 2: ~/project-feat → Feature development
Terminal 3: ~/project-fix → Bug fixes每个 worktree 都会独立运行自己的 AI 会话。
When to Parallelize
何时并行处理
| Scenario | Action |
|---|---|
| Tests running (2+ min) | Start new feature in worktree |
| Long build | Debug issue in parallel |
| Exploring approaches | Compare 2-3 simultaneously |
| Review + new work | Reviewer in one, dev in other |
| Waiting on CI | Start next task in worktree |
| 场景 | 操作 |
|---|---|
| 测试正在运行(2 分钟以上) | 在 worktree 中启动新功能 |
| 长时间构建 | 并行调试问题 |
| 探索不同方案 | 同时比较 2~3 种方案 |
| 审查 + 新工作 | 一个 worktree 负责审查,另一个负责开发 |
| 等待 CI | 在 worktree 中开始下一个任务 |
Guardrails
注意事项
- Each worktree is a full working copy — changes are isolated.
- Before removing a worktree, verify changes are committed:
git -C ../project-feat status - Don't forget to clean up worktrees when done ().
git worktree prune - Avoid editing the same files in multiple worktrees simultaneously.
- 每个 worktree 都是完整的工作副本——更改彼此隔离。
- 移除 worktree 前,验证更改已提交:
git -C ../project-feat status - 完成后别忘了清理 worktree()。
git worktree prune - 避免在多个 worktree 中同时编辑相同文件。
Output
输出
- Current worktree list
- Created worktree path and branch
- Instructions for opening a new session
- 当前 worktree 列表
- 已创建的 worktree 路径和分支
- 打开新会话的说明