parallel-worktrees

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Parallel 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-branch
Claude Code:
bash
claude --worktree    # or claude -w (auto-creates isolated worktree)
Cursor / 任意编辑器:
bash
git worktree add ../project-feat feature-branch

Open 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):
  • claude -w
    auto-creates and cleans up worktrees
  • Subagents support
    isolation: worktree
    in agent frontmatter
  • Ctrl+F
    kills all background agents (two-press confirmation)
  • Ctrl+B
    sends a task to background
以下功能为 Claude Code 独有;如果使用 Cursor,可以跳过:
  • claude -w
    自动创建并清理 worktree
  • Subagents 支持在 Agent frontmatter 中设置
    isolation: worktree
  • Ctrl+F
    终止所有后台 Agent(需按两次确认)
  • Ctrl+B
    将任务发送到后台

Workflow

工作流

  1. Show current worktrees:
    git worktree list
  2. Create a worktree for the parallel task.
  3. Open a new editor/terminal session in the worktree.
  4. When done, clean up the worktree.
  1. 显示当前 worktree:
    git worktree list
  2. 为并行任务创建 worktree。
  3. 在 worktree 中打开新的编辑器或终端会话。
  4. 完成后清理 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 prune
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 prune

Usage Pattern

使用模式

Terminal 1: ~/project          → Main work
Terminal 2: ~/project-feat     → Feature development
Terminal 3: ~/project-fix      → Bug fixes
Each 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

何时并行处理

ScenarioAction
Tests running (2+ min)Start new feature in worktree
Long buildDebug issue in parallel
Exploring approachesCompare 2-3 simultaneously
Review + new workReviewer in one, dev in other
Waiting on CIStart 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 路径和分支
  • 打开新会话的说明