Skip to content

fix(exec): use input_tokens only for context_used tracking (#56) - #329

Merged
vybe merged 3 commits into
mainfrom
feature/56-consistent-context-tracking
Apr 14, 2026
Merged

vybe merged 3 commits into
mainfrom
feature/56-consistent-context-tracking

Conversation

@vybe

@vybe vybe commented Apr 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix context_used calculation in TaskExecutionService to use input_tokens only instead of input_tokens + output_tokens
  • Aligns with Claude Code SDK semantics where input_tokens represents the full context window fill level (including all accumulated tool results)
  • Matches existing correct pattern in AgentClient._parse_task_response()

Background

Per Claude Code SDK docs, the ResultMessage.usage.input_tokens (or modelUsage.inputTokens) represents the context window fill level at the final turn - it includes the initial prompt, system prompts, and all tool results accumulated during execution. The output_tokens is what was generated, which is NOT part of context until the next turn.

For stateless/headless executions, input_tokens alone is the correct metric for context_used since:

  1. It represents how full the context window got
  2. Adding output would inflate percentages beyond 100% in some cases
  3. It's semantically what "context used" means

Test Plan

  • Syntax validation passes
  • Change is 1 line, low risk
  • Manual: verify executions show correct context percentages

Closes #56

🤖 Generated with Claude Code

vybe and others added 3 commits April 14, 2026 11:52
The context_used field should represent context window fill level,
not total tokens processed. Claude Code SDK's input_tokens already
represents the full context at the final turn (including accumulated
tool results), so adding output_tokens was incorrect.

This aligns TaskExecutionService with the existing correct pattern
in AgentClient._parse_task_response().

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Verify context_used equals input_tokens only, not input + output.
Per Claude Code SDK, input_tokens represents full context window fill.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consistent context usage tracking for stateless executions

1 participant