Skip to main content

Crate claude_session_parser

Crate claude_session_parser 

Source
Expand description

Streaming parser for Claude Code session JSONL files.

Three modules, all pub:

  • usage — per-assistant-turn token/cost/tool entries (UsageEntry), session summaries (SessionUsage), hook executions (HookExecution), pricing tables, and project-path encoding compatible with Claude Code’s ~/.claude/projects/ directory naming.
  • chat — flat, timestamp-ordered ChatEvent stream for rendering the conversation (user / assistant / thinking / tool-use / tool-result blocks).
  • activity — deterministic classifier that tags each assistant turn with one of 13 categories (Coding, Debugging, Refactor, Testing, Exploration, …).

Parsing is streaming (BufReader::lines()), tolerates malformed lines, and caps inputs at MAX_JSONL_BYTES (200MB) so a corrupted or runaway file cannot block a caller.

See the crate README for the trust-surface description, the JSONL format notes (split content blocks, <synthetic> skip, hook formats), and a usage example.

Re-exports§

pub use activity::classify;
pub use activity::normalize_user_text;
pub use activity::Activity;
pub use chat::parse_chat_events;
pub use chat::ChatEvent;
pub use usage::context_window_for_model;
pub use usage::encode_project_path;
pub use usage::find_current_session_jsonl;
pub use usage::parse_jsonl_entries;
pub use usage::pricing_for_model;
pub use usage::reduce_session;
pub use usage::HookExecution;
pub use usage::ModelPricing;
pub use usage::ParsedJsonl;
pub use usage::SessionUsage;
pub use usage::UsageEntry;

Modules§

activity
Deterministic classifier for Claude Code turns.
chat
usage

Constants§

MAX_JSONL_BYTES
Hard cap on JSONL file size accepted by usage::parse_jsonl_entries and chat::parse_chat_events.