Resumed Claude Code sessions: message history silently truncated at resume boundaries — getSessionMessages filters JSONL by a single sessionId
Version: v1.36.1 (@cloudcli-ai/cloudcli)
Area: Claude provider, session message history
Summary
GET /api/providers/sessions/:id/messages silently truncates the history of any Claude Code session that was resumed or continued. Only the segment of the transcript whose records match the DB's provider_session_id is returned; everything before (or after) the resume boundary is dropped with no indication to the client.
Where
server/modules/providers/list/claude/claude-sessions.provider.ts, in getSessionMessages (line 104 at the v1.36.1 tag). Records read from the session's JSONL file are filtered by exact session-id match at line 139:
for await (const line of rl) {
...
const entry = JSON.parse(line) as AnyRecord;
if (entry.sessionId === providerSessionId) { // line 139
messages.push(entry);
}
...
}Why that filter loses data
When a Claude Code session is resumed/continued (--resume, --continue, desktop-app resume), the CLI keeps writing to a single transcript file that contains records from the whole resume lineage under multiple sessionId values: the records written before the resume keep the original session's id, and records written after carry the new id. The file is named after the newest id, and the older segment exists only in that file — there is no separate JSONL for the pre-resume session.
Concrete example from a real (local) transcript directory:
<new-id>.jsonl — 1,385 records total
├─ records 1–70 sessionId = <old-id> (pre-resume history)
└─ records 71–1385 sessionId = <new-id> (post-resume)With provider_session_id = <new-id>, the endpoint returns 1,315 of 1,385 records and the first 70 (the entire pre-resume conversation) vanish. If the DB row instead holds <old-id>, the result is worse: 70 records survive and the remaining 1,315 are dropped. Either way the truncation is silent — total/hasMore are computed from the filtered set, so the client has no way to know messages are missing.
Sessions with several resume generations lose one segment per boundary.
Reproduction
- In Claude Code (CLI or desktop), run a session, exit, and resume it (
claude --resume), exchanging a few messages in each segment. - Let CloudCLI discover the session from disk.
- Fetch
GET /api/providers/sessions/:id/messagesand compare the returned count againstgrep -c . <file>.jsonl(or against the count of records persessionId:jq -r '.sessionId' file.jsonl | sort | uniq -c). - Only the records whose
sessionIdequals the storedprovider_session_idcome back.
Suggested direction
- Follow the lineage instead of exact-matching a single id: accept records whose
sessionIdappears in the file's parent/continuation chain (the ids present in the file form that chain, and boundary records reference the prior segment), or - For disk-discovered sessions, fall back to reading the file unfiltered and dedupe by record
uuid— since the file already is the session's full transcript, the filter mostly re-derives what the filename established.
Related in spirit to #1002 (another case where the indexing/reading layer silently drops session content), but a distinct code path and failure mode.
Source: siteboon/claudecodeui