Recently I discovered what might be the most productivity-boosting workflow change I've made in years. In this article, I'm going to share my experience with combining git worktree and Claude Code to achieve something I never thought possible: working on multiple coding tasks simultaneously without losing my mind to context switching.
The Problem: Context Switching Hell
You know the drill. You're deep in the zone working on feature A, making great progress, when suddenly an urgent bug report comes in. You have to:
- Stash your changes or make a hasty commit
- Switch branches
- Get your head back into the bug's context
- Fix it
- Switch back to your original work
- Try to remember where you left off
By the time you're back to feature A, you've lost precious mental context and momentum. I was doing this dance multiple times a day, and it was killing my productivity.
My Solution: Git Worktree + Claude Code
tl;dr: I create a separate git worktree for each ticket and start a dedicated Claude Code session in each one using multiple iTerm2 panes.
Here's my workflow breakdown:
- Create a worktree for each ticket/task
- Open multiple iTerm2 panes
- Start Claude Code session in each pane
- Work on multiple tasks simultaneously
Why Git Worktree?
For those unfamiliar, git worktree allows you to have multiple working directories for the same repository, each checked out to different branches. Think of it as having multiple copies of your project, but they all share the same git history.
Here's how I set it up:
# Create a new worktree for feature branch
git worktree add ../myproject-feature-auth feature/user-authentication
# Create another worktree for bug fix
git worktree add ../myproject-bugfix-login bugfix/login-validation
# List all worktrees
git worktree list
Each worktree is a complete working directory where I can make changes, run tests, and commit without affecting other worktrees.
The Claude Code Magic
Here's where it gets interesting. I open iTerm2 and create multiple panes (Cmd+D and Cmd+Shift+D are your friends). In each pane, I navigate to a different worktree and start a Claude Code session:
# Pane 1: Feature work
cd ~/projects/myproject-feature-auth
claude
# Pane 2: Bug fix work
cd ~/projects/myproject-bugfix-login
claude
# Pane 3: Code review prep
cd ~/projects/myproject-refactor-api
claude
Each Claude Code session maintains its own context about that specific task. The AI agent understands the branch I'm on, the files I'm working with, and the conversation history related to that particular ticket.
The Benefits Are Game-Changing
High Throughput: I can make progress on 3-4 different tasks in parallel. While Claude is implementing a solution in one pane, I can review its work in another pane or start discussing a different problem.
Minimal Context Switching: Each Claude session requires minimal input from me because it remembers our entire conversation history. I don't have to re-explain the problem every time I switch tasks.
Perfect Context Isolation: Each worktree + Claude session is completely isolated. The AI agent working on the authentication feature has no confusion about the bug fix I'm working on in another pane.
Resume Anywhere: I can leave a task mid-conversation and come back hours (or days) later. The Claude session remembers exactly where we left off, what we were trying to accomplish, and what approaches we had already tried.
Setting Up Your Own Workflow
Here's my recommended setup process:
1. Create your worktree structure:
# From your main project directory
git worktree add ../project-name-ticket-123 feature/ticket-123
git worktree add ../project-name-hotfix-456 hotfix/critical-bug-456
2. Configure iTerm2 panes:
- Open iTerm2
- Split horizontally: Cmd+Shift+D
- Split vertically: Cmd+D
- Arrange panes to your preference
3. Start Claude sessions:
# In each pane, navigate to the respective worktree
cd ../project-name-ticket-123
claude
4. Establish context in each session:
Tell each Claude session about the specific task, show relevant code files, and explain what you're trying to accomplish.
What I Learned
From this workflow experiment, I learned that context preservation is more valuable than I initially thought. The ability to maintain multiple concurrent conversations with Claude, each focused on a specific problem domain, eliminates the cognitive overhead of constantly re-establishing context.
The combination works because:
- Git worktree solves the technical isolation problem
- Claude Code solves the context maintenance problem
- Multiple panes solve the switching problem
Trade-offs to Consider
This workflow isn't perfect for everyone:
Resource usage: Running multiple Claude sessions uses more system resources and API calls.
Cognitive load: You still need to mentally track multiple tasks, though the context switching pain is greatly reduced.
Complexity: More moving pieces mean more things that can go wrong (though I haven't encountered issues yet).
Q&A: Addressing the Details
After sharing this workflow with friendds, I got some great questions that deserve clarification:
Q: How do you actually resume Claude sessions after hours or days?
A: Simple - I just don't close the Claude Code session. I keep the terminal panes open, so the session maintains its context forever (or until my machine restarts). No need for export/import.
Q: What about branch synchronization and merge conflicts?
A: I'm assuming a PR workflow here. Each worktree branch eventually opens a PR against main. The isolation means I don't worry about synchronization until PR time.
Q: How do you manage Claude's context window limitations?
A: This is honestly a bottleneck. When the context gets too large, I sometimes need to start fresh or be strategic about what files I show Claude. It's not perfect.
Q: Which tasks actually benefit from this workflow?
A: Features or bugs that are well broken down ahead of time with clear requirements. If you're doing exploratory work or the requirements are fuzzy, this approach might be overkill.
Q: What about running tests across multiple worktrees?
A: Tests run independently in each worktree. As long as you're not using hardcoded ports or shared resources, parallel test execution works fine.
Q: How do you track which pane is which task?
A: iTerm2 tip - press Cmd+I to set a custom session name for each pane. I name them after the ticket number or feature name.
Q: How do you clean up old worktrees?
A: I don't have a cleanup process yet. That's definitely something I need to figure out as my worktree list grows. git worktree prune
helps with deleted branches, but manual cleanup is still needed.
What's Next
I'm excited to optimize this workflow further. Some ideas I'm exploring:
- Creating shell aliases for quick worktree + Claude session setup
- Using tmux for even better session management
- Developing a simple script to automate the entire setup process
- Building a worktree cleanup routine
This workflow has genuinely transformed how I approach development work. Instead of dreading interruptions and context switches, I now see them as opportunities to make parallel progress on multiple fronts.
Give it a try and let me know how it works for you!
Thanks for your read!
Top comments (0)