[Bug] TypeError in insights command: Object.keys() called on undefined value
Resolved 💬 16 comments Opened Feb 4, 2026 by michellemayes Closed Feb 13, 2026
💡 Likely answer: A maintainer (wolffiex, collaborator)
responded on this thread — see the highlighted reply below.
Bug Description
/insights
⎿ TypeError: undefined is not an object (evaluating 'Object.keys(b)')
Environment Info
- Platform: darwin
- Terminal: iTerm.app
- Version: 2.1.31
- Feedback ID: 86f6ee30-02b6-4477-9b06-1abcbe765559
Errors
[{"error":"Error: LSP server plugin:pyright-lsp:pyright failed to start: Executable not found in $PATH: \"pyright-langserver\"\n at start (/$bunfs/root/claude:2167:22315)\n at async H (/$bunfs/root/claude:2167:24763)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:27.216Z"},{"error":"Error: Executable not found in $PATH: \"pyright-langserver\"\n at spawn (unknown)\n at spawn (node:child_process:667:35)\n at spawn (node:child_process:14:39)\n at start (/$bunfs/root/claude:2167:20845)\n at start (/$bunfs/root/claude:2167:22369)\n at H (/$bunfs/root/claude:2167:24763)\n at H (/$bunfs/root/claude:2167:25738)\n at _ (/$bunfs/root/claude:2167:32525)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:27.216Z"},{"error":"Error: Failed to start LSP server plugin:pyright-lsp:pyright: Executable not found in $PATH: \"pyright-langserver\"\n at <anonymous> (/$bunfs/root/claude:2167:32547)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:27.216Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKCyooFVg8U8bGo1gQ\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:34.752Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKDKePrHf2XE2pLDjk\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:34.942Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKCxKda5918vu3Vgw7\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:35.111Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKCyopxKRUED7hW4F3\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:35.137Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKEBjd4Rowbps4TzwT\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:35.143Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKCw5oU5bVZqSyKy38\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:35.421Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKGgJbVQXB1WyJ9Qqt\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:36.535Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKHo2LrRt3NfziuahS\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-02-04T16:46:36.951Z"},{"error":"Error: 500 {\"type\":\"error\",\"error\":{\"type\":\"api_error\",\"message\":\"Internal server error\"},\"request_id\":\"req_011CXoNKNq93caqQZq8ejnfr\"}\n at generate (/$bunfs/root/claude:344:8942)\n at makeRequest (/$bunfs/root/claude:361:5435)\n at processTicksAndRejections (native:7:39)","timestamp…
Note: Content was truncated.
16 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Same here, other folks on my team getting this as well.
Also got this error: TypeError: undefined is not an object (evaluating 'Object.keys(h)')
I appear to be billed tokens for what they fetched before they're trying to display, though.
Same here with v2.1.31
Confirming same issue on macOS. Running
/insightsthrows:Version: 2.1.31 (Claude Code)
Same here, MacOS 2.1.31 installed from Brew.
/insightsalso fails in 2.1.31 on macOS for me whenexport CLAUDE_CODE_USE_VERTEX=1.It works fine when I use it on another machine with a Claude Pro account.
Running
/debugimmediately after the failed/insightswhen running Claude via Vertex AI gives this:Reference:
Full debug output:
Just ran into this myself for
/insights, and got claude to heal itself. Maybe other features have similar/same root cause, so leaving some analysis in case it is helpful for anyone.Issue in my case was OAuth (into a Claude Enterprise subscription account, in case that matters) expiring resulting in API errors, for example:
/insightsdid not check for/notice that this happened and cached error responses into~/.claude/usage-data/facets/. Even after logging back in (which made other features work again), the error when invoking/insightspersisted because it kept trying to read prior facet files (which contained said errors still)./facetsseems to not be able to handle the json format of the error responses.Running
grep -l '"type": "error"' ~/.claude/usage-data/facets/*.json | xargs rm -vfixed it for me. Think for yourself if you want to copy paste this command as is of course, but it should only remove prior facet files with errors that/insightscreated. If I understand correctly, these are "cache" files with analysis of prior sessions. Even removing all of them should in worst case only result in the next/insightsrun taking a bit longer (as it will regenerate them) and should not affect anything else.had to run the command slightly different:
grep -l '"error":' ~/.claude/usage-data/facets/*.json | xargs rm -vRunning this command worked for me also :
grep -l '"error":' ~/.claude/usage-data/facets/*.json | xargs rm -vAdditional troubleshooting that did NOT resolve the issue
Environment: Linux (WSL2), Claude Code v2.1.31
Steps tried:
grep -l '"error":' ~/.claude/usage-data/facets/*.json | xargs rm -v
rm ~/.claude/usage-data/facets/*.json
surrogates - none found.
Debug log analysis:
The debug log shows the actual API errors being returned:
This "no low surrogate in string" error repeats for many parallel requests (15+ times in quick succession), suggesting /insights is
firing off multiple API calls that all fail due to malformed JSON in the request body.
Conclusion:
The issue appears to be in how Claude Code v2.1.31 constructs the API request body for /insights, not in cached files. The request
contains invalid Unicode (unpaired surrogate characters) that the API rejects. Clearing caches doesn't help because the bug is in
the request construction.
This may be related to @nickcernis's finding about the structured-outputs-2025-12-15 beta header issue, or it could be a separate
encoding bug.
Running this command worked for me also : grep -l '"error":' ~/.claude/usage-data/facets/*.json | xargs rm -v
Root Cause Analysis
I investigated this issue in v2.1.33 and identified the exact root cause by decompiling the binary.
Where the crash happens
In the minified code, the
Qfilter function (used to filter out "warmup_minimal" sessions) does:The guard
if (!w) return !1only checks if the facet object itself is falsy. But when the facet API call fails (e.g.,invalid_request_errordue to surrogate characters in session data, or500 Internal server error), the error response object is saved as the facet cache file and also kept in the in-memory Map. Since the error response{"type":"error","error":{...}}is truthy, it passes the guard, butw.goal_categoriesisundefined, causing the TypeError.The bug in
SN8(facet save function)The function
jN8extracts facets via API. When the API returns an error,jN8still returns the parsed response.SN8then saves it to~/.claude/usage-data/facets/<session_id>.jsonwithout validating that it's actually a valid facet object. On subsequent/insightsruns,MN8reads this cached error response and treats it as a valid facet.How to reproduce
/insights— the error response gets cached as a facet file/insightscrashes when iterating over the cached error responseWorkaround
Delete or fix corrupted facet files in
~/.claude/usage-data/facets/:Note: You may also need to pre-create facet files for sessions that don't have cached facets yet, since
/insightswill attempt to generate them (up to 50 per run) and any API failure will reproduce the crash. Pre-creating all missing facets prevents the problematic API calls entirely.Suggested fix
In
SN8, validate that the object hasgoal_categoriesas a dict before saving. In theQfunction, add a check:if (!w?.goal_categories) return !1.Environment
Workaround Verified: Pre-creating Facet Files Successfully Resolves the Issue
I can confirm that the workaround suggested by @atani works perfectly. Here's my experience and verification results:
Environment
Root Cause Confirmation
@atani's analysis is spot-on. The issue occurs because:
400errors:``
``invalid_request_error: "no low surrogate in string: line 1 column 4192"
SN8function saves the API error response as a facet file without validation/insightsruns, the error response object{"type":"error","error":{...}}passes theif (!w)check (because it's truthy), butw.goal_categoriesisundefined, causing the TypeErrorWorkaround Implementation
I pre-created valid facet files for all 145 missing sessions using the suggested Python script. Key points:
goal_categories: {}is safe in JavaScript —Object.keys({})returns[]without crashing/insightsfrom attempting API calls that would fail and cache error responsesValidation Results
After applying the workaround:
The
/insightscommand now works perfectly and generated a full usage report analyzing all 30 sessions.Complete Workaround Script
For anyone hitting this issue, here's the complete script that worked for me:
Additional Notes
Suggested Permanent Fix
As @atani suggested, the fix should be in two places:
In
SN8(facet save function):In
Q(filter function):Hope this helps others hitting the same issue! 🎉
This is late but we fixed this in a recent release. Let me know if this isn't fixed and thanks for the report!
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.