
Managing multiple features or bug fixes concurrently can be challenging, especially when they require different dependencies or configurations. Git worktrees offer a powerful solution by allowing you to have multiple working directories, each checked out to a different branch, all within the same Git repository. This means you can switch contexts rapidly without the overhead of stashing or committing incomplete work.
When combined with Claude Code, this workflow becomes even more potent. Imagine you’re working on a new feature (branch feature-x) and discover a critical bug that needs immediate attention (branch hotfix-y). Instead of context-switching your IDE and Claude Code sessions awkwardly, you can create a new worktree for hotfix-y in a separate directory. This allows you to have two independent Claude Code sessions running, each fully aware of its respective branch’s code context, without interference.
To set up a new worktree, navigate to your repository’s root directory in your terminal and run:
git worktree add ../hotfix-y hotfix-y
This command creates a new directory ../hotfix-y and checks out the hotfix-y branch into it. You can then open this new directory in a separate instance of your IDE and initiate a new Claude Code session. Claude Code, when used with MCP (Model Context Protocol), will correctly infer the context of the code within each worktree, providing more relevant and accurate assistance for each task. This isolation minimizes confusion and accelerates your development cycle.