Repository navigation
fix(exec): use input_tokens only for context_used tracking (#56) - #329
Merged
Merged
Conversation
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]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
context_usedcalculation inTaskExecutionServiceto useinput_tokensonly instead ofinput_tokens + output_tokensinput_tokensrepresents the full context window fill level (including all accumulated tool results)AgentClient._parse_task_response()Background
Per Claude Code SDK docs, the
ResultMessage.usage.input_tokens(ormodelUsage.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. Theoutput_tokensis what was generated, which is NOT part of context until the next turn.For stateless/headless executions,
input_tokensalone is the correct metric forcontext_usedsince:Test Plan
Closes #56
🤖 Generated with Claude Code