**Codex Multi-Agent Workflow with Git Worktrees — Transcript & Summary | SozAI**
Source: https://sozai.app/transcript/codex-multi-agent-workflow-git-worktrees/

Learn how to use Git worktrees with Codex CLI and Mac OS app to run multiple AI agents in parallel for redesigning projects efficiently.

## Key Takeaways

- Git worktrees enable efficient parallel work by multiple AI agents on the same project repository without duplicating Git history.
- Worktrees save disk space and simplify branch management and merging locally, reducing dependency on remote GitHub operations.
- Codex CLI and Mac OS app both support managing worktrees and running parallel redesign tasks with AI agents.
- Multiple design styles can be developed simultaneously and merged selectively into the main branch.
- Worktrees provide a practical solution for concurrent feature development even when files overlap.

## What the video covers

- Introduction to using Git worktrees to run multiple AI agents working simultaneously on different branches of a project.
- Comparison between copying project folders multiple times versus using Git worktrees that share a single Git repository.
- Explanation of how worktrees save space and allow branch sharing and merging locally without needing GitHub.
- Demonstration of setting up multiple worktrees for parallel redesigns of a web application using Codex CLI.
- Running multiple Codex agents in parallel with different design styles such as Swiss, futurism, brutalism, Bauhaus, Art Deco, and Japanese minimalism.
- Using Codex Mac OS app to manage worktrees and threads with similar concepts to the CLI but with a graphical interface.
- How to merge preferred redesign branches into the main branch locally and clean up worktrees after completion.
- Details on managing worktrees, including listing, renaming, and cleaning up unused worktrees.
- Discussion on practical scenarios where worktrees help when multiple features touch the same files.
- Final thoughts on the workflow benefits and alternatives like copying folders for isolated agent work.

## Chapters

1. 00:00 Introduction to Git Worktrees and Multi-Agent Workflow
2. 00:47 Copying Folders vs Independent Git Repositories
3. 01:22 Advantages of Git Worktrees Over Folder Copies
4. 02:13 Setting Up Worktrees for YouTube Copilot Project
5. 03:00 Listing Worktrees and Branches
6. 03:53 Running Parallel Agents with Different Design Styles
7. 04:39 Using Codex Mac OS App for Worktree Management
8. 05:48 Creating and Managing Worktrees in Codex Mac OS App
9. 07:48 Worktree Cleanup and Final Merging Steps
10. 09:15 Summary and Alternative Workflows

Answers

## Questions about this video

What are Git worktrees and why are they useful in multi-agent workflows?

Git worktrees allow multiple working directories to share a single Git repository, enabling parallel development on different branches without duplicating the repository. This saves disk space and simplifies branch management, making it ideal for running multiple AI agents on the same project.

How does using Git worktrees compare to copying project folders for parallel work?

Copying project folders creates independent repositories that consume more disk space and require pushing and pulling changes via GitHub. Git worktrees share the same Git directory, use less space, and allow local branch sharing and merging without needing remote operations.

Can I merge branches locally when using Git worktrees without pushing to GitHub?

Yes, since all worktrees share the same Git repository and history, you can merge branches locally within the worktrees without pushing to or pulling from GitHub, streamlining the workflow.

## Full Transcript — Download SRT & Markdown

00:00

Speaker A

Today we're going to learn how to use Git work trees to start multiple agents that work at the same time on our project. Imagine we have a project and we have the main branch. Let's say it's an app and we want to have a different

00:11

Speaker A

design at the same time. Now we have AI agents and we can start like 10 different agents and we can prompt every AI agent to design the web page in a different style, and at the end we can

00:21

Speaker A

compare the 10 different versions. Now one way to do that is to get this folder that we have with the main branch and then copy it over 10 times. So we can literally copy the project folder four times and start an AI agent in every single

00:35

Speaker A

folder. With this setup, we basically have four independent directories and they point all to the same origin on GitHub. Let me rename the branches so that becomes a bit more clear. Say we have an application, we want to redesign

00:47

Speaker A

it. We have one folder with the main branch and we have four different independent Git repositories. We run three agents in parallel in those different folders. And once they are done with the redesign, we pick the design that we like. We push it to

01:00

Speaker A

GitHub and then we can make a pull request and merge it in the main branch.

01:04

Speaker A

So you see it gets a bit complicated. Now the alternative to that is using work trees. Work trees are very similar to this approach of copying folders.

01:11

Speaker A

Basically we also copy folders but they all share the same Git repository. So I'm going to copy this whole setup. I'm going to paste it because they are so similar. But at the same time the work trees don't have

01:22

Speaker A

their own Git directory. It's shared. And what that means is that all those folders use less space because they only have one Git directory. But more importantly, they can share branches or they can merge branches between each other. What does it mean? So imagine we

01:37

Speaker A

have a main branch and then we have those three branches air1, airb, and airc which are redesign one, redesign b, and redesign c. So if I'm in this folder, I can actually see all those three branches and then I can merge them in

01:50

Speaker A

main. I don't need GitHub actually. I don't need to push to GitHub and then pull anything that has created those work trees. And once we are done with the three versions with the parallel agents, we can pick one of the branches

02:02

Speaker A

that we like and just merge it into main. And I'm going to show you exactly how this works right now. We're going to open Codex CLI. We're going to start it in just a minute. But I want to tell you

02:13

Speaker A

this is YouTube Copilot, the project that we're going to be working on. And I'm going to create a new folder here that will hold all my work trees so I know where they are.

02:22

Speaker A

YouTube Copilot work trees. So these are the work trees that are going to be here and this is YouTube Copilot, the project. So in those three terminal windows I'll start Codex and I'll start agents in parallel that

02:36

Speaker A

are working on redesigning the web page. And on this fourth window I'll just open Codex and I'm going to tell Codex to create three work trees under YouTube Copilot work trees. Each work tree should switch to the following branches.

02:49

Speaker A

Let Codex work. I'm going to ask Codex to please start a local server so we can see the application that we're working with. You could also see the work trees here while the app is starting and I can

03:00

Speaker A

actually go to the repositories and do git worktree list. So we can see all the work trees and if we do git branch list you could see that every work tree can see every branch and this is the

03:15

Speaker A

application that we want to redesign. This is an application that I developed for myself for YouTube to generate me some thumbnails, tech backgrounds, and title improvers, analytics, and so on. So I'd like to redesign it and we'll start three agents in parallel. So we are

03:30

Speaker A

going to get three different versions of this design. Once we like one of the versions, we'll merge that into main.

03:36

Speaker A

I'm going to open Codex here, Codex here, and Codex here. And in every work tree I have told Codex to please redesign the front end according to Swiss international typographics, according to futurism, according to brutalism. So we're going to get three

03:53

Speaker A

different versions of this web application by three different agents working in parallel without interfering with each other. But the approach that you probably would need more in practice is, okay, I want to work on those two different features but they touch the

04:05

Speaker A

same file. How do I do that? You do that with work trees. I'm going to start them now. Start one, two, and actually I quickly interrupted this one because I started that in the wrong branch. So I'm going to start it here and going to go

04:18

Speaker A

to Codex and we watch them work. Now once they are done we're going to move to the Codex Mac OS app. We're going to check this out and once we're done with the Mac OS app we're going to

04:27

Speaker A

check out the approach with IDEs but they share a similar philosophy. And by the way the Mac OS app is synced with the CLI. So I can see this thread that I have started in the CLI now appear in

04:39

Speaker A

the Mac OS app. So they are all done. This is the original design and I have them here. So this is the futurism design that we have here. This is the brutalism design that we have and this is the Swiss style design that we have

04:52

Speaker A

which I think I like best but of course personal preference. Now what do we do from here? We can go back to Codex. Remember this is the folder where it all started, the YouTube Copilot. This is not a work tree. This is

05:04

Speaker A

the main folder. So we can go here and ask Codex to merge any of the branches that we have. In this case, I like the Swiss style most. So I can ask Codex, hey, merge with this branch. And since

05:15

Speaker A

they all share the same Git folder, the same Git history, I can merge them locally. I don't need to go through GitHub. So I can merge it here. Then I can ask Codex, hey, can you clean up the

05:25

Speaker A

work trees or remove the work trees? But this is how you work with work trees with the Codex CLI. I'm going to show you now how to do that with the Mac OS app because the controls there are a bit

05:36

Speaker A

different but the underlying concepts of course are the same. So I asked Codex, can you clean up all work trees and branches in this repo? Leave main.

05:44

Speaker A

That's my objective here. All right, the cleanup is complete. We have the YouTube Copilot project here again. We can open it in Finder.

05:53

Speaker A

We can open it in any text editor if we like. I can toggle the terminal here.

05:58

Speaker A

And now we're going to start three work trees again. We are going to start a new thread. And a new thread is just a space so I can talk to Codex the same like the terminals. And here instead of

06:08

Speaker A

local, I click new work tree. And it says create a copy of your local project to work in parallel. And this is exactly what we want. So I'm going to say redesign the front end according to Bauhaus modernism design style. We're

06:21

Speaker A

going to see here this icon which says this conversation is running in a local Git work tree. Now notice we didn't have to create any local folders. Codex took care of that. And if we open this work tree in Finder, so we're going to see

06:34

Speaker A

that it is being created somewhere under Codex work trees and then an ID and so on. So Codex takes care of creating those work trees and tracking them and so on. So we don't have to create those folders ourselves. We can open the terminal and

06:48

Speaker A

say git worktree list. We're going to see we have one work tree, but we would like to create two more. So I started a new thread then a new work tree and then I said please redesign the front end

06:58

Speaker A

according to Art Deco design style and start it on port 5173. I'm going to start it here. I can actually rename the work trees so it's a bit more intuitive Bauhaus style. I can also start a local project or a local thread which means

07:14

Speaker A

that we'll be in our main work tree where our main Git history which is YouTube Copilot. I'm just going to say here is a local thread so we can have it here in the sidebar and we're going to

07:26

Speaker A

ask Codex to design according to Japanese minim...

07:39

Speaker A

the concepts by the way we can also pin the threads like that and this important because of work tree cleanup work trees will never be cleaned up if a pin conversation is tied to it otherwise Work trees are eligible for cleanup when

07:52

Speaker A

it's more than 4 days old and you have more than 10 work trees. Although even if Codex cleans up the work tree, it will save a snapshot of the work on it.

08:00

Speaker A

So you can restore it at any point. So don't worry, Codex wouldn't just delete your work. But you can read more about work trees on their documentation. Now remember again our main branch is running on port 5171. This important

08:13

Speaker A

because now we'll actually merge the work from one of the work trees into main via the Mac OS app to see how that works. So this is the art deco style of the application and I think the others

08:24

Speaker A

are also done. The bow house is done on port 72. So this is the bow house design and the Japanese was also done on port 74. So those are the three different versions that we run in parallel. We're

08:37

Speaker A

going to pick one now. I think I like actually I don't like any of them but we're going to merge uh just for the demo we're going to pick this one the Japanese and in order to merge it we're

08:47

Speaker A

going to click here hand off to local what that would do is now give us an option to either create a local branch and all of this is local but local means the folder where we started the source

09:00

Speaker A

of truth for the git history so so basically this is what uh the Mac OS app means by local and we're going to click existing branch main and we're going to click checked out locally. It's already checked out means

09:15

Speaker A

our local folder is already on the main branch. We're going to click continue and we're going to say to local. So we're going to hand off changes to local and we're going to click apply and and we have handed off the Japanese

09:29

Speaker A

minimalism to our local space. Here we can see also the diff here and that's the Japanese minimalism that has been implemented here. We can also take the terminal and do get status. We can see the changes and we can now commit them

09:49

Speaker A

and so on. So if you go on the port 51 we can see that our application is not how it looked anymore. It's the Japanese minimalism style. Now we have two different work trees. We can either archive them or we can click branch from

10:04

Speaker A

here. This would create a new branch art deco style for example. We're going to commit and then we can keep working on this branch art deco style in the art deco style work tree. And we can also check out this branch in any other

10:18

Speaker A

thread as long as the work tree doesn't occupy it anymore. So any work tree, any local folder can check out any branch because the git history is shared as long as one branch is not shared at the same time by multiple work trees. So if

10:31

Speaker A

I switch to the local tree, I can't actually pick the art deco style because it's occupied. And if you work actually with IDs, you just need to find the folder of the work tree and then drag and drop it into your ID. For example, I

10:46

Speaker A

can drag and drop here into cursor and then you can start working in cursor on the work tree. If this is too overwhelming for you or if it seems too complicated, I think that's a fair point. In this case, you can just copy

10:59

Speaker A

and paste the folders. So, you can basically operate under this setup where you don't have to manage work tree. You can just have many folders. They don't share the git history. And I think that's good enough. I think it's another

11:09

Speaker A

useful way you can work with multiple agents. But if you prefer to just copy paste the folder and treat them separately, I think this workflow is also good enough.

Topics: Git worktrees Codex CLI Codex Mac OS app multi-agent workflow AI agents parallel development branch management web app redesign Git merge software development workflow


---
This is the markdown twin of https://sozai.app/transcript/codex-multi-agent-workflow-git-worktrees/ — the same content, without the markup.
Published by SozAI (https://sozai.app). Reuse and quotation are allowed with attribution and a link back.
Machine-readable index: https://sozai.app/llms.txt · data API: https://sozai.app/api/
