claude-code - 💡(How to fix) Fix Worktrees spawned by Claude Code are missing untracked files from main branch

Official PRs (…)
ON THIS PAGE

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…

Root Cause

Claude makes incorrect refactoring decisions based on an incomplete view of the codebase. In one documented case, a module listed as a require() dependency was declared "missing" because the file was untracked in the worktree. This required the user to manually intervene and redirect Claude to the main directory.

Fix Action

Fix / Workaround

Suggested Fix / Mitigation

RAW_BUFFERClick to expand / collapse

Bug Description

When Claude Code spawns a git worktree (via EnterWorktree), the worktree only contains tracked files from the repository. Untracked files present in the main working directory are not visible in the worktree.

This causes Claude to make incorrect decisions about the codebase — e.g., concluding that a module "doesn't exist" or that a require() path is broken, when the file actually exists in the main branch as an untracked file.

Reproduction Steps

  1. Have one or more untracked files in the main project directory (e.g., config_loader.js, combo_trend_tracker.js)
  2. Claude Code spawns or enters a worktree (e.g., via EnterWorktree or automatic worktree creation for plan mode)
  3. From within the worktree, use Glob or Read to look for those files
  4. Result: Files are not found — worktree only reflects tracked git state

Expected Behavior

The worktree should either:

  • Include untracked files from the main working directory, OR
  • Clearly surface a warning that untracked files are not present, so Claude can fall back to reading from the main directory

Actual Behavior

Untracked files silently do not exist in the worktree. Claude proceeds with incomplete file state, leading to wrong analysis (e.g., "this module does not exist", broken require() path analysis).

Environment

  • OS: Windows 11 Pro (10.0.22631)
  • Claude Code: CLI version (latest)
  • Repo type: Standard git repository (not bare)

Impact

Claude makes incorrect refactoring decisions based on an incomplete view of the codebase. In one documented case, a module listed as a require() dependency was declared "missing" because the file was untracked in the worktree. This required the user to manually intervene and redirect Claude to the main directory.

Suggested Fix / Mitigation

Either copy untracked files into the worktree at creation time, or inject a clear notice in the worktree's CLAUDE.md that untracked files are not present and all reads should fall back to the main working directory.

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

claude-code - 💡(How to fix) Fix Worktrees spawned by Claude Code are missing untracked files from main branch