claude-code - 💡(How to fix) Fix Feature: Git Worktree Awareness for Claude Code Desktop

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Code Example

{
  "git": {
    "worktreeStrategy": "current-branch"
  }
}
RAW_BUFFERClick to expand / collapse

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

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING