C:/Program Files/Git/insights command crashes with null/undefined object error
Bug Description
The /insights command consistently crashes with a null/undefined object error.
Error Messages
The error message varies but indicates the same root cause:
TypeError: undefined is not an object (evaluating 'Object.keys(h)')TypeError: Object.entries requires that input parameter not be null or undefined
Environment
- Claude Code Version: 2.1.31
- OS: Windows 11 (MINGW64_NT-10.0-22621)
- Platform: Git Bash / MSYS2
Reproduction Steps
- Run
/insightscommand in Claude Code - Error occurs immediately
Investigation Findings
During extensive debugging, I discovered:
- Corrupted Usage Data File:
- File path:
~/.claude/usage-data/facets/b177a99f-f7c6-4b0f-87b2-ada3534538b6.json - This file is repeatedly written with API error responses instead of valid session data:
``json``
{
"type": "error",
"error": {
"type": "invalid_request_error",
"message": "The request body is not valid JSON: no low surrogate in string: line 1 column 26123 (char 26122)"
},
"request_id": "req_011CXpxk4q5fb18nfQ2rTzdz",
"session_id": "b177a99f-f7c6-4b0f-87b2-ada3534538b6"
}
- Root Cause:
- A background process continuously tries to process session
b177a99f-f7c6-4b0f-87b2-ada3534538b6 - The API request contains invalid UTF-16 characters (no low surrogate)
- Error responses are written to the usage data directory
- The
/insightscommand attempts to aggregate these files but lacks null checks
- Missing Null Check:
- The error
Object.keys(h)orObject.entriesindicates variablehisundefined - Suggests the code doesn't validate data structure before accessing properties
Attempted Fixes (None Worked)
- ✗ Deleted corrupted file → Immediately recreated with same error
- ✗ Replaced with valid JSON structure → Overwritten by error response
- ✗ Set file to read-only (chmod 444) → Error persists
- ✗ Cleared entire
usage-data/facets/directory → New error files created - ✗ Deleted
stats-cache.json→ No effect
Expected Behavior
The /insights command should:
- Handle corrupted or invalid usage data gracefully
- Show a warning instead of crashing
- Skip problematic files or sessions
Suggested Fix
Add null/undefined checks before calling Object.keys() or Object.entries() on parsed usage data:
// Before
const keys = Object.keys(h);
// After
const keys = h ? Object.keys(h) : [];
Workaround
Currently, there is no effective workaround. The command is unusable.
Impact
- Low severity (non-essential feature)
- Does not affect core Claude Code functionality
- Only impacts usage statistics viewing
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗