C:/Program Files/Git/insights crashes with EBUSY on Windows when session-meta file is locked
Description
The /insights slash command fails completely on Windows with:
Error: EBUSY: resource busy or locked, open 'C:\Users\<user>\.claude\usage-data\session-meta\<uuid>.json'
Steps to Reproduce
- Have one or more Claude Code sessions running on Windows
- Run
/insightsin any session
The command crashes every time. It never produces output — it fails completely rather than skipping the locked file.
Root Cause
The generateUsageReport function iterates over all session-meta JSON files using fs.promises.readFile. On Windows, when another Claude Code session (or the current one) has a session-meta file open for writing, the OS enforces an exclusive lock. Unlike Unix, Windows does not allow concurrent reads on files opened for writing.
The read helper (pj1 in the compiled binary) has a try/catch that returns null on failure, but either a different code path doesn't handle the error, or the error propagates before reaching that handler.
The write function (gj1) uses a simple fs.promises.writeFile with no temp-file-then-rename pattern, which holds the file handle open during the write and triggers EBUSY for any concurrent reader.
Expected Behavior
/insights should skip any session-meta files it can't read (they're just caches — the data can be regenerated from the .jsonl session logs on the next run). The current session's file is always locked, so it will always fail on Windows unless the error is caught and skipped.
Suggested Fix
- Catch
EBUSY/EPERMerrors when reading session-meta files and skip them (returnnull/ treat as cache miss) - Optionally: use a write-to-temp-then-rename pattern in
gj1to avoid holding the target file handle open during writes
Environment
- Claude Code version: 2.1.92
- OS: Windows 11 Pro (10.0.26200)
- Shell: Git Bash (MSYS2)
- Install method: npm (via happy-coder wrapper)
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗