claude-code - 💡(How to fix) Fix Cowork: launch virtiofsd with cache=none on workspace mounts to fix stale .git/index.lock [1 comments, 2 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#45125Fetched 2026-04-09 08:12:40
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×3commented ×1cross-referenced ×1

Error Message

Every agent must clone the mounted repo to /tmp (local VM disk, not virtiofs), do all git work there, push, then cp files back. This works but is slow, error-prone, and requires every agent prompt to know about it.

Root Cause

Attempting to rm or unlink the lockfile from inside the VM fails with Operation not permitted, because the file no longer exists on the host — only in the guest cache.

Fix Action

Fix / Workaround

Current workaround (in our project's CLAUDE.md)

Every agent doing git work on a Cowork-mounted repo has to carry a /tmp clone workaround in its prompt. Removing this would simplify dozens of agent prompts and remove a whole class of silent failures.

Code Example

fatal: Unable to create '.git/index.lock': File exists
RAW_BUFFERClick to expand / collapse

Problem

Cowork's workspace folder is shared into the sandbox VM via virtiofs with what appears to be cache=always (or auto) and writeback enabled. This causes a well-known virtiofs cache-coherency bug: when a file is deleted on the host, the guest page cache keeps the dentry pinned, so the guest still 'sees' the file on subsequent stat/open calls.

In practice this breaks all git write operations on a mounted repo. A stale .git/index.lock from a prior background git process remains visible inside the VM even after the host has removed it, so every git add / git commit fails with:

fatal: Unable to create '.git/index.lock': File exists

Attempting to rm or unlink the lockfile from inside the VM fails with Operation not permitted, because the file no longer exists on the host — only in the guest cache.

Related upstream reports:

  • kata-containers/runtime#2770 — virtio-fs cache prevents host deletes from propagating
  • kata-containers/runtime#1902 — same root cause
  • kata-containers/kata-containers#691 — upstream moved virtiofsd default to cache=none for exactly this reason
  • anthropics/claude-code#28890 — VirtioFS mount goes stale, breaks workspace sessions
  • anthropics/claude-code#11005 — stale .git/index.lock blocks git commands

Current workaround (in our project's CLAUDE.md)

Every agent must clone the mounted repo to /tmp (local VM disk, not virtiofs), do all git work there, push, then cp files back. This works but is slow, error-prone, and requires every agent prompt to know about it.

Proposed fix

Launch virtiofsd for Cowork workspace mounts with one of:

  1. --cache=none (preferred — matches kata-containers default, fully fixes the bug, only costs read throughput on bulk file reads which is irrelevant for code repos), or
  2. --cache=auto --writeback=no + guest mount option noauto_cache (keeps read perf, forces metadata revalidation on lookup — should also fix lockfile coherency).

Either change is host-side only; nothing inside the sandbox can work around this properly.

Repro

  1. Open a Cowork session with a git repo in the selected workspace folder.
  2. Run any background-y git operation that creates .git/index.lock and is killed before cleanup.
  3. From the host, rm .git/index.lock.
  4. Inside the sandbox, ls .git/index.lock — file is still visible. git commit fails. rm fails with EPERM.

Impact

Every agent doing git work on a Cowork-mounted repo has to carry a /tmp clone workaround in its prompt. Removing this would simplify dozens of agent prompts and remove a whole class of silent failures.

extent analysis

TL;DR

Launch virtiofsd with --cache=none to fix the virtiofs cache-coherency bug.

Guidance

  • Verify the current virtiofsd launch options to confirm that cache=always or cache=auto with writeback enabled is being used.
  • Test the proposed fix by launching virtiofsd with --cache=none and verify that git write operations work as expected.
  • Consider testing the alternative fix --cache=auto --writeback=no with guest mount option noauto_cache to balance performance and correctness.
  • Validate the fix by reproducing the issue using the provided repro steps and verifying that the fix resolves the problem.

Example

No code snippet is necessary for this issue, as the fix involves modifying the launch options of virtiofsd.

Notes

The proposed fix only requires changes to the host-side configuration, and no modifications are needed inside the sandbox.

Recommendation

Apply the workaround by launching virtiofsd with --cache=none, as it is the preferred solution that fully fixes the bug and is consistent with the kata-containers default.

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 Cowork: launch virtiofsd with cache=none on workspace mounts to fix stale .git/index.lock [1 comments, 2 participants]