A short, practical guide to run Cursor and Claude Code in parallel without losing context.

1) Why git worktree for AI coding

Day-in-the-life example: You’re deep into a large feature when an urgent bug pings you. Normally, you’d switch branches, your editor reloads, your flow breaks, and you have to pause your mental model of the feature while you dive into the bug.

With git worktree, you don’t have to disrupt anything. You spin up a separate working copy of the repo, fix the bug there, and keep your feature branch exactly as you left it. Each task has its own space, so you can jump between them without collisions.

For AI coding, this means running parallel threads: one workspace and conversation focused on the feature, another on the bug. You and the AI both maintain continuity, so instead of constantly interrupting yourselves, you’re free to handle tasks side by side.

Benefits of git worktree:

  • Work on multiple tasks in parallel - each worktree has its own folder and branch, so you and AI agents can work on different things at the same time without clashing.

  • One shared history - all worktrees share the same repository object store, which keeps branches and remotes in sync automatically.

  • No more git stash - your changes stay right where you left them in each worktree, ready to pick up again.

  • Fewer mistakes - it’s much harder to commit to the wrong branch by accident.

2) What is git worktree?

git worktree lets you attach multiple working directories to the same repository so you can work on two or more branches simultaneously without constant branch switching.

Tips and Best practices

  • Give each worktree a meaningful, short name (e.g., include ticket ID).

  • Keep all worktrees in a single parent folder (e.g., worktrees/<your-feature-folder>).

3) How‑to Guide

Goal: Start a new worktree for your feature/bugfix from main, open it in Cursor or any IDE and start working.

Let’s continue with the example from earlier: you’re deep into a large feature on your main branch when an urgent bug comes up. Instead of stashing your changes or switching branches, you can create a dedicated worktree just for the bugfix. This keeps your feature work untouched while giving you a clean space to focus on the bug. Let’s see how it’s done:

3.1 Create the worktree

Run:

git fetch origin main
git worktree add wt-bugfix -b bugfix-branch origin/main

3.2 Verify your worktrees

Run:

git worktree list

Output:

/worktrees/my-repo              147dcb8464 [my-big-feature]
/worktrees/wt-bugfix            6034442556 [bugfix-branch]

3.3 Open in Cursor (new window)

Run:

cursor /worktrees/wt-bugfix

A new Cursor window opens, ready on your bugfix branch.

4) Cleanup

When you’re done (after merging the branch):

git worktree remove /worktrees/wt-my-new-feature
# (optional) delete the branch if merged
# git branch -d my-new-feature-branch

Bottom line: Parallel development becomes natural with git worktree: handle bugs, features, and experiments at the same time, all in clean, separate spaces.

Keep Reading

No posts found