First public release, published as one snapshot. What changed between versions is in CHANGELOG.md. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
"""Reads Claude Code session transcripts (.jsonl), as written under ~/.claude/projects/<slug>/. No model call."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
USAGE_FIELDS = ("input_tokens", "cache_read_input_tokens", "cache_creation_input_tokens", "output_tokens")
|
|
|
|
|
|
def is_agent_type(recorded: object, name: str) -> bool:
|
|
"""Whether a subagent's recorded agentType is the agent `name`, started bare ("okf-wiki-reader") or from a
|
|
plugin, which Claude Code records with the plugin's namespace ("<plugin>:okf-wiki-reader")."""
|
|
if not isinstance(recorded, str):
|
|
return False
|
|
plugin, sep, bare = recorded.rpartition(":")
|
|
return bare == name and (not sep or bool(plugin))
|
|
|
|
|
|
def read_transcript(path: Path) -> list[dict[str, Any]]:
|
|
"""Every JSON object line of a transcript; a line that does not parse is skipped."""
|
|
lines = []
|
|
for raw in path.read_text(encoding="utf-8").splitlines():
|
|
try:
|
|
line = json.loads(raw)
|
|
except json.JSONDecodeError:
|
|
continue
|
|
if isinstance(line, dict):
|
|
lines.append(line)
|
|
return lines
|