C:/Program Files/Git/insights command crashes with null/undefined object error

Resolved 💬 3 comments Opened Feb 5, 2026 by 0okay Closed Feb 9, 2026

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

  1. Run /insights command in Claude Code
  2. Error occurs immediately

Investigation Findings

During extensive debugging, I discovered:

  1. 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"
}
``

  1. 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 /insights command attempts to aggregate these files but lacks null checks
  1. Missing Null Check:
  • The error Object.keys(h) or Object.entries indicates variable h is undefined
  • Suggests the code doesn't validate data structure before accessing properties

Attempted Fixes (None Worked)

  1. ✗ Deleted corrupted file → Immediately recreated with same error
  2. ✗ Replaced with valid JSON structure → Overwritten by error response
  3. ✗ Set file to read-only (chmod 444) → Error persists
  4. ✗ Cleared entire usage-data/facets/ directory → New error files created
  5. ✗ 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

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗