claude-code-data
    Preparing search index...

    Function readSession

    • Reads and parses one Claude Code session into its aggregate metadata.

      Streams the main JSONL file and computes counters and last-wins fields (tokens, gitBranch, primaryModel, etc.) without retaining the per-turn entries. Memory usage stays constant regardless of the file size.

      Pair with readSessionTurns when you need the message stream.

      Parameters

      • projectDir: string

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

      • sessionId: string

        UUID of the session (without .jsonl extension)

      Returns Promise<ParsedSession>

      const session = await readSession(
      '/Users/me/.claude/projects/-Users-me-my-project',
      'e2b491ed-ec11-4fc3-b9ff-90a11d0a8c0c'
      );
      console.log(session.tokens.input); // total input tokens
      console.log(session.gitBranch); // 'feat/my-feature'