[BUG] /insights silently uses stale session-meta snapshots for grown/continued sessions; report prose re-rolls, masking the staleness
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
Note
I have searched existing issues. The closest match, #26358, describes the same root cause but is either closed or locked to collaborators, so I could not add this detail there — filing here with additional evidence and a second symptom.
What's Wrong?
/insights reads cached session statistics from ~/.claude/usage-data/session-meta/*.json. These snapshots are written once — in my install they all share a single mtime, i.e. generated in a batch at /insights time rather than at session creation — and are never refreshed when the session's .jsonl transcript keeps growing (e.g. via claude --continue across multiple days). All activity after the snapshot is therefore silently excluded from every report.
Concrete instance — one long-running session continued over several days:
| | cached session-meta | live .jsonl |
|---|---|---|
| last written (mtime) | 2026-06-06 16:30 | 2026-06-11 19:15 |
| user_message_count | 40 | 539 |
The cache undercounts this session by 499 user messages and is ~5 days stale. Notably, the snapshot's mtime is still Jun 6 even though I ran /insights again later on Jun 6 and again today (Jun 11) — so re-running /insights does not invalidate or refresh an existing snapshot; it is effectively write-once.
Second symptom — misleading freshness: across three /insights runs (two on Jun 6, one today), the narrative report prose is re-generated each time — wording and framing vary — but the substance is identical, because the inputs are frozen. That cosmetic variation makes a stale report look freshly computed, with no cue that the meaningful content has actually not been updated.
What Should Happen?
The underlying issue is a cache-invalidation gap. Any of the following resolves it (in order of preference):
- Regenerate a
session-metaentry when the matching.jsonlmtime/size has advanced since the snapshot, so/insightsalways reflects the full session. - Failing that, surface a visible staleness warning when a snapshot predates its
.jsonl(e.g. "Note: N messages recorded after the last metadata snapshot are not reflected in this report"). - Do not re-generate the narrative report prose when the underlying data is unchanged, so the report stops misleadingly implying a freshness it doesn't have.
Likely the same "metadata captured once, never refreshed" class as #20406 (gitBranch metadata). Related but distinct: #22030 (stale sessions-index.json undercounts messages on --resume).
Error Messages/Logs
# session-meta cache vs. live transcript for one continued session (ids truncated)
$ stat -c '%y %n' session-meta/b96ca6ab-*.json projects/-workspace/b96ca6ab-*.jsonl
2026-06-06 16:30 session-meta/b96ca6ab-*.json # cache, frozen
2026-06-11 19:15 projects/-workspace/b96ca6ab-*.jsonl # live transcript, grew 5 days later
cached user_message_count : 40
live user message count : 539 # Δ = 499 unrecorded
# No error is emitted — the staleness is silent.
Steps to Reproduce
- Start a session, do some work, and run
/insights. - Continue the same session with
claude --continueover one or more later days, adding many more messages. - Run
/insightsagain (even days later). - Observe: that session's
session-meta/*.jsonmtime and counts are unchanged from step 1; the report's stats and the meaning of its prose are identical, while the live.jsonlhas grown substantially.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.173
Platform
Anthropic API
Operating System
Other Linux - A Docker devcontainer running Linux 6.12.76-linuxkit
Terminal/Shell
Other - A Docker devcontainer launched from Windows Command Prompt (not Windows Terminal)