AI编码
dev.to ·
@ArshTechPro
Worktrunk:为并行 AI Agent 简化 Git Worktree
Worktrunk 是一个用 Rust 编写的开源命令行工具,旨在简化 git worktree 的使用。当 Claude Code、Codex 等 AI 编码 agent 并行处理不同任务时,同一目录会互相覆盖改动,而 git worktree 可让每个分支拥有独立工作目录。Worktrunk 允许用户仅通过分支名操作,自动推导目录路径,减少原生命令中重复输入分支名和多次清理的繁琐步骤。
AI推荐理由 介绍 Rust 编写的开源 CLI 工具 Worktrunk,用分支名简化 git worktree 的创建与清理,面向并行运行多个 AI 编码 agent 的场景。属于开发者工具类实用介绍,但正文为作者自述,未提供性能数据或独立验证,且摘要被截断。
62
正文
AI coding agents like Claude Code and Codex can now work on longer tasks without supervision. That means you can realistically run several of them at once, each on a different feature or bug.
The catch: if they all work in the same folder, they overwrite each other's changes. Git has a built-in answer for this called worktrees. A worktree is a separate working directory attached to the same repository, so each branch can live in its own folder at the same time.
The problem is that git's worktree commands are clunky. Just starting a new one looks like this:
git worktree add -b feat ../repo.feat
cd ../repo.feat
Enter fullscreen mode
Exit fullscreen mode
You type the branch name three times. Cleaning up afterward takes another three commands. Do this ten times a day and it gets old fast.
What Worktrunk is
Worktrunk is a command-line tool, written in Rust, that makes worktrees as easy to use as regular branches. You refer to everything by branch name, and Worktrunk works out the folder paths for you.
It's open source (MIT or Apache-2.0), was released at the start of 2026, and already has over 5k stars on GitHub.
The core commands
Here's how Worktrunk compares with plain git:
Task
Worktrunk
Plain git
Switch to a worktree
wt switch feat
cd ../repo.feat
Create and start an agent
wt switch -c -x claude feat
git worktree add -b feat ../repo.feat && cd ../repo.feat && claude
Clean up
wt remove
cd ../repo && git worktree remove ../repo.feat && git branch -d feat
List with status
wt list
git worktree list (paths only)
Four commands cover most of what you'll do day to day.
Getting started
Install with Homebrew (macOS and Linux):
brew install worktrunk && wt config shell install
Enter fullscreen mode
Exit fullscreen mode
Or with Cargo:
cargo install worktrunk && wt config shell install
Enter fullscreen mode
Exit fullscreen mode
The wt config shell install step matters. It adds shell integration so wt can actually change your current directory.
Create a worktree for a new feature:
wt switch --create feature-auth
Enter fullscreen mode
Exit fullscreen mode
This creates the branch and the worktree, then moves you into it. Check all your worktrees and their status with:
wt list
Enter fullscreen mode
Exit fullscreen mode
When you're done, you can open a PR as usual and run wt remove after it merges. Or merge locally with one command:
wt merge main
Enter fullscreen mode
Exit fullscreen mode
That commits your changes, rebases onto main, merges, and removes the worktree and branch.
Running agents in parallel
This is where Worktrunk shines. Start three agents on three tasks, each in its own isolated worktree:
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'
Enter fullscreen mode
Exit fullscreen mode
The -x flag runs a command after switching, and everything after -- is passed to that command. No agent touches another agent's files.
Extras worth knowing
Beyond the basics, Worktrunk includes:
Hooks that run commands when a worktree is created or merged, such as installing dependencies or starting a dev server.
LLM-generated commit messages based on your diff.
Build cache copying so a new worktree can reuse node_modules/ or target/ instead of starting cold.
PR checkout with wt switch pr:123.
A unique port per worktree so multiple dev servers can run side by side.
Is it worth a try?
Yes, if you:
Run more than one AI coding agent at a time.
Juggle several branches and hate stashing or re-cloning.
Already use git worktrees and are tired of the long commands.
A few honest caveats. It's a young project, so expect frequent releases and occasional changes. Every worktree is a full copy of your working files, so large repos use more disk space (the cache-copying feature helps, but doesn't remove this). On Windows, wt clashes with the Windows Terminal command, so it installs as git-wt instead unless you disable that alias. And if you only ever work on one branch at a time, plain git switch is all you need.
If parallel agents are part of your workflow, Worktrunk removes most of the friction of worktrees. Install it, spin up two worktrees, and you'll know within ten minutes whether it sticks.
Links
GitHub: https://github.com/max-sixty/worktrunk