Multiply your AI development speed using Git Worktrees

· Mathieu Santostefano · Expertise · 2 minutes to read
Large tree under the sunlight

Say goodbye to context switching and the "stash-and-switch" headache. By leveraging Git Worktrees alongside modern AI agents, you can now isolate environments and handle bug fixes in parallel while your AI builds features in the background. It’s a total DX game-changer that turns your Git workflow into a multi-threaded powerhouse.

At SensioLabs, the creator of Symfony, we know that Developer Experience (DX) matters more than ever to transform the way teams build software. Every developer knows the pain of context switching. Usually, this means using git stash to save your work, checking out a new branch, and often enduring a reinstallation of dependencies and a reset of fixtures, before you can even start looking at an urgent issue.

What if you never had to stash your work or wait for dependencies to reinstall again? Enter Git Worktrees. And when you combine this native Git feature with modern AI coding agents like Claude Code, you unlock a completely revolutionized workflow.

What Are Git Worktrees?

Git worktrees are a built-in feature that lets you check out multiple branches from the same repository simultaneously, each in its own separate working directory. Instead of juggling a single workspace and constantly switching states, you can have a dedicated workspace for every branch you are actively working on.

The primary purposes of Git worktrees include:

  • Preserving complex staging: If you have already advanced well on staging your work, worktrees allow you to work on another branch without risking a stash pop failing later due to modified files.

  • Avoiding environment disruption: Switching between branches that have vastly different dependencies wastes a considerable amount of time. Worktrees allow these different environments to co-exist on your disk.

  • Side-by-side comparisons: You can easily run multiple branches locally at the same time to compare behavior or review pull requests without losing context.

The Next Level: Parallel AI Sessions

By using worktrees, you can run parallel AI sessions in complete isolation. This means you can have Claude Code actively developing a feature in one worktree, while you manually fix a bug in another, without either session interfering with the other.

How it works with Claude Code

Starting an isolated AI session is incredibly simple. You just use the --worktree (or -w) flag when launching the agent:

claude --worktree my-new-feature

Note that worktree checkbox is enabled by default in Claude Desktop, tab “Code”. You should be careful, depending on if you want a worktree or not. It’s opt-in on Claude Code CLI, but opt-out on Claude Desktop Code.

If you omit the name, Claude will generate a random one automatically. You can also instruct specialized subagents to use worktrees, ensuring that background tasks are handled safely in parallel.

Once you exit the AI session, the cleanup is managed for you. If the agent made no changes, the worktree and its branch are automatically removed. If changes or commits were made, you will be prompted to either keep the worktree to review later or discard it entirely.

It should be noted that this worktree feature is also available on Claude Desktop (under the tab “Code”), and in many other AI coding agents (Codex, Antigravity, Gemini CLI (experimental), etc.).

Solving the .env Dilemma

One common hurdle for PHP and Symfony developers using worktrees is that fresh checkouts do not include untracked files, such as your local .env or .env.local configuration files.

To make this seamless, Claude Code supports a .worktreeinclude file at the root of your project. Using standard .gitignore syntax, you can tell the agent to automatically copy your local environment files into every new worktree it creates. This means the AI agent's isolated environment is immediately ready to run and test your application.

Conclusion

Improving Developer Experience is a core focus here at SensioLabs. By moving away from git stash and adopting Git worktrees, you remove friction from your daily tasks. Coupling this architecture with AI coding agents allows you to parallelize your output and tackle complex bugs and features simultaneously.

Ready to Level Up Your Workflow?

SensioLabs helps your team master advanced architectures and modern DX workflows to maximize development velocity. We provide the consulting and training needed to transform your technical debt into a unified, AI-enhanced production engine.

This might also interest you

Paper notes on a wall
Imen Ezzine

Behind the Scenes: 3 Collaborative Ceremonies for Better Development

Following a recent LinkedIn post, I wanted to write this article to describe 3 ceremonies that truly made an impact on me during one of my latest missions: Event Storming, Example Mapping, and Domain Storytelling.

Read more
Why PHP?
Silas Joisten

Why PHP Powers the Enterprise Web: The Strategic Advantage Companies Cannot Ignore

PHP remains one of the most reliable and cost effective backend technologies for enterprise systems.

Read more
Fabien Potencier
Elise Hamimi

SymfonyCon Amsterdam 2025: Our Recap and the Highlights

After an iconic first edition in 2019, SymfonyCon made its big comeback to Amsterdam. From the start, you could feel the energy of a highly anticipated conference: more than 1,200 attendees, 39 nationalities, the biggest Symfony community reunion of the year, great discoveries... and a fun atmosphere. This year was extra special because it was the 20th anniversary of Symfony. SensioLabs was there: we'll tell you all about our experience there!

Read more
Chart going up
Silas Joisten

Why Tests? Explained for Management

For business leaders: why testing matters for ROI, risk reduction, and agility explained in management language with numbers and real case studies.

Read more
PHP 8.5 URI extension
Oskar Stark

PHP 8.5's New URI Extension: A Game-Changer for URL Parsing

PHP 8.5 introduces a powerful new URI extension that modernizes URL handling. With support for both RFC 3986 and WHATWG standards, the new Uri class provides immutable objects, fluent interfaces, and proper validation - addressing all the limitations of the legacy parse_url() function. This guide shows practical before/after examples and explains when to use each standard.

Read more
Open in new tab
Silas Joisten

The Tab Trap: Why Forcing New Tabs Is Bad UX

We’ve all done it — added target="_blank" to a link to “help users” stay on our site. But what feels like a harmless convenience often creates confusion, breaks accessibility, and introduces hidden security risks.

Read more
3 dog heads
Mathieu Santostefano

Bring Your Own HTTP client

Break free from rigid dependencies in your PHP SDKs. Learn how to use PSR-7, PSR-17, and PSR-18 standards along with php-http/discovery to allow users to bring their favorite HTTP client, whether it's Guzzle, Symfony HttpClient, or another. A must-read for PHP and Symfony developers.

Read more
Blue sign on a building with several Now What? letters
Thibaut Chieux

How To Prioritize Messages When Building Asynchronous Applications With Symfony Messenger

Asynchronous processing offers benefits like decoupled processes and faster response times, but managing message priorities can become a challenge. When dealing with tasks ranging from password resets to complex exports, ensuring timely delivery of critical messages is essential. This article explores common asynchronous processing issues and provides solutions using Symfony Messenger, allowing you to optimize your application without extensive refactoring.

Read more
Image