MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / getTokenCountFromUsage

Function getTokenCountFromUsage

src/utils/tokens.ts:55–65  ·  view source on GitHub ↗
(usage: Usage)

Source from the content-addressed store, hash-verified

53 * Use tokenCountWithEstimation() when you need context size from messages.
54 */
55export function getTokenCountFromUsage(usage: Usage): number {
56 if (!usage) {
57 return 0
58 }
59 return (
60 (usage.input_tokens ?? 0) +
61 (usage.cache_creation_input_tokens ?? 0) +
62 (usage.cache_read_input_tokens ?? 0) +
63 (usage.output_tokens ?? 0)
64 )
65}
66
67export function tokenCountFromLastAPIResponse(messages: Message[]): number {
68 let i = messages.length - 1

Callers 7

finalizeAgentToolFunction · 0.85
tokenCountWithEstimationFunction · 0.85
runInProcessTeammateFunction · 0.85
tokens.test.tsFile · 0.85
runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected