[BUG] /stats command fails with 'Failed to load stats: Invalid time value'
Bug description
The /stats command fails immediately with the error:
Failed to load stats: Invalid time value
No stats are displayed.
Steps to reproduce
- Open Claude Code
- Run
/stats - See error
Root cause (from minified cli.js analysis)
The error originates in the stats calculation functions in cli.js. Two places pass raw timestamp values to new Date() without validation:
ztY()function (stats aggregation) — calculates date range from session timestamps:
``javascript`
J = w && $ ? Math.ceil((new Date($).getTime() - new Date(w).getTime()) / 86400000) + 1 : 0
w
If or $ (min/max timestamps from sessionStats) contain an invalid date string, new Date() returns Invalid Date and .getTime() throws RangeError: Invalid time value`.
p2q()function (streak calculation) — iterates over date strings:
``javascript`
let X = new Date(_[D-1]), M = new Date(_[D]);
if (Math.round((M.getTime() - X.getTime()) / 86400000) === 1)
new Date()` without format validation.
Same issue — date strings from the sorted set are passed to
The error is caught by mtY() and displayed as "Failed to load stats: Invalid time value".
Suggested fix
Validate timestamps before constructing Date objects, e.g.:
const d = new Date(timestamp);
if (Number.isNaN(d.getTime())) continue; // skip invalid entries
Environment
- Claude Code version: 2.1.45
- OS: macOS (Darwin 24.6.0, arm64)
- Shell: zsh
- Terminal: iTerm2
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗