Skip to content

Context usage shows 0 at session start until first LLM response #257

Description

@xinhuagu

Problem

When a new session starts, the context usage bar shows 0/200K (0%) and stays at 0 until the first LLM response comes back with stream.usage data.

Root cause

  1. ContextMonitor initializes lastRealInputTokens = 0 (Java long default) — no mechanism exists to set an initial value at session start.

  2. onUsageUpdate is only triggered by StreamingAgentLoop after receiving a streaming response with accumulator.usage — before any LLM call completes, the CLI has no input token data.

  3. Anthropic's API only reports input_tokens in the response (message_start and message_delta SSE events), so the CLI cannot know context occupation before the first request is sent and a response begins streaming.

Current behavior

Time ctx display Reason
Session start 0 ContextMonitor default, daemon sends no initial usage
After user input, before LLM response 0 Input tokens come from API response
During LLM streaming Real value message_deltastream.usagerecordStreamingUsage

Additional issue: debug log messages leaking to console

logback-cli.xml had ContextMonitor set to DEBUG level, causing recordStreamingUsage and recordTurnComplete debug messages to appear on the user's terminal.

Linked

Part of Epic #248

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions