claude-code-data
    Preparing search index...

    Function readSubagentTurns

    • Streams the subagent turns spawned by a session, one at a time.

      Recursively scans <sessionId>/subagents/agent-<agentId>.jsonl files (CC ≥ 2.1.2), including nested layouts (e.g. subagents/workflows/<runId>/agent-<id>.jsonl), and yields each user/assistant turn tagged with its agentId. Memory stays bounded — the consumer can group, filter, or process incrementally.

      Yields nothing if the session has no subagents/ directory.

      Parameters

      • projectDir: string

        Absolute path to the project directory under ~/.claude/projects/<slug>/

      • sessionId: string

        UUID of the parent session (without .jsonl extension)

      Returns AsyncGenerator<{ agentId: string; turn: MessageEntry }>

      // Group by agent — typical use case
      const byAgent = new Map<string, MessageEntry[]>();
      for await (const { agentId, turn } of readSubagentTurns(dir, id)) {
      if (!byAgent.has(agentId)) byAgent.set(agentId, []);
      byAgent.get(agentId)!.push(turn);
      }