/insights crashes with TypeError on Object.entries/Object.keys — regression from #23138
Bug Description
/insights crashes immediately with a TypeError. This is a regression of #23138, which was reportedly fixed in February 2026 but has resurfaced in 2.1.77.
Error
Two different error messages depending on context:
MacBook (when Skill tool intercepts first):
/insights
⎿ TypeError: Cannot convert undefined or null to object
Mac Mini (native handler):
/insights
⎿ TypeError: Object.entries requires that input parameter not be null or undefined
Both are the same root cause: null/undefined values passed to Object.keys() or Object.entries() in the facet processing code.
Root Cause
From decompiling cli.js, the crash occurs in the session filter function that checks goal_categories:
let T = (I) => {
let B = P.get(I); // get facet from Map
if (!B) return !1; // guard: skip if no facet
let g = B.goal_categories;
b = Object.keys(g)... // ← crashes when goal_categories is undefined/null
The guard if (!B) only checks if the facet object exists, not if its fields are valid. A facet where goal_categories is null or undefined passes the guard but crashes on Object.keys().
Similarly, Object.entries() is called elsewhere on facet fields without null checks.
Environment
- Claude Code version: 2.1.77 (latest as of 2026-03-17)
- Platform: macOS 15.4 (Darwin 25.3.0, arm64)
- Tested on: Two separate machines (MacBook Pro + Mac Mini), both 2.1.77
- Facet files: Mix of real facets (well-formed) and sessions without facets. 271 JSONL sessions, 157 facet files on MacBook; 563 JSONL, 34 facets on Mac Mini.
Steps to Reproduce
- Open Claude Code CLI
- Type
/insightsand press Enter - Error is thrown immediately
Expected Behavior
The /insights command should handle missing facet fields gracefully, either by skipping sessions with incomplete facets or by treating null fields as empty objects.
Suggested Fix
Change the guard to validate expected fields:
if (!B?.goal_categories) return !1;
And similarly for all Object.keys() / Object.entries() calls on facet fields — use optional chaining or fallback to empty objects:
Object.keys(g ?? {})
Object.entries(g ?? {})
Previous Issues
This is a regression of:
- #23138 (root issue, closed as fixed)
- #23523, #23864, #24376, #24393, #24633 (all closed as duplicates of #23138)
The workaround from #23138 (grep -l '"error":' ~/.claude/usage-data/facets/*.json | xargs rm -v) does not resolve this instance because the issue is missing/null fields, not error-response facets.
Additional Context
The APq validation function correctly checks for null:
q.goal_categories !== null && typeof q.goal_categories === "object"
But this validation is only applied during facet creation, not during the insights aggregation loop. Facets that were created by older versions or that have partial data bypass this check.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗