---
title: "Isolate risky work in a worktree — PromptConduit"
description: Experiment freely on a branch without touching your main checkout.
image: "https://promptconduit.dev/og-image.png"
---

<!-- Markdown copy of https://promptconduit.dev/coaching/isolate-with-worktrees. Index of every page: https://promptconduit.dev/llms.txt -->

# Isolate risky work in a worktree

Experiment freely on a branch without touching your main checkout.

Updated October 8, 2026 · [Scott Havird](https://promptconduit.dev/about) · 3 min read

A **git worktree** is a second working directory for the same repository, on its own branch, sharing history and remotes with your main checkout. The agent can refactor freely there while your primary checkout stays clean and buildable.

## When PromptConduit flags this

PromptConduit marks a session as “worktree used” if any of its events show that the working directory is a git worktree, carry a worktree path, call the `EnterWorktree` or `ExitWorktree` tool, or fire the `WorktreeCreate` hook.

The **“Consider a worktree for heavy work”** note (severity: info) fires when no worktree was used and the session was heavy:

-   **Editor extension (live session):** at least 80 tool calls, in a session with at least 3 prompts.
-   **Web Trends view:** at least 400 tool calls across the selected period, with at least 5 prompts, and no worktree use anywhere in it.

This is an informational nudge, not a warning. Plenty of heavy sessions belong in the main checkout. The note is there for the ones where a failed attempt would leave a mess.

## Why it matters

Worktrees isolate *file edits*. That gives you three things:

-   **A cheap undo.** If the attempt goes wrong, remove the worktree and branch. Your main checkout never moved, so there’s nothing to revert by hand.
-   **Parallel work without collisions.** You keep building, testing, or reviewing in your main checkout while the agent edits in its own copy. Two agent sessions in two worktrees don’t overwrite each other.
-   **A clean review boundary.** Everything the agent did is on one branch, so you review it as a diff and merge or discard it like any other branch.

It is not a cost optimization in itself. The benefit is lower risk on big, speculative, or long-running changes.

## What to do

**Start the session in a worktree.** In Claude Code:

```
claude --worktree refactor-auth
```

That creates `.claude/worktrees/refactor-auth/` on branch `worktree-refactor-auth`. Run the same command with a different name in a second terminal for a second isolated session. Add `.claude/worktrees/` to your `.gitignore` so the worktree contents don’t show up as untracked files in the main checkout.

**Or ask mid-session.** Tell Claude to “work in a worktree” and it uses the `EnterWorktree` tool to create one and move the session into it.

**Set up the environment.** A worktree is a fresh checkout, so install dependencies there. To carry gitignored files across automatically, add `.worktreeinclude` at the project root:

```
.env
.env.local
```

**Pick the base.** New worktrees branch from the repository’s default branch. To branch from your current local `HEAD` instead (for example, to carry unpushed commits), set `"worktree": { "baseRef": "head" }` in settings.

**Clean up on exit.** A clean, unnamed worktree is removed automatically. If there is work in it, Claude Code asks whether to keep it and prints a `claude --worktree <name> --resume` command for later. For worktrees you created by hand, use `git worktree list` and `git worktree remove`.

**Combine with planning and delegation.** Approve a [plan](https://promptconduit.dev/coaching/use-plan-mode) first, then let it execute in the worktree. For parallel edits by several [subagents](https://promptconduit.dev/coaching/delegate-with-subagents), ask Claude to “use worktrees for your agents”, or add `isolation: worktree` to a custom subagent’s frontmatter so each one gets its own temporary worktree.

## How to check it worked

In the editor extension’s coaching tab, the **Worktree** cell under “How you drove the agent” reads **Yes · Isolated on a branch** when the live session used one, and **No · Ran in the main checkout** otherwise. The note stops appearing for heavy sessions once they run in a worktree.

PromptConduit also records the repository and branch on every event, so a worktree session shows up under its own branch. If you track spend per repository, see [Cursor AI spend by repo and model](https://promptconduit.dev/blog/cursor-ai-spend-by-repo-and-model) for how the repo and branch context is used. Setup for the coaching tab is in [/docs/editor-extension](https://promptconduit.dev/docs/editor-extension).

## Frequently asked questions

### How do I start Claude Code in a git worktree?

Run claude --worktree <name> (or -w). By default Claude Code creates the worktree under .claude/worktrees/<name>/ at the repository root, on a new branch named worktree-<name>. The repository needs at least one commit.

### What happens to the worktree when I exit?

If the worktree is clean, an unnamed session removes it and its branch automatically. If it has changes or new commits, Claude Code asks whether to keep or remove it, and prints a command to resume later if you keep it.

### When does PromptConduit suggest a worktree?

When a session with at least 80 tool calls ran without any worktree (editor extension), or a period with at least 400 tool calls had no worktree use (web Trends view).

### Do gitignored files like .env get copied into a new worktree?

Not by default, since a worktree is a fresh checkout. Add a .worktreeinclude file at the project root, using .gitignore syntax, to copy matching gitignored files into each new worktree Claude Code creates.

Get this coaching on your own sessions

The free PromptConduit CLI and editor extension compute coaching insights like this one from your own Claude Code and Cursor sessions, fully offline.

`curl -fsSL https://promptconduit.dev/install | bash`

[Quick start →](https://promptconduit.dev/docs/quick-start) [Teams: free up to 3, Team $99/month flat →](https://promptconduit.dev/pricing)

## Related

-   [Adopt skills and slash-commands](https://promptconduit.dev/coaching/adopt-skills-and-slash-commands)
    
    Capture repeatable work as skills instead of retyping long prompts.
    
-   [Batch your tool calls](https://promptconduit.dev/coaching/batch-tool-calls)
    
    Grouping independent reads and edits cuts round-trips and output tokens.
    
-   [Delegate with subagents](https://promptconduit.dev/coaching/delegate-with-subagents)
    
    Parallel agents cover more ground and keep your main context clean.
    

[← All guides](https://promptconduit.dev/coaching)

```json
{
  "@context": "https://schema.org",
  "@type": "SoftwareApplication",
  "@id": "https://promptconduit.dev/#software",
  "name": "PromptConduit",
  "applicationCategory": "DeveloperApplication",
  "operatingSystem": "macOS, Linux, Windows",
  "description": "PromptConduit shows what AI coding costs per developer, repo, and pull request across Claude Code and Cursor. An open-source CLI records every session to a local JSONL file first, with git context and exact cost computed on your machine. Teams sync to see spend across members, models, repos, and clients, with budgets and alerts.",
  "url": "https://promptconduit.dev",
  "installUrl": "https://promptconduit.dev/docs/installation",
  "softwareHelp": {
    "@type": "CreativeWork",
    "url": "https://promptconduit.dev/docs"
  },
  "releaseNotes": "https://promptconduit.dev/changelog",
  "license": "https://opensource.org/licenses/MIT",
  "isAccessibleForFree": true,
  "publisher": {
    "@id": "https://promptconduit.dev/#organization"
  },
  "offers": [
    {
      "@type": "Offer",
      "name": "Free",
      "description": "The full CLI on your machine, and a team of up to 3.",
      "price": "0",
      "priceCurrency": "USD",
      "url": "https://promptconduit.dev/pricing",
      "availability": "https://schema.org/InStock",
      "eligibleQuantity": {
        "@type": "QuantitativeValue",
        "maxValue": 3,
        "unitText": "members"
      }
    },
    {
      "@type": "Offer",
      "name": "Team",
      "description": "Up to 15 members. One flat price, no seat math.",
      "price": "99",
      "priceCurrency": "USD",
      "url": "https://promptconduit.dev/pricing",
      "availability": "https://schema.org/InStock",
      "priceSpecification": {
        "@type": "UnitPriceSpecification",
        "price": "99",
        "priceCurrency": "USD",
        "unitCode": "MON",
        "referenceQuantity": {
          "@type": "QuantitativeValue",
          "value": 1,
          "unitCode": "MON"
        }
      },
      "eligibleQuantity": {
        "@type": "QuantitativeValue",
        "maxValue": 15,
        "unitText": "members"
      }
    },
    {
      "@type": "Offer",
      "name": "Growth",
      "description": "Up to 50 members, for teams and agencies running AI across many repos.",
      "price": "249",
      "priceCurrency": "USD",
      "url": "https://promptconduit.dev/pricing",
      "availability": "https://schema.org/InStock",
      "priceSpecification": {
        "@type": "UnitPriceSpecification",
        "price": "249",
        "priceCurrency": "USD",
        "unitCode": "MON",
        "referenceQuantity": {
          "@type": "QuantitativeValue",
          "value": 1,
          "unitCode": "MON"
        }
      },
      "eligibleQuantity": {
        "@type": "QuantitativeValue",
        "maxValue": 50,
        "unitText": "members"
      }
    }
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "@id": "https://promptconduit.dev/#organization",
  "name": "PromptConduit",
  "url": "https://promptconduit.dev",
  "logo": "https://promptconduit.dev/favicon.svg",
  "email": "hello@promptconduit.dev",
  "contactPoint": {
    "@type": "ContactPoint",
    "contactType": "customer support",
    "email": "hello@promptconduit.dev",
    "url": "https://promptconduit.dev/about"
  },
  "sameAs": [
    "https://github.com/promptconduit/cli",
    "https://github.com/promptconduit/editor-extension",
    "https://twitter.com/promptconduit"
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "Isolate risky work in a worktree",
  "description": "Experiment freely on a branch without touching your main checkout.",
  "author": {
    "@type": "Person",
    "@id": "https://promptconduit.dev/about#person",
    "name": "Scott Havird",
    "url": "https://promptconduit.dev/about",
    "sameAs": [
      "https://scotthavird.com",
      "https://github.com/scotthavird"
    ],
    "worksFor": {
      "@id": "https://promptconduit.dev/#organization"
    }
  },
  "publisher": {
    "@id": "https://promptconduit.dev/#organization"
  },
  "datePublished": "2026-06-29",
  "dateModified": "2026-10-08",
  "mainEntityOfPage": "https://promptconduit.dev/coaching/isolate-with-worktrees",
  "image": "https://promptconduit.dev/og-image.png",
  "keywords": "git worktree, isolation, refactor, agent skills"
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "BreadcrumbList",
  "itemListElement": [
    {
      "@type": "ListItem",
      "position": 1,
      "name": "Home",
      "item": "https://promptconduit.dev/"
    },
    {
      "@type": "ListItem",
      "position": 2,
      "name": "Coaching guides",
      "item": "https://promptconduit.dev/coaching"
    },
    {
      "@type": "ListItem",
      "position": 3,
      "name": "Isolate risky work in a worktree",
      "item": "https://promptconduit.dev/coaching/isolate-with-worktrees"
    }
  ]
}
```

```json
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
    {
      "@type": "Question",
      "name": "How do I start Claude Code in a git worktree?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Run claude --worktree <name> (or -w). By default Claude Code creates the worktree under .claude/worktrees/<name>/ at the repository root, on a new branch named worktree-<name>. The repository needs at least one commit."
      }
    },
    {
      "@type": "Question",
      "name": "What happens to the worktree when I exit?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "If the worktree is clean, an unnamed session removes it and its branch automatically. If it has changes or new commits, Claude Code asks whether to keep or remove it, and prints a command to resume later if you keep it."
      }
    },
    {
      "@type": "Question",
      "name": "When does PromptConduit suggest a worktree?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "When a session with at least 80 tool calls ran without any worktree (editor extension), or a period with at least 400 tool calls had no worktree use (web Trends view)."
      }
    },
    {
      "@type": "Question",
      "name": "Do gitignored files like .env get copied into a new worktree?",
      "acceptedAnswer": {
        "@type": "Answer",
        "text": "Not by default, since a worktree is a fresh checkout. Add a .worktreeinclude file at the project root, using .gitignore syntax, to copy matching gitignored files into each new worktree Claude Code creates."
      }
    }
  ]
}
```
