Agent SDK: option for get_session_messages to return a session's full history, not just the current chain
Problem
get_session_messages(session_id) (Python) and getSessionMessages() (TypeScript) return a session's current conversation chain. Messages on earlier branches are not returned. That includes branches left by rewinds and edits, and history from before a compaction. Tools that analyse past work need those branches, and the documented API is the only supported way to read sessions.
Impact (measured)
I used the SDK to read one user's Claude Code history (318 sessions) and compared the result with every user message the sessions had recorded:
- 305 of 992 distinct hand-typed prompts (31%) were not returned.
- All of the missing prompts came from 5 long sessions with compaction or heavy rewinding. In one session the SDK returned 410 messages, while the session had recorded 16,616 user entries.
- The lost branches skew toward costly prompts. A rewind usually means the prompt went wrong. 15 of the 51 most instructive cases in our analysis were among the missing prompts.
Request
An opt-in parameter, for example get_session_messages(session_id, include_branches=True), that returns every message in the session. Each message would carry its parent id, or a branch or compaction marker, so callers can rebuild the tree. A per-message timestamp field would also help callers deduplicate messages that are replayed across resumed sessions.
Context
Prompting Wizard (an open source prompting course, https://github.com/Entuvo/prompting-wizard) uses the documented session APIs for an opt-in "learn from your past work" feature. It does not parse transcript files directly.