[DOCS] Include examples on tracking context usage percentage
Documentation Type
Missing documentation (feature not documented)
Documentation Location
https://docs.claude.com/en/docs/claude-code/sdk/sdk-cost-tracking
Section/Topic
Tracking Context Usage
Current Documentation
There is currently a docs page for "Tracking Costs and Usage" with the Claude Code SDK.
What's Wrong or Missing?
There is no page explaining how to track the current percentage of the context used with the Claude Code SDK.
This is necessary because:
- There is support for compaction in the Claude Code SDK, but no way to know how close one is to auto-compaction
- The current
usageblock returned is difficult to understand, and doesn't clearly add up to the 200k token limit that most Anthropic models use.
Suggested Improvement
We need both more data to be returned via the Claude Code SDK, as well as a concrete guide on how to calculate the percentage of total model context used (and how close one is to auto compaction) for a given conversation. This should tell us specifically:
- The total % of model context used
- How close the conversation is to auto-compaction
Impact
High - Prevents users from using a feature
Additional Context
This makes auto-compaction incredibly painful for users to deal with.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗