Here’s the thing — most developers have been using git in essentially the same way for years. Branch, code, commit, merge, repeat. It works. Nobody’s complaining. But once AI coding agents entered the picture, that single-working-directory model started showing cracks almost immediately.
If you’ve ever tried running two Claude Code sessions on the same repo at once, you’ll know exactly what I mean. They trip over each other. One session rewrites a file the other is halfway through reading. Tests fail for reasons that have nothing to do with your code. It’s chaos — and completely avoidable once you understand git worktrees.
What’s a worktree, anyway?
Most developers know a git repository as a folder with a .git directory inside it. What’s less well known is that git has supported multiple working trees for years — each checked out to a different branch, all sharing the same underlying repository history. No duplication of your .git folder, no cloning twice.
The command itself is dead simple:
git worktree add ../my-project-feature feature/new-auth
That gives you a second folder, ../my-project-feature, checked out on feature/new-auth, completely independent from your main working tree. You can have your editor open in one, your terminal in another, and they’ll never interfere.
On its own, that’s mildly useful. Combined with AI agents? It’s a different story.
Why this matters now
The Stack Overflow 2026 Developer Survey found that 92% of developers use at least one AI coding tool daily. That’s up from 65% in 2024. As these tools have matured from “fancy autocomplete” into full agentic systems that read your codebase, edit files, run tests, and iterate on failures — the bottleneck has shifted.
The bottleneck is no longer writing code. It’s context switching.
Here’s a scenario you might recognise: you’re mid-way through a feature branch when a colleague Slacks you about a production bug. You stash your changes, check out main, dig into the bug, realise it’s not a quick fix, stash that, check back out to your feature — and by now you’ve completely lost your thread. That cognitive overhead is real, and it compounds across the day.
Worktrees eliminate that. The bug fix lives in its own folder. Your feature work stays exactly where it was. You flip between them like switching tabs.
Running AI agents in parallel
The worktree pattern was a bit niche before AI agents made it genuinely necessary. The tipping point came when developers started running multiple Claude Code (or Copilot, or Codex) sessions on the same repo simultaneously.
The core problem: each AI agent session needs its own working directory. If two sessions share the same directory and both decide to edit src/auth/middleware.ts, you don’t get a merge — you get corruption. Overwritten changes, confused context, broken builds, and an AI agent confidently explaining why the mess it just made is actually fine.
With worktrees, each agent gets its own isolated directory:
# Worktree 1: feature work
git worktree add ../project-feature feature/user-profiles
# Worktree 2: bug fix
git worktree add ../project-bugfix fix/auth-token-expiry
# Then launch separate agent sessions:
cd ../project-feature && claude # Agent 1
cd ../project-bugfix && claude # Agent 2
Both agents are working against the same repo history. Neither knows or cares what the other is doing. You review each one’s output independently, then merge when you’re happy.
Claude Code actually has first-class support for this now — when you exit a session started with --worktree, it asks whether you want to keep or discard the worktree. Mid-task? Keep it. Done and merged? Bin it immediately. Clean.
A practical setup for UK dev teams
If you’re working in a team (and most of us are), a few extra conventions make this pattern much smoother.
Name your worktree directories consistently. Something like ../[repo]-[branch-slug] keeps things navigable when you’re jumping between tasks. If your team uses a monorepo, consider a dedicated ../worktrees/ parent directory so worktrees don’t end up scattered across your filesystem.
For teams with GDPR obligations — which is most of us in the UK — there’s an additional reason to care about how AI agents interact with your codebase. An isolated worktree means you can be deliberate about which parts of the codebase an agent session can see and touch. You’re not handing an agent your entire repo state; you’re scoping it to a branch. That’s a sensible boundary from both a security and compliance standpoint, especially if your codebase contains any personal data or production config files.
Worth checking your .gitignore too. Any secrets or environment files that shouldn’t travel with a branch won’t appear in a fresh worktree checkout — fair enough, and exactly how it should be.
The workflow that’s actually clicked
After a few weeks of using this pattern, the rhythm starts to feel natural. You wake up, pull main, spin up a worktree for whatever you’re building today, and kick off an agent session in it. While the agent is working — running tests, making edits — you’re reviewing what it did in the previous session, or handling a code review, or doing the thinking-heavy work that agents still aren’t great at.
When you’re ready to review the agent’s output, it’s all sitting in one place, on one branch, with a clean diff. No mystery about what changed or why.
The thing that surprised me most is how much less stressful context switching has become. Knowing that your work-in-progress is isolated and safe — that checking out a hotfix branch won’t trash your half-built feature — removes a low-level anxiety you didn’t realise was there.
Getting started
If you haven’t used worktrees before, the learning curve is minimal. Run git worktree list to see what you’ve got, git worktree add to create one, git worktree remove to clean up. That’s genuinely most of it.
The harder part is shifting your mental model. Your project isn’t a single folder anymore — it’s a set of parallel workspaces, each focused on one thing, each tidy and contained. Once that clicks, it’s hard to imagine going back to the old way.
Especially with an AI agent in each window, quietly getting on with it.