Worktrunk 2026年11月
Worktrunk 于今年年初发布,迅速成为最受欢迎的 git worktree 管理器。它是用心构建的(绝无敷衍!)。请告诉我任何使用上的不便之处;我非常专注于让 Worktrunk 持续保持优秀,而最大的帮助就是大家反馈遇到的问题。
Worktrunk 是一个用于 git worktree 管理的 CLI,专为并行运行 AI agent 而设计。Worktrunk 的三个核心命令让 worktree 像分支一样简单。此外,Worktrunk 还提供了一系列提升使用体验的功能,简化处理大量并行变更的工作,包括自动化本地工作流的 hooks 和写时复制的构建缓存。
快速演示:
📚 完整文档请访问 worktrunk.dev 📚
背景:git worktree 与 AI agent
像 Claude Code 和 Codex 这样的 AI agent 可以在无人监督的情况下处理较长的任务,因此同时管理 5-10 个以上的任务是可行的。Git 原生的 worktree 功能为每个 agent 提供独立的工作目录,这样它们就不会互相干扰彼此的变更。但 git worktree 的使用体验很笨拙。即使像创建新 worktree 这样的小任务,也需要输入三次分支名:git worktree add -b feat ../repo.feat,然后 cd ../repo.feat。
Worktrunk 让 git worktree 像分支一样简单
Worktree 通过分支名来寻址;路径根据可配置的模板计算得出。接受分支的命令也接受该分支所检出 worktree 的路径。
从核心命令开始
核心命令:
| 任务 | Worktrunk | 原生 git | |------|-----------|----------| | 切换 worktree | wt switch feat | cd ../repo.feat | | 创建 + 启动 Claude | wt switch -c -x claude feat | git worktree add -b feat ../repo.feat && \cd ../repo.feat && \claude | | 清理 | wt remove | cd ../repo && \git worktree remove ../repo.feat && \git branch -d feat | | 带状态列出 | wt list | git worktree list(仅路径) |
按需扩展到更高级的命令
- 工作流自动化:Hooks — 在创建、合并前、合并后等时机运行命令
- LLM 提交信息 — 从 diff 生成提交信息
- 合并工作流 — 一条命令完成 squash、rebase、merge、清理
- 交互式选择器 — 浏览 worktree,实时查看 CI 状态和 diff、日志、PR 及评论预览
- 共享构建缓存 — 十个 worktree 获得
target/、node_modules/等目录,无需构建或复制(在 APFS、btrfs 和 XFS 上) wt list --full— 每个分支的 CI 状态和 AI 生成的摘要- PR 检出 —
wt switch pr:123直接跳转到 PR 的分支 - 每个 worktree 独立开发服务器 —
hash_port模板过滤器为每个 worktree 分配唯一端口 - 别名与分支级变量 — 自定义
wt命令和分支作用域状态,用于 hook 模板 - ……以及更多功能
多个并行 agent,同样简单的命令:
安装
Homebrew(macOS 和 Linux):
brew install worktrunk && wt config shell install
Shell 集成允许命令切换目录。
Cargo:
cargo install worktrunk && wt config shell install
Windows 及其他平台:wt 默认使用 Windows Terminal 的命令,因此 Winget 额外将 Worktrunk 安装为 git-wt 以避免冲突:
winget install max-sixty.worktrunk
git-wt config shell install
或者,禁用 Windows Terminal 的别名(设置 → 应用 → 高级应用设置 → 应用执行别名 → "Terminal"/"Terminal Preview")以直接使用 wt。
免费代码签名由 SignPath.io 提供,证书由 SignPath Foundation 提供 — 政策。
Arch Linux:
sudo pacman -S worktrunk && wt config shell install
Conda / Pixi(社区维护的 feedstock):
conda install -c conda-forge worktrunk && wt config shell install
或使用 Pixi:pixi global install worktrunk && wt config shell install。
快速开始
为新功能创建一个 worktree:
$ wt switch --create feature-auth
✓ Created branch feature-auth from main and worktree @ ~/repo.feature-auth
这会创建一个新分支和 worktree,然后切换到其中。完成工作后,用 wt list 查看所有 worktree:
$ wt list
Branch Status HEAD± main↕ main…± Remote⇅ Commit Age Message
@ feature-auth + ↑ +27 -8 ↑1 +31 4bc72dc 2h Add authenticatio…
^ main ^⇡ ⇡1 0e631ad 1d Initial commit
○ Showing 2 worktrees, 1 with changes, 1 ahead, hidden: Path
@ 标记当前 worktree。+ 表示已暂存的变更,↑1 表示领先 main 1 个提交,⇡ 表示未推送的提交。
完成后,可以选择:
PR 工作流 — 提交、推送、创建 PR、通过 GitHub/GitLab 合并,然后清理:
wt step commit # 提交已暂存的变更
gh pr create # 或 glab mr create
wt remove # PR 合并后
本地合并 — squash、rebase 到 main、快进合并、清理:
$ wt merge main
◎ Generating commit message and committing changes... (2 files, +53, no squashing needed)
Add authentication module
✓ Committed changes @ a1b2c3d
◎ Merging 1 commit to main @ a1b2c3d (no rebase needed)
* a1b2c3d Add authentication module
auth.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib.rs | 2 ++
2 files changed, 53 insertions(+)
✓ Merged to main (1 commit, 2 files, +53)
◎ Removing feature-auth worktree & branch in background (same commit as main, _)
○ Switched to worktree for main @ ~/repo
对于并行 agent,创建多个 worktree 并在每个中启动一个 agent:
wt switch -x claude -c feature-a -- 'Add user authentication'
wt switch -x claude -c feature-b -- 'Fix the pagination bug'
wt switch -x claude -c feature-c -- 'Write tests for the API'
-x 标志在切换后运行一个命令;-- 之后的参数会传递给它。配置 post-start hooks 来自动化设置(安装依赖、启动开发服务器)。
下一步
- 学习核心命令:
wt switch、wt list、wt merge、wt remove - 设置 hooks 实现自动化配置
- 探索 LLM 提交信息、交互式选择器、Claude Code 集成、CI 状态与 PR 链接
- 浏览技巧与模式获取实用配方:别名、开发服务器、数据库、agent 交接等
- 扩展 Worktrunk — 通过 hooks 和别名自定义工作流
- 观看 @DevOpsToolbox 关于 Worktrunk 的视频
- 运行
wt --help或wt获取快速 CLI 参考--help - ⭐ 给仓库加星
- 向朋友推荐 Worktrunk
- 提交 issue — 反馈