DaleSchool

Isolated Development with Worktrees

Advanced20min

Learning Objectives

  • Work in an isolated worktree with claude -w
  • Understand parallel development patterns using multiple worktrees
  • Switch between local and web sessions with Teleport

Working Code

Use claude -w to work in an isolated worktree:

cd my-project
claude -w

Claude Code automatically creates a separate git worktree and works inside it. Your main working directory's code remains completely unaffected.

> Refactor the authentication system in this project from JWT to session-based.
> This is experimental, so feel free to make bold changes.

When the experiment is done:

  • If you like the result, merge the changes into the main branch.
  • If you don't, just delete the worktree. Your main code stays clean.

Try It Yourself

Use multiple terminals to work with worktrees simultaneously:

Terminal 1 — main work:

cd my-project
claude
> Implement the user list API

Terminal 2 — isolated experiment:

cd my-project
claude -w
> Completely redesign the DB schema. Denormalize to optimize read performance.

Terminal 1 proceeds safely while Terminal 2's bold experiments happen in an isolated environment.

"Why?" — Experiments Need a Safety Net

The most dangerous moment in development is when you think "what if I try this?" Large refactorings, architecture changes, trying new libraries — doing these directly on the main code makes them hard to undo.

Advantages of Worktrees

ApproachProblemWorktree
Experiment on mainRisk of code contaminationWork in an isolated copy
git stashSwitching context is tediousWork on multiple tasks simultaneously
New branchFile system is sharedPhysically separate directories

Teleport: Moving Between Local and Web

Teleport transfers a Claude Code session from the terminal to the web (claude.ai/code), or vice versa:

> /teleport

Your local session's context is sent to the web. You can leave your desktop and continue working in the browser.

The reverse direction:

claude --teleport

This brings a web session to your local terminal.

Use cases:

  • Continue work started at the office (terminal) from home (web browser)
  • Quickly check something on mobile via web, then do serious work on desktop

Parallel Development Pattern

Terminal 1: claude        → Main feature work (stable)
Terminal 2: claude -w     → Experimental refactoring (isolated)
Terminal 3: claude -w     → Performance optimization attempt (isolated)

Each worktree has independent git state, so you can work simultaneously without conflicts.

Deep Dive

How is a worktree different from a git branch?

A git branch is a logical fork, while a worktree is a physical fork.

  • branch: Switching branches in the same directory changes the files. Only one branch active at a time.
  • worktree: Checks out a branch in a separate directory. Multiple branches can be active simultaneously.

claude -w automatically creates and manages this git worktree for you.

  1. Use claude -w to attempt a bold refactoring in an isolated environment. Verify your main code is unaffected.
  2. Work simultaneously with claude in one terminal and claude -w in another.
  3. Try /teleport to transfer your session to the web (requires access to claude.ai/code).

What does the claude -w command do?

Further Reading