Replay your coding agent sessions as a map and a timeline
Python agent-observabilityai-agentsclaudeclaude-codecodexcoding-agentscursordeveloper-toolsdevtoolsgithub-copilotkirollmobservabilityopencodeprivacypythonsession-replaytypescriptvisualization
fix(builder): read Claude Code workflow subagent transcripts
rav4nnb3503b6254e4
diff --git a/README.md b/README.mdindex 26789c4..e867fdc 100644--- a/README.md+++ b/README.md@@ -122,7 +122,7 @@ Every view is a URL, so a link to a moment in a session reopens it for anyone wh| Agent | Reads from (defaults) | Subagent lanes | Tokens | Notes ||---|---|---|---|---|-| **Claude Code** | `~/.claude/projects/**/*.jsonl` and `…/subagents/agent-*.jsonl` | yes | per request | Highest fidelity: read straight from the JSONL, including hooks, compactions, stop reasons and latency |+| **Claude Code** | `~/.claude/projects/**/*.jsonl` and `…/subagents/**/agent-*.jsonl` | yes | per request | Highest fidelity: read straight from the JSONL, including hooks, compactions, stop reasons and latency || **Codex** (CLI, IDE) | `~/.codex/sessions/**/*.jsonl` | main lane only | per turn | || **Cursor** (agent CLI and IDE composer) | `~/.cursor` agent transcripts, `~/.cursor/chats/*/*/store.db`, IDE `state.vscdb` | main lane only | not recorded, see limitations | SQLite stores are copied and decoded locally, read-only || **GitHub Copilot CLI** | `~/.copilot/session-state/**` | main lane only | per turn | |diff --git a/python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.py b/python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.pyindex 045bff5..262fb00 100644--- a/python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.py+++ b/python/src/agentplay/_core/ingestion/coding_agent/_sources/local/source.py@@ -1165,14 +1165,17 @@ def _has_cursor_store_header(head: bytes) -> bool:return False-def _claude_code_subagent_files(transcript: Path) -> list[Path]:- """List child transcripts; missing directory is normal, read errors are not."""- directory = transcript.with_suffix("") / "subagents"- try:- with os.scandir(directory) as entries:- return sorted(Path(e.path) for e in entries if Path(e.name).match("agent-*.jsonl"))- except FileNotFoundError:- return []+def claude_code_subagent_files(transcript: Path) -> list[Path]:+ def _raise_unless_missing(err: OSError) -> None:+ if not isinstance(err, FileNotFoundError):+ raise err++ return sorted(+ Path(root, name)+ for root, _dirs, names in os.walk(transcript.with_suffix("") / "subagents", onerror=_raise_unless_missing)+ for name in names+ if Path(name).match("agent-*.jsonl")+ )def _with_claude_code_subagents(@@ -1188,7 +1191,7 @@ def _with_claude_code_subagents({childfor parent in (transcript, *related_parents)- for child in _claude_code_subagent_files(parent)+ for child in claude_code_subagent_files(parent)})parts = [data]@@ -1610,7 +1613,11 @@ class LocalSource:# be newer than the parent (parent killed mid-subagent, so no# tool_result line ever advanced it) -- the session's activity clock# is the newest write across the whole family.- for sub in _claude_code_subagent_files(jsonl_file):+ try:+ subs = claude_code_subagent_files(jsonl_file)+ except OSError:+ subs = [] # the build reports the unreadable folder against this session alone+ for sub in subs:try:mtime = max(mtime, datetime.fromtimestamp(sub.stat().st_mtime, tz=UTC))except OSError:diff --git a/python/src/agentplay/builder.py b/python/src/agentplay/builder.pyindex 09ecd1a..a4a5c2d 100644--- a/python/src/agentplay/builder.py+++ b/python/src/agentplay/builder.py@@ -18,7 +18,7 @@ Redaction contract (raw transcripts never leave the machine):* ``path_mode`` = ``dirs_only`` drops file names, ``hashed`` HMACs every segment.Claude Code is read directly from its JSONL (main transcript plus-``<session>/subagents/agent-*.jsonl``) because the shared span parser does not+``<session>/subagents/**/agent-*.jsonl``) because the shared span parser does notemit subagent tool calls and only keeps per-turn token totals. Every other agentgoes through the shared ``LocalSource`` spans (``build_map_from_spans``)."""@@ -2561,43 +2561,43 @@ def build_claude_code_map(tasks: list[dict[str, Any]] | None = None,) -> dict[str, Any]:"""Build a map for one Claude Code session file (plus its subagent transcripts)."""+ from agentplay._core.ingestion.coding_agent._sources.local.source import claude_code_subagent_files+transcript = Path(transcript)b = MapBuilder(path_mode=path_mode, hmac_key=hmac_key, resolver=resolver)b.task_specs = taskslinks: dict[str, str] = {}_read_claude_transcript(b, transcript, "main", links)- sub_dir = transcript.with_suffix("") / "subagents"- if sub_dir.is_dir():- for f in sorted(sub_dir.glob("agent-*.jsonl")):- raw_id = f.stem[len("agent-") :]- if raw_id.startswith("acompact-"):- # Auto-compaction snapshots re-record parent API messages, not an agent's- # work: a subagent would be fake and its llm events would double-count them.- # The compaction call itself stays billed on the parent.- continue- aid = links.get(raw_id) or ("sa-" + raw_id[:12])- sub_type, model = "general", ""- meta = f.with_suffix(".meta.json")- if meta.exists():- try:- m = json.loads(meta.read_text(encoding="utf-8"))- sub_type = str(m.get("agentType") or m.get("subagent_type") or sub_type)[:40]- model = str(m.get("model") or "")[:60]- except (ValueError, OSError):- pass- launch = next((e for e in b.events if e.get("child") == aid), None)- if launch is not None:- sub_type = launch.get("subagentType", sub_type)- b.agents.append(- {- "id": aid,- "parent": "main",- "kind": "subagent",- "subagentType": sub_type,- **({"model": model} if model else {}),- }- )- _read_claude_transcript(b, f, aid, {})+ for f in claude_code_subagent_files(transcript):+ raw_id = f.stem[len("agent-") :]+ if raw_id.startswith("acompact-"):+ # Auto-compaction snapshots re-record parent API messages, not an agent's+ # work: a subagent would be fake and its llm events would double-count them.+ # The compaction call itself stays billed on the parent.+ continue+ aid = links.get(raw_id) or ("sa-" + raw_id[:12])+ sub_type, model = "general", ""+ meta = f.with_suffix(".meta.json")+ if meta.exists():+ try:+ m = json.loads(meta.read_text(encoding="utf-8"))+ sub_type = str(m.get("agentType") or m.get("subagent_type") or sub_type)[:40]+ model = str(m.get("model") or "")[:60]+ except (ValueError, OSError):+ pass+ launch = next((e for e in b.events if e.get("child") == aid), None)+ if launch is not None:+ sub_type = launch.get("subagentType", sub_type)+ b.agents.append(+ {+ "id": aid,+ "parent": "main",+ "kind": "subagent",+ "subagentType": sub_type,+ **({"model": model} if model else {}),+ }+ )+ _read_claude_transcript(b, f, aid, {})doc = b.finish(session={"id": f"local:claude-code:{transcript.stem}",diff --git a/python/src/agentplay/discover.py b/python/src/agentplay/discover.pyindex d7cf7b3..a0d83fc 100644--- a/python/src/agentplay/discover.py+++ b/python/src/agentplay/discover.py@@ -228,14 +228,14 @@ def candidates(source: Any, *, since: datetime | None = None) -> list[Candidate]def source_bytes(c: Candidate) -> int:"""On-disk size of a session's transcript plus Claude Code subagent files."""+ from ._core.ingestion.coding_agent._sources.local.source import claude_code_subagent_files+total = 0with captured():p = Path(c.path)if p.is_file():total += p.stat().st_size- sub = p.with_suffix("") / "subagents"- if sub.is_dir():- total += sum(f.stat().st_size for f in sub.glob("agent-*.jsonl"))+ total += sum(f.stat().st_size for f in claude_code_subagent_files(p))return totaldiff --git a/python/src/agentplay/hook_detail.py b/python/src/agentplay/hook_detail.pyindex 78c0645..2b5715d 100644--- a/python/src/agentplay/hook_detail.py+++ b/python/src/agentplay/hook_detail.py@@ -70,8 +70,14 @@ def _text(value: Any) -> str | None:return value[:MAX_CHARS] if isinstance(value, str) and value else Nonedef _transcripts(path: str) -> list[str]:- """The session transcript, then its subagents' (``<session>/subagents/agent-*.jsonl``)."""- return [path, *sorted(str(f) for f in (Path(path).with_suffix("") / "subagents").glob("agent-*.jsonl"))]+ """The session transcript, then its subagents' (``<session>/subagents/**/agent-*.jsonl``)."""+ from ._core.ingestion.coding_agent._sources.local.source import claude_code_subagent_files++ try:+ subs = claude_code_subagent_files(Path(path))+ except OSError:+ subs = []+ return [path, *(str(f) for f in subs)]def _load(path: str, line_no: int, uuid: str) -> dict[str, Any] | None:"""The hook attachment on one line, or None if the file changed under us."""