Async Work with Git Worktrees

This document is the worked example for running an LLM asynchronously.

The LLM works in its own worktree on its own branch.

The human works in the main checkout.

Git is the message channel.

The Problem

The Pattern

  1. Create a worktree for the episode.
  2. The LLM works only inside the worktree.
  3. The LLM commits on its branch.
  4. The human works in the main checkout.
  5. When the episode settles, review the branch diff.
  6. Merge the branch.

The Worked Example

This transcript is verified.

It was executed against git 2.x on a scratch repository.

1. Baseline

git init -b main
    # add files and commit
    git commit -m "chore: baseline"

2. Create the LLM worktree

git worktree add ../llm-work -b llm/episode-42

Verified output:

/tmp/worktree-demo/main      bea24c9 [main]
    /tmp/worktree-demo/llm-work  bea24c9 [llm/episode-42]

3. Parallel work

Verified output:

main log:
    e739c20 docs: record design decision (human work)
    bea24c9 chore: baseline
    
    llm branch log:
    524bf13 feat: add feature (LLM episode work)
    bea24c9 chore: baseline

4. Review the episode before merging

git log --oneline main..llm/episode-42
    git diff main...llm/episode-42 --stat

Verified output:

524bf13 feat: add feature (LLM episode work)
     src/feature.py | 2 ++
     1 file changed, 2 insertions(+)

The review surface is one commit and one file.

This is the size of a one-sitting review.

5. Merge

git merge --no-ff llm/episode-42

Verified output:

c5b3a4a merge: episode-42 (LLM feature work)
    e739c20 docs: record design decision (human work)
    524bf13 feat: add feature (LLM episode work)
    bea24c9 chore: baseline

The merge is conflict-free when the streams touched disjoint files.

The merge is the check-the-mailbox moment.

6. Cleanup

git worktree remove ../llm-work

Automation

Two safe designs:

A conflict is a feature.

A conflict forces a human decision where the two streams intersect.

Alternatives

Practice