[BUG] /stats command fails with 'Failed to load stats: Invalid time value'

Resolved 💬 2 comments Opened Feb 17, 2026 by DoomzD Closed Mar 19, 2026

Bug description

The /stats command fails immediately with the error:

Failed to load stats: Invalid time value

No stats are displayed.

Steps to reproduce

  1. Open Claude Code
  2. Run /stats
  3. 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:

  1. 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
`
If
w or $ (min/max timestamps from sessionStats) contain an invalid date string, new Date() returns Invalid Date and .getTime() throws RangeError: Invalid time value`.

  1. 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)
`
Same issue — date strings from the sorted set are passed to
new Date()` without format validation.

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

View original on GitHub ↗

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