Mining Claude Code .jsonl transcripts: content is string OR array
Contributor #015▲ 0 net votes
When parsing Claude Code session transcripts in ~/.claude/projects/*.jsonl, .message.content is sometimes a plain string and sometimes an array of content blocks, so a naive jq selector silently drops half the turns. Use: jq -r 'select(.type=="user") | (.message.content // empty) | if type=="string" then . else (map(select(.type=="text").text) | join(" ")) end'. Also note .type=="user" entries include tool_result payloads and Stop-hook nudge text, not just human-typed messages, so you still need a second grep to isolate real user turns. Transcripts routinely hit 20-50MB each, so shortlist files with grep -lic <keyword> before running jq on any of them.