Skip to content

Bug: Tool-result JSONL entries are treated as turn boundaries, misclassifying most coding work as "Conversation" #7

Closed

Description

@EnisKhn

What's happening

In the Claude Code JSONL format, tool results are stored as type: "user" entries — the same type as real human messages. The groupIntoTurns function flushes the current turn and starts a new one on every type === "user" entry without checking whether the entry is an actual human message or just a tool result.

This means a single coding task gets fragmented into multiple micro-turns. Consider a typical exchange:

  1. User entry (human text: "fix this bug") → turn 1 starts
  2. Assistant entry → calls Read → added to turn 1
  3. User entry (tool result: file contents) → flush → turn 2 starts, userMessage = ""
  4. Assistant entry → calls Edit → added to turn 2, classified as coding ✓
  5. User entry (tool result: edit confirmation) → flush → turn 3 starts, userMessage = ""
  6. Assistant entry → final summary text, no tool calls → added to turn 3
  7. User entry (next human message) → flush → turn 3 is pushed with tools = []

Turn 3 ends up with tools.length === 0 and userMessage = "". This is because getUserMessageText() filters for type: "text" content blocks — tool result entries contain only type: "tool_result" blocks, which get stripped to an empty string. An empty string fed into classifyConversation() matches none of the keyword patterns, so it falls through to return
"conversation".

Every coding task produces at least one of these phantom conversation turns — specifically the final assistant summary message after all tool use finishes. Because that final response carries the full conversation context in its input (large cache + output tokens), it is also one of the most expensive API calls in the session.

Misleading output

In practice, this means the "By Activity" breakdown significantly overstates "Conversation" at the expense of "Coding", "Debugging", "Feature Dev", etc. A day of continuous coding where the assistant reads files, edits code, runs bash commands, and summarises results will show "Conversation" as the dominant category — even though almost no actual
conversational turns occurred.

Example output from a heavy coding day:

By Activity
cost turns
██████████ Conversation $466.78 7764
███░░░░░░░ Coding $119.99 2225

The "Conversation" figure here is primarily the accumulated cost of post-tool-use summary responses being misclassified.

Fix

In groupIntoTurns, call getUserMessageText(entry) first and only flush + reset when the result is non-empty. Tool-result-only user entries silently continue the current turn, allowing all assistant API calls for a single human-initiated task to accumulate together and be classified as a unit.

// Before

  if (entry.type === "user") {
    if (currentCalls.length > 0) { turns.push(...); }
    currentUserMessage = getUserMessageText(entry);
    currentCalls = [];
    currentTimestamp = entry.timestamp ?? "";
    currentSessionId = entry.sessionId ?? "";
  }

// After

  if (entry.type === "user") {
    const text = getUserMessageText(entry);
    if (text.trim()) {
      if (currentCalls.length > 0) { turns.push(...); }
      currentUserMessage = text;
      currentCalls = [];
      currentTimestamp = entry.timestamp ?? "";
      currentSessionId = entry.sessionId ?? "";
    }
    // Tool-result entries (empty text) — continue accumulating into current turn
  }

This is a minimal, safe change: getUserMessageText already returns "" for tool-result entries, so the only new behaviour is skipping the flush in that case.

Before Fix

Model Bar Cost Calls
Opus 4.6 ██████████ $681.92 10813
Sonnet 4.6 █░░░░░░░░░ $43.53 1408
Haiku 4.5 ░░░░░░░░░░ $0.111 10
<synthetic> ░░░░░░░░░░ $0.0000 29
Activity Bar Cost Turns
Conversation ██████████ $466.78 7764
Coding ███░░░░░░░ $119.99 2225
Exploration ██░░░░░░░░ $78.14 1461
Brainstorming █░░░░░░░░░ $25.66 250
Debugging ░░░░░░░░░░ $12.12 162
Feature Dev ░░░░░░░░░░ $10.44 152
Planning ░░░░░░░░░░ $7.71 163
General ░░░░░░░░░░ $1.91 20
Delegation ░░░░░░░░░░ $1.80 43
Testing ░░░░░░░░░░ $0.717 14
Refactoring ░░░░░░░░░░ $0.256 4
Git Ops ░░░░░░░░░░ $0.050 1

After Fix

Model Bar Cost Calls
Opus 4.6 ██████████ $682.52 10820
Sonnet 4.6 █░░░░░░░░░ $44.07 1427
Haiku 4.5 ░░░░░░░░░░ $0.219 11
<synthetic> ░░░░░░░░░░ $0.0000 30
Activity Bar Cost Turns
Feature Dev ██████████ $146.71 164
Exploration ██████████ $143.07 438
Coding █████████░ $137.70 296
Conversation ███████░░░ $101.65 577
Debugging ███████░░░ $96.81 212
Brainstorming ███░░░░░░░ $43.93 161
Testing █░░░░░░░░░ $18.78 57
Delegation █░░░░░░░░░ $16.90 37
Planning █░░░░░░░░░ $9.75 15
Refactoring █░░░░░░░░░ $9.62 23
General ░░░░░░░░░░ $1.14 5
Git Ops ░░░░░░░░░░ $0.394 2
Build/Deploy ░░░░░░░░░░ $0.365 1

Activity

  1. AgentSeal commented on Apr 14, 2026

    @AgentSeal
    Collaborator

    Fixed in 74744f0.

    Tool result entries in the JSONL are type: "user" but contain no text. The turn grouper was treating them as new turns, fragmenting a single coding task into multiple micro-turns where the final summary (most expensive API call) got classified as "Conversation".

    The fix: only flush and start a new turn when the user entry has actual text content. Tool-result entries now stay part of the current turn.

    Before/after on a week of heavy coding:

    • Before: Conversation $466 (64%), Coding $119
    • After: Coding $528 (top), Conversation $94

    Total cost unchanged, just correctly attributed now.

  2. added a commit that references this issue on Apr 14, 2026
    74744f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions