Manage Parallel AI Coding with Claude Code and Git Worktrees
Job to be done: Manage parallel AI-assisted coding tasks using Git worktrees
🇳🇬 Ways to use this in Nigeria
Ideas to get you started, adapt to your situation.
- Student
Build a Python script for your data structures assignment in one Git worktree, while simultaneously debugging a web app feature in another worktree with Claude Code.
- 9-5 employee
Develop a new API endpoint in one worktree and refactor legacy code in another, using Claude Code for each task without interference.
What you’ll get
You will set up multiple isolated coding environments (called Git worktrees) for a single project. Each worktree will have its own dedicated branch and can run a separate AI coding session with Claude Code. This approach allows you to work on several coding tasks simultaneously without their changes interfering with each other, making code review much simpler and avoiding common interruptions like stashing changes.
Tools you need
- Git (free): A version control system that tracks changes in your code, allowing you to manage different versions of your project.
- Claude Code (paid): An AI assistant for writing and debugging code, typically accessed via a command-line interface (CLI) or API.
- Terminal (free): A text-based interface on your computer (like Command Prompt on Windows or Terminal on macOS/Linux) used to run commands.
Steps
-
Install Git: Download and install Git for your operating system. Follow the instructions on the official Git website.
- You should see a successful installation message. Open your Terminal and type
git --versionto confirm it’s working.
- You should see a successful installation message. Open your Terminal and type
-
Install Claude Code: The author doesn’t specify installation steps for Claude Code. You will need to install the Claude Code CLI tool and configure it with your API key. Refer to the official Anthropic documentation for the most up-to-date instructions.
- You should have the
claudecommand available in your Terminal and be authenticated to use the service.
- You should have the
-
Clone your repository: If you don’t already have a project, clone an existing Git repository to your computer. Replace
[your-repo-url]with the actual URL of your project’s repository.git clone [your-repo-url]- You should see a new folder created with your project’s files inside it.
-
Navigate to your main repository: Open your Terminal and change your current directory to the main folder of your cloned repository. Replace
/path/to/your/main-repowith the actual path.# macOS or Linux cd /path/to/your/main-repo # Windows (PowerShell) cd "/path/to/your/main-repo"- Your terminal prompt should now show that you are inside your project’s main folder.
-
Refresh your base branch: Fetch the latest changes from the remote repository to ensure your local
main(ormaster) branch is up-to-date. The author usedmaster, butmainis a common modern default.git fetch origin main- You should see messages indicating that new changes have been downloaded from the remote server.
-
Create the first worktree: Create a new, isolated working directory and a new branch for your first parallel task. Replace
feature-one-namewith a descriptive name for your task andyour-repo-feature-onewith the desired folder name for this worktree. This folder will be created next to your main repository folder.# macOS or Linux git worktree add -b feature-one-name ../your-repo-feature-one main # Windows (PowerShell) git worktree add -b feature-one-name "../your-repo-feature-one" main- You should see a new folder (
your-repo-feature-one) appear next to your main repository, containing a copy of your project files, now on its own dedicated branch.
- You should see a new folder (
-
Start Claude Code in the first worktree: Change into the newly created worktree folder and start a Claude Code session. This session will only see and modify files within this isolated worktree.
# macOS or Linux cd ../your-repo-feature-one claude # Windows (PowerShell) cd "../your-repo-feature-one" claude- You should be in the new worktree folder, and a Claude Code session should start, ready for you to work on your first task.
-
Create the second worktree: Open a new Terminal window. Navigate back to your main repository folder (as in Step 4). Then, create a second isolated worktree for your next parallel task. Replace
feature-two-nameandyour-repo-feature-twowith appropriate names.# macOS or Linux cd /path/to/your/main-repo git worktree add -b feature-two-name ../your-repo-feature-two main # Windows (PowerShell) cd "/path/to/your/main-repo" git worktree add -b feature-two-name "../your-repo-feature-two" main- You should see another new folder (
your-repo-feature-two) appear, also with project files on its own branch.
- You should see another new folder (
-
Start Claude Code in the second worktree: In the new Terminal window, change into this second worktree folder and start another Claude Code session.
# macOS or Linux cd ../your-repo-feature-two claude # Windows (PowerShell) cd "../your-repo-feature-two" claude- You should be in the second worktree folder, and a second Claude Code session should start, completely independent of the first.
-
Work in parallel: You now have two separate Terminal windows, each running an independent Claude Code session within its own Git worktree. You can switch between these windows to work on different coding tasks simultaneously without their changes interfering with each other.
- You can now make changes, commit them, and interact with Claude Code in each worktree independently. When you’re done with a task in one worktree, you can review and merge its changes without affecting the other ongoing work.
Original source
This workflow was shared by lovestaco on the DEV Community blog. The author demonstrated how Git worktrees can be combined with parallel AI coding sessions to manage multiple development tasks efficiently.
Notes & variations
- Free-tier alternatives: If Claude Code’s paid model is a barrier, consider using the free tier of the Gemini API for coding assistance, or explore local AI models like those run with Ollama or LM Studio, which can be integrated with code editors like VS Code.
- Common mistake: A common pitfall is forgetting that while worktrees isolate your working files, they still share the same underlying
.gitrepository. This means you cannot have the same branch checked out in two different worktrees simultaneously. Also, ensure youcdinto the correct worktree folder before starting your AI coding session to avoid modifying the wrong set of files. - Tip for better results: Always use clear, descriptive branch names for your worktrees that directly relate to the task you’re performing. This makes it easy to remember which worktree is for which task, especially when you have several running in parallel.