運用 Git Worktrees 平行化 AI 編碼

Hacker News·

本文介紹一種利用 Git worktrees 和 workmux 工具來平行化 AI 編碼任務的工作流程。文章概述了生成、細化和委派任務給獨立 worktree agent 的三個步驟,有助於簡化開發和審查過程。

Using git worktrees to parallelize AI coding

A workflow for delegating tasks to parallel worktree agents using workmux

As a continuation of the earlier post that introduced workmux, here's
a useful pattern for delegating tasks to worktree agents.

The workflow in a nutshell

Step 1: Come up with tasks

The first step is to come up with things to do. The tasks can be anything:
features, bug fixes, improvement ideas or refactoring suggestions etc. As an
example, I'll ask the agent for improvement ideas for a project I happen to be
working on, but you could just as easily use a to-do list file as a source for
the tasks.

Image

I like to occasionally use gemini-3-pro-preview through consult-llm-mcp to
see what Gemini comes up with.

Step 2: Refine the tasks

Gemini came up with a nice list of items to do, but I don't necessarily want to
implement all of them, or they might require some adjustments. The advantage of
a markdown file as an intermediate step, as opposed to just holding the items in
the agent's context, is that you can freely edit it in the editor. However,
either way works, so this step is optional.

Image

Step 3: Delegate to an agent in a worktree

As mentioned in the introductory post, the advantage of worktrees in
agent parallelization is that the changes done won't conflict with other agents.
Agents will only see type errors, test failures, or lint issues caused by their
own changes, and reviewing their work is also much easier.

In the Telegram bot, I want to implement this feature of allowing the user to
edit the draft listing using natural language. For example, "Set price to 80€".
(What a great idea I hadn't considered. This avoids the need to build a separate
bot slash command for every conceivable action.)

Instructing the agent to create a worktree for a task with workmux requires some
prompt glue, so I have a custom command that makes worktree
creation easy.

This command instructs the agent to create a new worktree with workmux, passing
the referenced task as a prompt to the agent that starts within the created
worktree and its tmux window.

Image

workmux add natural-language-edit -b -P /tmp/tmp.xxx.md creates a worktree and
tmux window named natural-language-edit. The -b flag runs it in the
background (stays in current window), and -P passes the temp file as a prompt
to the agent.

Image

Because every worktree has its own tmux window with the agent process running,
you can interact with the agent as needed, or start reviewing the changes as
they come in.

Image

Step 4: Review changes and merge

Once an agent finishes, you can switch to its window and review the changes like
you normally would with git diff or other tools. I usually skim the diff in
Neovim and request changes as needed. For the natural language editing feature,
it's useful to also run the dev server in another pane to test the changes
manually.

You may have noticed the /worktree command asks agents to review the changes
before finishing. I find it extremely useful to do a round of review with AI,
and especially Gemini, before looking at the diff myself.

Image

When happy with the changes, you can run workmux merge --rebase which rebases
on main, merges and cleans up the worktree. Note that if there are conflicts
from other merged branches, the worktree's agent can usually resolve them (see
earlier post).

With this workflow, I can start a few agents, do something else, and come back
to a queue of diffs ready for review.

workmux

git worktrees + tmux windows for zero-friction parallel dev

Thanks for reading! You can check out my projects on
GitHub
or follow me on
Twitter.

Hacker News

相關文章

  1. Workmux:運用 Git Worktrees 和 Tmux 實現平行 AI 代理

    4 個月前

  2. 利用 Git Submodules 實現 AI / LLM 代理指令的集中化方法

    3 個月前

  3. 在AI工具中處理多個儲存庫的困境

    3 個月前

  4. 利用 Git 標註 AI 生成的程式碼

    3 個月前

  5. Show HN:使用 gitz (Rust 與 AI) 自動化 Git 提交訊息

    4 個月前