claude-code - 💡(How to fix) Fix cwd-cache failure persists session-wide after transient git mv race on macOS [1 participants]

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…
GitHub stats
anthropics/claude-code#51885Fetched 2026-04-23 07:42:18
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×4

On macOS, when a git mv operation causes a transient inode race on the working directory, the Claude Code harness's cwd preflight (stats the cwd before every Bash call) caches the stat failure session-wide and never re-validates. Every subsequent Bash tool call in the session — including those from subagents spawned into the same session — dies before a shell is ever spawned with:

Working directory "/path/to/repo" no longer exists. Please restart Claude from an existing directory.

The directory is fine. Only the cached failure state is broken.

Root Cause

  • The Read tool continues working throughout because it bypasses the cwd validator.
  • Subagents spawned after the wedge inherit the broken state and fail identically — dispatching them wastes tokens producing elaborate failure reports rather than doing work.
  • The only recovery is /exit + reopen — there is no in-session repair path.
  • The failure is non-deterministic: it requires a specific timing window during git mv on a path the harness is concurrently stat-ing.

Fix Action

Fix / Workaround

  • The Read tool continues working throughout because it bypasses the cwd validator.
  • Subagents spawned after the wedge inherit the broken state and fail identically — dispatching them wastes tokens producing elaborate failure reports rather than doing work.
  • The only recovery is /exit + reopen — there is no in-session repair path.
  • The failure is non-deterministic: it requires a specific timing window during git mv on a path the harness is concurrently stat-ing.

Code Example

Working directory "/path/to/repo" no longer exists. Please restart Claude from an existing directory.
RAW_BUFFERClick to expand / collapse

Summary

On macOS, when a git mv operation causes a transient inode race on the working directory, the Claude Code harness's cwd preflight (stats the cwd before every Bash call) caches the stat failure session-wide and never re-validates. Every subsequent Bash tool call in the session — including those from subagents spawned into the same session — dies before a shell is ever spawned with:

Working directory "/path/to/repo" no longer exists. Please restart Claude from an existing directory.

The directory is fine. Only the cached failure state is broken.

Key observations

  • The Read tool continues working throughout because it bypasses the cwd validator.
  • Subagents spawned after the wedge inherit the broken state and fail identically — dispatching them wastes tokens producing elaborate failure reports rather than doing work.
  • The only recovery is /exit + reopen — there is no in-session repair path.
  • The failure is non-deterministic: it requires a specific timing window during git mv on a path the harness is concurrently stat-ing.

Reproduction context

Triggered via git mv plans/proposed/<file> plans/approved/<file> inside a shell script invoked by a Bash tool call, on macOS 14.x (Apple Silicon). The harness cwd preflight races with the git mv inode rename.

Request

Add a re-validation pass (or a short retry with backoff) before caching a stat failure as permanent. A single failed stat on a path that is otherwise a valid, mounted directory should not tombstone the session.

Related

Similar class of issue to #29610 (permissionMode: bypassPermissions wedge).

extent analysis

TL;DR

Implement a re-validation pass or a short retry with backoff before caching a stat failure as permanent in the Claude Code harness's cwd preflight.

Guidance

  • Identify the specific timing window during git mv that triggers the inode race and consider adding a delay or synchronization mechanism to avoid it.
  • Modify the cwd preflight to include a retry mechanism with a limited number of attempts and a backoff strategy to handle transient stat failures.
  • Investigate the possibility of using a more robust method for checking the existence of the working directory, such as using fs.existsSync() or a similar function.
  • Consider adding logging or debugging statements to track the occurrence of stat failures and the subsequent behavior of the harness.

Example

# Pseudocode example of a retry mechanism with backoff
max_attempts = 3
backoff_delay = 100ms

for attempt in 1..max_attempts:
  if stat(cwd) succeeds:
    break
  else:
    sleep(backoff_delay * attempt)
    backoff_delay *= 2

Notes

The proposed solution assumes that the issue is solely due to the caching of stat failures and that a re-validation pass or retry mechanism can effectively mitigate the problem. However, the non-deterministic nature of the failure may require additional debugging and testing to ensure the solution is robust.

Recommendation

Apply a workaround by implementing a retry mechanism with backoff in the cwd preflight, as this is a more feasible and immediate solution compared to upgrading to a potentially non-existent fixed version.

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