[DOCS] Outdated manual calculation in statusline.md examples following 2.1.6 update
Documentation Type
Missing documentation (feature not documented)
Documentation Location
https://code.claude.com/docs/en/statusline
Section/Topic
The "Context Window Usage" section, specifically the "Advanced approach with manual calculation" code snippets.
Current Documentation
The documentation provides an "Advanced approach with manual calculation" for displaying the context window percentage:
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
CONTEXT_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size')
USAGE=$(echo "$input" | jq '.context_window.current_usage')
if [ "$USAGE" != "null" ]; then
# Calculate current context from current_usage fields
CURRENT_TOKENS=$(echo "$USAGE" | jq '.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens')
PERCENT_USED=$((CURRENT_TOKENS * 100 / CONTEXT_SIZE))
echo "[$MODEL] Context: ${PERCENT_USED}%"
else
echo "[$MODEL] Context: 0%"
fi
What's Wrong or Missing?
The changelog for version 2.1.6 of Claude Code introduced context_window.used_percentage and context_window.remaining_percentage fields specifically to simplify this workflow.
By continuing to feature the "Advanced approach" with manual token summation (.input_tokens + .cache_creation_input_tokens + .cache_read_input_tokens), the documentation is teaching users a redundant and more complex method than necessary. Users may not realize the model already provides a pre-calculated, authoritative percentage that handles all token types correctly.
Suggested Improvement
The "Advanced approach" section should be removed or reframed to show how to access the new fields. The manual calculation code should be deprecated or replaced with the cleaner jq access to the pre-calculated field.
Suggested Text for the bash example:
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
# Use the pre-calculated field added in v2.1.6
PERCENT_USED=$(echo "$input" | jq -r '.context_window.used_percentage // 0')
echo "[$MODEL] Context: ${PERCENT_USED}%"
Impact
High - Prevents users from using a feature
Additional Context
- Version Reference: Claude Code 2.1.6 added
context_window.used_percentageandcontext_window.remaining_percentagefields to status line input for easier context window display. - Related Documentation: The "JSON Input Structure" section on the same page (https://code.claude.com/docs/en/statusline) correctly lists these fields, creating a discrepancy with the code examples below it.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗