Feature: Git Worktree Awareness for Claude Code Desktop

Resolved 💬 3 comments Opened May 20, 2026 by Zap1024 Closed May 23, 2026

Problem

Claude Code Desktop sessions operating in git worktrees lack awareness of their current worktree context. This causes Edit/Write tools to resolve absolute paths against the main repository directory, not the current worktree.

Example:

  • Worktree path: D:/repo/.claude/worktrees/feature-branch/
  • Main repo path: D:/repo/
  • Session cwd correctly shows worktree
  • But Edit/Write resolves D:/repo/file.md → main directory, not worktree

Impact

  1. AI agents in worktree sessions accidentally modify main branch files
  2. Changes appear "staged" on main but are actually 0-byte placeholder files
  3. Worktree isolation guarantee is violated

Expected Behavior

Claude Code should:

  1. Detect when session is inside a git worktree
  2. Use worktree's root as the base for all file operations
  3. Optionally respect a git.worktreeStrategy setting in settings.json

Proposed Solution

Add a git.worktreeStrategy option to settings.json:

{
  "git": {
    "worktreeStrategy": "current-branch"
  }
}

Behavior options:

  • "current-branch" (recommended): Edit operations target current worktree
  • "main-only": Edit operations always target main repository
  • "prompt": Prompt user when path ambiguity detected

Environment

  • Claude Code Desktop
  • Windows 10/11
  • Git worktrees

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗