Add Claude Code JSONL session import#2
Closed
Siddhant-K-code wants to merge 3 commits into
Closed
Conversation
## Summary Import Claude Code's native JSONL session logs (~/.claude/projects/) into agent-trace format, enabling replay, export, and stats on existing sessions without hooks. ## Changes - `src/agent_trace/jsonl_import.py` — JSONL parser, importer, CLI handler, session discovery - `src/agent_trace/cli.py` — added `import` subcommand and `--discover` flag (3 lines) - `tests/test_jsonl_import.py` — 5 unit tests Parses: tool_use/tool_result blocks, token usage (input/output/cache), subagent detection (isSidechain, subagent_type, caller.type), session metadata. ## Test Plan - All 135 tests pass (130 existing + 5 new) - Tested with real Claude Code session (315-line JSONL, 38 tool calls, 4M tokens) ## Checklist - [x] Follows existing code style - [x] Tests pass - [x] Documentation updated (if applicable) Co-authored-by: Ona <no-reply@ona.com>
- --discover output goes to stdout (was stderr), enabling pipe/grep - Preserve full session ID from JSONL instead of truncating to 16 chars - Consistent 2000-char truncation with '...' indicator for tool result previews - Guard toolUseResult path with 'not tool_results' to prevent duplicate TOOL_RESULT events - Emit ASSISTANT_RESPONSE even when tool calls are present in the same message - discover_claude_sessions uses jsonl_file.stem directly, no per-file open - Replace O(n²) filesystem-probing _decode_project_path with simple str.replace Co-authored-by: Ona <no-reply@ona.com>
Siddhant-K-code
added a commit
that referenced
this pull request
Mar 22, 2026
Imports Claude Code native JSONL session logs (~/.claude/projects/) into agent-trace format, enabling replay, export, and stats on existing sessions without hooks. - New `import` subcommand and `--discover` flag in CLI - Parses tool_use/tool_result blocks, token usage, subagent detection - 5 new unit tests (135 total passing) Co-authored-by: Ona <no-reply@ona.com>
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Imports Claude Code's native JSONL session logs (
~/.claude/projects/) into agent-trace format, enabling replay, export, and stats on existing sessions without hooks.Originally contributed by @ywatanabe1989 in #1. This version addresses all review feedback from that PR.
Changes
src/agent_trace/jsonl_import.py— JSONL parser, importer, CLI handler, session discoverysrc/agent_trace/cli.py—importsubcommand and--discoverflagtests/test_jsonl_import.py— 5 unit testsParses: tool_use/tool_result blocks, token usage (input/output/cache), subagent detection (
isSidechain,subagent_type,caller.type), session metadata.Fixes over #1
--discoverwrote listing to stderrcontent_previewtruncated to 200 chars...indicator, matching other eventsTOOL_RESULTeventstoolUseResultpath withnot tool_resultsto avoid emitting twice for the same callASSISTANT_RESPONSEwhenever text is non-empty, regardless of accompanying tool callsdiscoveropened every JSONL file to read session IDjsonl_file.stemdirectly — Claude Code names files<session-uuid>.jsonl_decode_project_pathwas O(n²) and filesystem-dependentencoded.replace("-", "/")Test Plan